message

package
v1.0.303 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

These functions are wrappers for the regular Buffer read/write funcs for use with protobufs. Protos only support 32 and 64 bit signed/unsigned integers, but bytes, chars, shorts, words need to be read and written.

Index

Constants

View Source
const (
	EntityOrigin1    = 1 << 0
	EntityOrigin2    = 1 << 1
	EntityAngle2     = 1 << 2
	EntityAngle3     = 1 << 3
	EntityFrame8     = 1 << 4
	EntityEvent      = 1 << 5
	EntityRemove     = 1 << 6
	EntityMoreBits1  = 1 << 7 // keep going
	EntityNumber16   = 1 << 8
	EntityOrigin3    = 1 << 9
	EntityAngle1     = 1 << 10
	EntityModel      = 1 << 11
	EntityRenderFX8  = 1 << 12
	EntityAngle16    = 1 << 13
	EntityEffects8   = 1 << 14
	EntityMoreBits2  = 1 << 15 // keep going
	EntitySkin8      = 1 << 16
	EntityFrame16    = 1 << 17
	EntityRenderFX16 = 1 << 18
	EntityEffects16  = 1 << 19
	EntityModel2     = 1 << 20
	EntityModel3     = 1 << 21
	EntityModel4     = 1 << 22
	EntityMoreBits3  = 1 << 23 // keep going
	EntityOldOrigin  = 1 << 24
	EntitySkin16     = 1 << 25
	EntitySound      = 1 << 26
	EntitySolid      = 1 << 27
	EntityModel16    = 1 << 28
	EntityMoreFX8    = 1 << 29
	EntityAlpha      = 1 << 30
	EntityMoreBits4  = 1 << 31 // keep going
	EntityScale      = 1 << 32
	EntityMoreFX16   = 1 << 33

	EntitySkin32     = EntitySkin8 | EntitySkin16
	EntityEffects32  = EntityEffects8 | EntityEffects16
	EntityRenderFX32 = EntityRenderFX8 | EntityRenderFX16
	EntityMoreFX32   = EntityMoreFX8 | EntityMoreFX16
)

entity state flags

View Source
const (
	SVCBad = iota
	SVCMuzzleFlash
	SVCMuzzleFlash2
	SVCTempEntity
	SVCLayout
	SVCInventory
	SVCNOP
	SVCDisconnect
	SVCReconnect
	SVCSound
	SVCPrint
	SVCStuffText
	SVCServerData
	SVCConfigString
	SVCSpawnBaseline
	SVCCenterPrint
	SVCDownload
	SVCPlayerInfo
	SVCPacketEntities
	SVCDeltaPacketEntities
	SVCFrame
	SVCZPacket   // r1q2
	SVCZDownload // r1q2
	SVCGameState // r1q2/q2pro
	SVCSetting   // r1q2/q2pro
	SVCNumTypes  // r1q2/q2pro
)

server to client message types

View Source
const (
	CLCBad = iota
	CLCNop
	CLCMove
	CLCUserinfo
	CLCStringCommand
	CLCSetting              // r1q2 specific
	CLCMoveNoDelta     = 10 // q2pro specific
	CLCMoveBatched          // q2pro specific
	CLCUserinfoNoDelta      // q2pro specific
)

client to server message types

View Source
const (
	SoundVolume      = 1 << 0 // 1 byte
	SoundAttenuation = 1 << 1 // 1 byte
	SoundPosition    = 1 << 2 // 3 coordinates
	SoundEntity      = 1 << 3 // short 0-2: channel, 3-12: entity
	SoundOffset      = 1 << 4 // 1 byte, msec offset from frame start
	SoundIndex16     = 1 << 5 // index is 16 bits
)

Sound properties

View Source
const (
	TentGunshot = iota
	TentBlood
	TentBlaster
	TentRailTrail
	TentShotgun
	TentExplosion1
	TentExplosion2
	TentRocketExplosion
	TentGrenadeExplosion
	TentSparks
	TentSplash
	TentBubbleTrail
	TentScreenSparks
	TentShieldSparks
	TentBulletSparks
	TentLaserSparks
	TentParasiteAttack
	TentRocketExplosionWater
	TentGrenadeExplosionWater
	TentMedicCableAttack
	TentBFGExplosion
	TentBFGBigExplosion
	TentBossTeleport
	TentBFGLaser
	TentGrappleCable
	TentWeldingSparks
	TentGreenBlood
	TentBlueHyperBlaster
	TentPlasmaExplosion
	TentTunnelSparks
	TentBlaster2
	TentRailTrail2
	TentFlame
	TentLightning
	TentDebugTrail
	TentPlainExplosion
	TentFlashlight
	TentForceWall
	TentHeatBeam
	TentMonsterHeatBeam
	TentSteam
	TentBubbleTrail2
	TentMoreBlood
	TentHeatBeamSparks
	TentHeatBeamSteam
	TentChainFistSmoke
	TentElectricSparks
	TentTrackerExplosion
	TentTeleportEffect
	TentDBallGoal
	TentWidowBeamOut
	TentNukeBlast
	TentWidowSplash
	TentExplosion1Big
	TentExplosion1NP
	TentFlechette
	TentNumEntities
)

temporary entity types

View Source
const (
	RFFrameLerp = 64
	RFBeam      = 128
)
View Source
const (
	MaxItems         = 256
	MaxStats         = 32
	MaxEntities      = 1024
	MaxConfigStrings = 2080
	MaxMessageLength = 1390
	PrintLevelLow    = 1
	PrintLevelObit   = 2
	PrintLevelHigh   = 3
	PrintLevelChat   = 3
)
View Source
const (
	CallbackOnConnect = iota + SVCNumTypes
	CallbackOnBegin
	CallbackOnMention // a print containing our name
	CallbackOnDamage  // someone shot us
	CallbackOnDie     // we're dead
)
View Source
const (
	PlayerType        = 1 << 0
	PlayerOrigin      = 1 << 1
	PlayerVelocity    = 1 << 2
	PlayerTime        = 1 << 3
	PlayerFlags       = 1 << 4
	PlayerGravity     = 1 << 5
	PlayerDeltaAngles = 1 << 6
	PlayerViewOffset  = 1 << 7
	PlayerViewAngles  = 1 << 8
	PlayerKickAngles  = 1 << 9
	PlayerBlend       = 1 << 10
	PlayerFOV         = 1 << 11
	PlayerWeaponIndex = 1 << 12
	PlayerWeaponFrame = 1 << 13
	PlayerRDFlags     = 1 << 14
	PlayerReserved    = 1 << 15

	PlayerBits = 16
	PlayerMask = (1 << PlayerBits) - 1
)
View Source
const (
	CSMapname = 33
)

configstrings

Variables

This section is empty.

Functions

func DeltaEntityBitmask added in v1.0.233

func DeltaEntityBitmask(to *pb.PackedEntity, from *pb.PackedEntity) int

DeltaEntityBitmask will return the bitmask representing the differences between the `to` and `from` entities.

func DeltaPlayerBitmask added in v1.0.233

func DeltaPlayerBitmask(from *pb.PackedPlayer, to *pb.PackedPlayer) int

DeltaPlayerBitmask will return a bitmask representing the difference between two playerstates. This way only differences are transmitted from server to client to save bandwidth/processing since playerstates are emitted on every frame (every 100ms by default, and down to every 20ms for q2pro on protocol 36). This is used for both parsing and writing playerstates.

The bitmask is an unsigned short

Types

type Buffer added in v1.0.233

type Buffer struct {
	Data   []byte
	Index  int
	Length int // maybe not needed
}

func MarshalCenterPrint added in v1.0.233

func MarshalCenterPrint(cp *pb.CenterPrint) Buffer

Write a Centerprint proto back to binary

func MarshalConfigstring added in v1.0.233

func MarshalConfigstring(cs *pb.ConfigString) Buffer

Write a Configstring proto back to binary

func MarshalFlash added in v1.0.233

func MarshalFlash(mf *pb.MuzzleFlash) Buffer

Write a Muzzleflash proto back to binary

func MarshalFrame added in v1.0.233

func MarshalFrame(fr *pb.Frame) Buffer

Write a Frame proto (including playerstate and entities) back to binary

func MarshalLayout added in v1.0.233

func MarshalLayout(lo *pb.Layout) Buffer

Write a Layout proto back to binary

func MarshalPrint added in v1.0.233

func MarshalPrint(p *pb.Print) Buffer

Write a Print proto back to binary

func MarshalServerData added in v1.0.233

func MarshalServerData(s *pb.ServerInfo) Buffer

Write a ServerData proto back to binary

func MarshalSound added in v1.0.233

func MarshalSound(s *pb.PackedSound) Buffer

Write a PackedSound proto back to binary

func MarshalStuffText added in v1.0.233

func MarshalStuffText(st *pb.StuffText) Buffer

Write a StuffText proto back to binary

func MarshalTempEntity added in v1.0.233

func MarshalTempEntity(te *pb.TemporaryEntity) Buffer

Write a TempEntity proto back to binary

func NewBuffer added in v1.0.233

func NewBuffer(data []byte) Buffer

func NewClientCommand

func NewClientCommand(str string) Buffer

func NewConnectionlessPacket

func NewConnectionlessPacket(str string) Buffer

func NewEmptyBuffer added in v1.0.281

func NewEmptyBuffer() Buffer

func WriteDeltaEntity added in v1.0.233

func WriteDeltaEntity(from *pb.PackedEntity, to *pb.PackedEntity) Buffer

WriteDeltaEntity will emit the differences between `from` and `to` as binary that q2 clients can understand.

func WriteDeltaPlayerstate added in v1.0.233

func WriteDeltaPlayerstate(from *pb.PackedPlayer, to *pb.PackedPlayer) Buffer

WriteDeltaPlayerstate will convert the changes between the `from` and `to` playerstates from a textproto to binary that q2 clients understand.

func (*Buffer) Append added in v1.0.233

func (m *Buffer) Append(m2 Buffer)

combine 2 buffers, set index to the end

func (*Buffer) AtEnd added in v1.0.275

func (m *Buffer) AtEnd() bool

As the buffer been parsed all the way to the end?

func (*Buffer) IsEmpty added in v1.0.275

func (m *Buffer) IsEmpty() bool

Find out if the buffer has any data or not

func (*Buffer) ParseCenterPrint added in v1.0.233

func (m *Buffer) ParseCenterPrint() *pb.CenterPrint

A string that should appear temporarily in the center of the screen

func (*Buffer) ParseChallenge added in v1.0.233

func (m *Buffer) ParseChallenge() (*pb.Challenge, error)

This the first server-to-client message after client issues "getchallenge" when initiating a connection.

Example response: ÿÿÿÿchallenge 910908644 p=34,35,36

func (*Buffer) ParseConfigString added in v1.0.233

func (m *Buffer) ParseConfigString() *pb.ConfigString

Configstrings are strings sent to each client and associated with an index. They're referenced by index in various playces such as layouts, etc.

func (*Buffer) ParseDeltaPlayerstate added in v1.0.233

func (m *Buffer) ParseDeltaPlayerstate(from *pb.PackedPlayer) *pb.PackedPlayer

ParseDeltaPlayerstate will merge a previous playerstate with one parsed from the receiver. Only the changed values are copied.

The merge (decompression) has to happen at parse-time because values can change TO zero, and after parsing is complete there is no way to tell if a zero is a new value or a missing value.

func (*Buffer) ParseEntity added in v1.0.233

func (m *Buffer) ParseEntity(from *pb.PackedEntity, num uint16, bits uint32) *pb.PackedEntity

ParseEntity will parse an entity from stream and return an uncompressed PackedEntity proto. It uses the `from` param to decompress, this acts as a baseline, applies the changes and returns a clone of that full PackedEntity.

func (*Buffer) ParseEntityBitmask added in v1.0.233

func (m *Buffer) ParseEntityBitmask() uint32

Read up to the first 4 bytes of an entity, depending on the previous ones. This value tells you what data is in the rest of the entity message.

func (*Buffer) ParseEntityNumber added in v1.0.233

func (m *Buffer) ParseEntityNumber(flags uint32) uint16

ParseEntityNumber will read the edict number of an entity. This number will be between 1 and MaxEntities. Entity 0 is the world.

func (*Buffer) ParseFrame added in v1.0.233

func (m *Buffer) ParseFrame(oldFrames map[int32]*pb.Frame) *pb.Frame

Frame message are sent from the server to each client every 0.1 seconds (100 milliseconds), this is the server's default framerate. Each fram will contain info about that frame (the number, the number of the frame it was compressed against, areabits, etc), and also the current playerstate and copy of all entities that changed since the delta frame.

func (*Buffer) ParseInventory added in v1.0.233

func (m *Buffer) ParseInventory()

2 bytes for every item

func (*Buffer) ParseLayout added in v1.0.233

func (m *Buffer) ParseLayout() *pb.Layout

A layout is a string of code to represent how things need to be arranged on the screen. The intermission screen after a TDM match for example with players, scores, pings, stats, etc is an example

func (*Buffer) ParseMuzzleFlash added in v1.0.233

func (m *Buffer) ParseMuzzleFlash() *pb.MuzzleFlash

A gun fired, nearby clients should see the flash. Monsters also produce muzzle flashes when they shoot, but only in single-player mode.

func (*Buffer) ParsePacket added in v1.0.233

func (p *Buffer) ParsePacket(oldFrames map[int32]*pb.Frame) (*pb.Packet, error)

ParsePacket will parse all the messages in a particular server packet.

func (*Buffer) ParsePacketEntities added in v1.0.233

func (m *Buffer) ParsePacketEntities(from map[int32]*pb.PackedEntity) map[int32]*pb.PackedEntity

ParsePacketEntities will parse an `SVC_PACKETENTITIES` msg. This is the last of the 3-tuple of msgs sent from the server for each frame. There is no delimiter between entities, once the entity is fully parsed it immediately moves on to the next. If the entity number is 0, the end of the clod of ents has been reached.

This has to decompress entities as they're parsed or else there is no way to tell new values from existing. This makes it impossible to decompress all entities after the fact.

func (*Buffer) ParsePrint added in v1.0.233

func (m *Buffer) ParsePrint() *pb.Print

Print messages are sent from the server to all clients when there is something that should be printed in the console of all clients. This includes player chat, obituaries, inventory (out of ammo, cant switch to the railgun).

func (*Buffer) ParseServerData added in v1.0.233

func (m *Buffer) ParseServerData() *pb.ServerInfo

The ServerData message is the first one sent from the server to the client after the client connects. It contains info about the protocol used, the current map name (not the map filename), etc.

func (*Buffer) ParseSound added in v1.0.233

func (m *Buffer) ParseSound() *pb.PackedSound

This is a start-sound packet

func (*Buffer) ParseSpawnBaseline added in v1.0.233

func (m *Buffer) ParseSpawnBaseline() *pb.PackedEntity

A baseline is just a normal entity in its default state, from a client's perspective

func (*Buffer) ParseStuffText added in v1.0.233

func (m *Buffer) ParseStuffText() *pb.StuffText

Stuffs are a way for the server to force a client to execute a command. If a client is connected to a server, it will do anything the server tells it to via a StuffText message. Anything a player can type into their console can be stuff'd to them, including harmful things like `disconnect` or `set rate "10"`.

func (*Buffer) ParseTempEntity added in v1.0.233

func (m *Buffer) ParseTempEntity() *pb.TemporaryEntity

Temporary entities include things like explosions, sparks, and things like projectiles (rockets).

func (*Buffer) ReadByte added in v1.0.233

func (msg *Buffer) ReadByte() int

unsigned

func (*Buffer) ReadByteP added in v1.0.262

func (b *Buffer) ReadByteP() uint32

func (*Buffer) ReadChar added in v1.0.233

func (msg *Buffer) ReadChar() int

1 byte signed

func (*Buffer) ReadCharP added in v1.0.262

func (b *Buffer) ReadCharP() int32

func (*Buffer) ReadCoord added in v1.0.233

func (msg *Buffer) ReadCoord() int

func (*Buffer) ReadData added in v1.0.233

func (msg *Buffer) ReadData(length int) []byte

just grab a subsection of the buffer

func (*Buffer) ReadDirection added in v1.0.233

func (msg *Buffer) ReadDirection() int

func (*Buffer) ReadLong added in v1.0.233

func (msg *Buffer) ReadLong() int

Read 4 bytes and construct a 32 bit signed integer from the data. Using the binary.LittleEndian package for this conversion doesn't work as it only can give you an UNsigned int which is insufficient. Negative delta frame numbers are interpreted as uncompressed and connectionless packets (rcon/etc) have a prefix of -1; we need negative values.

func (*Buffer) ReadLongP added in v1.0.262

func (b *Buffer) ReadLongP() int32

func (*Buffer) ReadPosition added in v1.0.233

func (msg *Buffer) ReadPosition() [3]int

func (*Buffer) ReadShort added in v1.0.233

func (msg *Buffer) ReadShort() int

2 bytes signed

func (*Buffer) ReadShortP added in v1.0.262

func (b *Buffer) ReadShortP() int32

func (*Buffer) ReadString added in v1.0.233

func (msg *Buffer) ReadString() string

Keep building a string until we hit a null

func (*Buffer) ReadVarInt64 added in v1.0.262

func (msg *Buffer) ReadVarInt64() uint64

func (*Buffer) ReadWord added in v1.0.233

func (msg *Buffer) ReadWord() int

2 bytes unsigned

func (*Buffer) ReadWordP added in v1.0.262

func (b *Buffer) ReadWordP() uint32

func (*Buffer) Reset added in v1.0.233

func (m *Buffer) Reset()

Reinitialize the back to zero

func (*Buffer) Rewind added in v1.0.233

func (m *Buffer) Rewind()

Set the internal pointer back to the beginning of the buffer. Same as `seek(0)`

func (*Buffer) Seek added in v1.0.233

func (m *Buffer) Seek(offset int)

Set the internal pointer to a specific value between zero and the langth of the buffer.

func (*Buffer) Size added in v1.0.233

func (m *Buffer) Size() int

Get the length of the current buffer

func (*Buffer) UnreadSize added in v1.0.286

func (m *Buffer) UnreadSize() int

Get the length of the buffer remaining to be read. This is from the current index position to the end.

func (*Buffer) WriteByte added in v1.0.233

func (msg *Buffer) WriteByte(b int)

func (*Buffer) WriteByteP added in v1.0.262

func (b *Buffer) WriteByteP(num uint32)

func (*Buffer) WriteChar added in v1.0.233

func (msg *Buffer) WriteChar(c int)

func (*Buffer) WriteCharP added in v1.0.262

func (b *Buffer) WriteCharP(num int32)

func (*Buffer) WriteCoord added in v1.0.233

func (msg *Buffer) WriteCoord(c int)

func (*Buffer) WriteData added in v1.0.233

func (msg *Buffer) WriteData(data []byte)

func (*Buffer) WriteLong added in v1.0.233

func (msg *Buffer) WriteLong(data int)

4 bytes signed

func (*Buffer) WriteLongP added in v1.0.262

func (b *Buffer) WriteLongP(num int32)

func (*Buffer) WriteShort added in v1.0.233

func (msg *Buffer) WriteShort(s int)

func (*Buffer) WriteShortP added in v1.0.262

func (b *Buffer) WriteShortP(num int32)

func (*Buffer) WriteString added in v1.0.233

func (msg *Buffer) WriteString(s string)

Strings are null terminated, so add a 0x00 at the end.

func (*Buffer) WriteWord added in v1.0.233

func (msg *Buffer) WriteWord(w int)

func (*Buffer) WriteWordP added in v1.0.262

func (b *Buffer) WriteWordP(num uint32)

type ClientPacket

type ClientPacket struct {
	Sequence1   int
	Sequence2   int
	QPort       int  //
	Reliable1   bool // requires an ack
	Reliable2   bool
	MessageType int    // what kind of msg?
	Data        []byte // the actual msg
}

func (ClientPacket) Marshal

func (p ClientPacket) Marshal() []byte

type ConnectionlessPacket

type ConnectionlessPacket struct {
	Sequence int32 // always -1
	Data     string
}

Out of band message

func (ConnectionlessPacket) Marshal

func (cp ConnectionlessPacket) Marshal() []byte

func (ConnectionlessPacket) Send

func (cp ConnectionlessPacket) Send(srv string, port int) (Buffer, error)

type Parser added in v1.0.233

type Parser interface {
	ApplyPacket(packet *pb.Packet)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL