Documentation ¶
Index ¶
- Constants
- Variables
- func Encode(messages ...Message) ([]byte, error)
- func IsConnectingMessage(code MessageCode) bool
- func IsEditMessage(code MessageCode) bool
- func IsOwnerOnly(code MessageCode) bool
- func IsServerOnly(code MessageCode) bool
- func IsSpammyMessage(code MessageCode) bool
- type AddBot
- type AmmoState
- type Announce
- type AuthAns
- type AuthChallenge
- type AuthKick
- type AuthTry
- type BaseInfo
- type BaseRegen
- type BaseScore
- type BaseState
- type Bases
- type BotBalance
- type BotLimit
- type CheckMaps
- type ClearBans
- type ClearDemos
- type ClientDisconnected
- type ClientFlagState
- type ClientInitFlags
- type ClientPacket
- type ClientPing
- type ClientPrivilege
- type ClientState
- type ClientTakeFlag
- type ClientTokenState
- type Clipboard
- type Connect
- type Copy
- type CurrentMaster
- type Damage
- type DelBot
- type DeleteCube
- type DemoPacket
- type DemoPlayback
- type DepositTokens
- type Died
- type DropFlag
- type DropTokens
- type EditEntity
- type EditFace
- type EditMaterial
- type EditMode
- type EditTexture
- type EditVSlot
- type EditVar
- type EntityState
- type ExpireTokens
- type Explode
- type ExplodeFX
- type FlagState
- type Flip
- type ForceDeath
- type ForceIntermission
- type FromAI
- type GameSpeed
- type GetDemo
- type GetMap
- type GunSelect
- type Handler
- type Hit
- type HitPush
- type IVec
- type InitAI
- type InitClient
- type InitTokens
- type InvisFlag
- type Item
- type ItemAck
- type ItemList
- type ItemPickup
- type ItemSpawn
- type JumpPad
- type Kick
- type ListDemos
- type MapCRC
- type MapChange
- type MapVote
- type MasterMode
- type Message
- type MessageCode
- type MessageProxy
- func (m *MessageProxy) Intercept(codes ...MessageCode) *Handler
- func (m *MessageProxy) InterceptWith(check func(MessageCode) bool) *Handler
- func (m *MessageProxy) Next(ctx context.Context, codes ...MessageCode) (Message, error)
- func (m *MessageProxy) NextTimeout(ctx context.Context, timeout time.Duration, codes ...MessageCode) (Message, error)
- func (m *MessageProxy) Process(ctx context.Context, channel uint8, message Message) (Message, error)
- func (m *MessageProxy) Remove(handler *Handler)
- func (m *MessageProxy) Take(ctx context.Context, codes ...MessageCode) (Message, error)
- func (m *MessageProxy) Wait(ctx context.Context, codes ...MessageCode) (Message, error)
- func (m *MessageProxy) WaitTimeout(ctx context.Context, timeout time.Duration, codes ...MessageCode) (Message, error)
- type NewMap
- type PackData
- type Packet
- type Paste
- type PauseGame
- type PhysicsState
- type Ping
- type Pong
- type Pos
- type ProxiedMessage
- type RecordDemo
- type Redo
- type Remip
- type Replace
- type ReplenishAmmo
- type ReqAuth
- type ResetFlag
- type Resume
- type ReturnFlag
- type Rotate
- type SayTeam
- type ScoreFlag
- type Selection
- type SendDemo
- type SendDemoList
- type SendMap
- type ServCMD
- type ServerInfo
- type ServerInitFlags
- type ServerMessage
- type ServerTakeFlag
- type SetMaster
- type SetTeam
- type Shoot
- type ShotFX
- type Sound
- type SpawnRequest
- type SpawnResponse
- type SpawnState
- type Spectator
- type StealTokens
- type StopDemo
- type Suicide
- type SwitchModel
- type SwitchName
- type SwitchTeam
- type TakeToken
- type Taunt
- type Team
- type TeamInfo
- type TeamScore
- type Teleport
- type Text
- type TimeUp
- type TokenState
- type TryDropFlag
- type TrySpawn
- type Undo
- type Vec
- type Welcome
Constants ¶
const (
DEFAULT_TIMEOUT = 5 * time.Second
)
const PROTOCOL_VERSION = 260
const RAD = math.Pi / 180.0
Variables ¶
var CLIENT_MESSAGES = make(map[MessageCode]Message)
This does not represent the messages a client or server is permitted to send (= presence here does not imply a message of that type is valid), there are just some differences in message structures depending on whether they came from the client or the server.
var EDIT_MESSAGES = []MessageCode{ N_COPY, N_DELCUBE, N_EDITENT, N_EDITF, N_EDITM, N_EDITT, N_EDITVAR, N_EDITVSLOT, N_FLIP, N_NEWMAP, N_PASTE, N_REMIP, N_REPLACE, N_ROTATE, }
var FAILED = fmt.Errorf("failed to unmarshal message")
var FAILED_EDIT = fmt.Errorf("failed to unmarshal edit message")
var SERVER_MESSAGES = make(map[MessageCode]Message)
var SERVER_ONLY = []MessageCode{ N_SERVINFO, N_INITCLIENT, N_WELCOME, N_MAPCHANGE, N_SERVMSG, N_DAMAGE, N_HITPUSH, N_SHOTFX, N_EXPLODEFX, N_DIED, N_SPAWNSTATE, N_FORCEDEATH, N_TEAMINFO, N_ITEMSPAWN, N_ITEMACC, N_TIMEUP, N_CDIS, N_CURRENTMASTER, N_PONG, N_RESUME, N_BASESCORE, N_BASEINFO, N_BASEREGEN, N_ANNOUNCE, N_SENDDEMOLIST, N_SENDDEMO, N_DEMOPLAYBACK, N_SENDMAP, N_DROPFLAG, N_SCOREFLAG, N_RETURNFLAG, N_RESETFLAG, N_INVISFLAG, N_CLIENT, N_AUTHCHAL, N_INITAI, N_EXPIRETOKENS, N_DROPTOKENS, N_STEALTOKENS, N_DEMOPACKET, }
Functions ¶
func IsConnectingMessage ¶
func IsConnectingMessage(code MessageCode) bool
func IsEditMessage ¶
func IsEditMessage(code MessageCode) bool
func IsOwnerOnly ¶
func IsOwnerOnly(code MessageCode) bool
If a server is not in "open edit" mode and we receive one of these messages from a user who is not the owner, we disconnect and reconnect them.
func IsServerOnly ¶
func IsServerOnly(code MessageCode) bool
func IsSpammyMessage ¶
func IsSpammyMessage(code MessageCode) bool
Types ¶
type AddBot ¶
type AddBot struct {
NumBots int32
}
N_ADDBOT
func (AddBot) Type ¶
func (m AddBot) Type() MessageCode
type Announce ¶
type Announce struct {
Announcement int32
}
N_ANNOUNCE
func (Announce) Type ¶
func (m Announce) Type() MessageCode
type AuthChallenge ¶
N_AUTHCHAL
func (AuthChallenge) Type ¶
func (m AuthChallenge) Type() MessageCode
type Bases ¶
type Bases struct {
Bases []BaseState
}
func (Bases) Type ¶
func (m Bases) Type() MessageCode
type BotBalance ¶
type BotBalance struct {
Balance int32
}
N_BOTBALANCE
func (BotBalance) Type ¶
func (m BotBalance) Type() MessageCode
type BotLimit ¶
type BotLimit struct {
Limit int32
}
N_BOTLIMIT
func (BotLimit) Type ¶
func (m BotLimit) Type() MessageCode
type CheckMaps ¶
type CheckMaps struct { }
N_CHECKMAPS
func (CheckMaps) Type ¶
func (m CheckMaps) Type() MessageCode
type ClearBans ¶
type ClearBans struct { }
N_CLEARBANS
func (ClearBans) Type ¶
func (m ClearBans) Type() MessageCode
type ClearDemos ¶
type ClearDemos struct {
Demo int32
}
N_CLEARDEMOS
func (ClearDemos) Type ¶
func (m ClearDemos) Type() MessageCode
type ClientDisconnected ¶
type ClientDisconnected struct {
Client int32
}
N_CDIS
func (ClientDisconnected) Type ¶
func (m ClientDisconnected) Type() MessageCode
type ClientFlagState ¶
type ClientInitFlags ¶
type ClientInitFlags struct {
Flags []ClientFlagState
}
func (ClientInitFlags) Type ¶
func (m ClientInitFlags) Type() MessageCode
type ClientPing ¶
type ClientPing struct {
Ping int32
}
N_CLIENTPING
func (ClientPing) Type ¶
func (m ClientPing) Type() MessageCode
type ClientState ¶
type ClientTakeFlag ¶
func (ClientTakeFlag) Type ¶
func (m ClientTakeFlag) Type() MessageCode
type ClientTokenState ¶
type Clipboard ¶
type Clipboard PackData
func (Clipboard) Type ¶
func (m Clipboard) Type() MessageCode
type Connect ¶
type Connect struct { Name string Model int32 Password string AuthDescription string AuthName string }
N_CONNECT
func (Connect) Type ¶
func (m Connect) Type() MessageCode
type Copy ¶
type Copy struct {
Sel Selection
}
N_COPY
func (Copy) Type ¶
func (m Copy) Type() MessageCode
type CurrentMaster ¶
type CurrentMaster struct { MasterMode int32 Clients []ClientPrivilege `type:"term"` }
func (CurrentMaster) Type ¶
func (m CurrentMaster) Type() MessageCode
type DelBot ¶
type DelBot struct { }
N_DELBOT
func (DelBot) Type ¶
func (m DelBot) Type() MessageCode
type DeleteCube ¶
type DeleteCube struct {
Sel Selection
}
N_DELCUBE
func (DeleteCube) Type ¶
func (m DeleteCube) Type() MessageCode
type DemoPacket ¶
type DemoPacket struct { }
N_DEMOPACKET
func (DemoPacket) Type ¶
func (m DemoPacket) Type() MessageCode
type DemoPlayback ¶
N_DEMOPLAYBACK
func (DemoPlayback) Type ¶
func (m DemoPlayback) Type() MessageCode
type DepositTokens ¶
type DepositTokens struct { Client int32 Base int32 Deposited int32 Team int32 Score int32 Flags int32 }
N_DEPOSITTOKENS
func (DepositTokens) Type ¶
func (m DepositTokens) Type() MessageCode
type DropTokens ¶
type DropTokens struct { Client int32 Dropx int32 Dropy int32 Dropz int32 Tokens []struct { Token int32 Team int32 Yaw int32 } `type:"term"` }
N_DROPTOKENS
func (DropTokens) Type ¶
func (m DropTokens) Type() MessageCode
type EditEntity ¶
type EditEntity struct { Index int32 Position Vec EntityType int32 Attr1 int32 Attr2 int32 Attr3 int32 Attr4 int32 Attr5 int32 }
N_EDITENT
func (EditEntity) Type ¶
func (m EditEntity) Type() MessageCode
type EditMode ¶
type EditMode struct {
Enabled bool
}
N_EDITMODE
func (EditMode) Type ¶
func (m EditMode) Type() MessageCode
type EntityState ¶
type ExpireTokens ¶
type ExpireTokens struct { Tokens []struct { Token int32 } `type:"term"` }
N_EXPIRETOKENS
func (ExpireTokens) Type ¶
func (m ExpireTokens) Type() MessageCode
type FlagState ¶
type Flip ¶
type Flip struct {
Sel Selection
}
N_FLIP
func (Flip) Type ¶
func (m Flip) Type() MessageCode
type ForceDeath ¶
type ForceDeath struct {
Client int32
}
N_FORCEDEATH
func (ForceDeath) Type ¶
func (m ForceDeath) Type() MessageCode
type ForceIntermission ¶
type ForceIntermission struct { }
N_FORCEINTERMISSION
func (ForceIntermission) Type ¶
func (m ForceIntermission) Type() MessageCode
type FromAI ¶
type FromAI struct {
Qcn int32
}
N_FROMAI
func (FromAI) Type ¶
func (m FromAI) Type() MessageCode
type GetMap ¶
type GetMap struct { }
N_GETMAP
func (GetMap) Type ¶
func (m GetMap) Type() MessageCode
type GunSelect ¶
type GunSelect struct {
GunSelect int32
}
N_GUNSELECT
func (GunSelect) Type ¶
func (m GunSelect) Type() MessageCode
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func (*Handler) Handles ¶
func (h *Handler) Handles(code MessageCode) bool
func (*Handler) Receive ¶
func (h *Handler) Receive() <-chan ProxiedMessage
type IVec ¶
func IVecFromVec ¶
type InitAI ¶
type InitAI struct { Aiclientnum int32 Ownerclientnum int32 Aitype int32 Aiskill int32 Playermodel int32 Name string Team string }
N_INITAI
func (InitAI) Type ¶
func (m InitAI) Type() MessageCode
type InitTokens ¶
type InitTokens struct { TeamScores [2]TeamScore Tokens []TokenState ClientTokens []ClientTokenState `type:"term"` }
func (InitTokens) Type ¶
func (m InitTokens) Type() MessageCode
type ItemList ¶
type ItemList struct {
Items []Item `type:"term"`
}
func (ItemList) Type ¶
func (m ItemList) Type() MessageCode
type ItemPickup ¶
type ItemPickup struct {
Item int32
}
N_ITEMPICKUP
func (ItemPickup) Type ¶
func (m ItemPickup) Type() MessageCode
type ItemSpawn ¶
type ItemSpawn struct {
Index int32
}
N_ITEMSPAWN
func (ItemSpawn) Type ¶
func (m ItemSpawn) Type() MessageCode
type ListDemos ¶
type ListDemos struct { }
N_LISTDEMOS
func (ListDemos) Type ¶
func (m ListDemos) Type() MessageCode
type MasterMode ¶
type MasterMode struct {
MasterMode int32
}
N_MASTERMODE
func (MasterMode) Type ¶
func (m MasterMode) Type() MessageCode
type Message ¶
type Message interface {
Type() MessageCode
}
type MessageCode ¶
type MessageCode int32 // network message code
const ( N_CONNECT MessageCode = iota N_SERVINFO N_WELCOME N_INITCLIENT N_POS N_TEXT N_SOUND N_CDIS N_SHOOT N_EXPLODE N_SUICIDE N_DIED N_DAMAGE N_HITPUSH N_SHOTFX N_EXPLODEFX N_TRYSPAWN N_SPAWNSTATE N_SPAWN N_FORCEDEATH N_GUNSELECT N_TAUNT N_MAPCHANGE N_MAPVOTE N_TEAMINFO N_ITEMSPAWN N_ITEMPICKUP N_ITEMACC N_TELEPORT N_JUMPPAD N_PING N_PONG N_CLIENTPING N_TIMEUP N_FORCEINTERMISSION N_SERVMSG N_ITEMLIST N_RESUME N_EDITMODE N_EDITENT N_EDITF N_EDITT N_EDITM N_FLIP N_COPY N_PASTE N_ROTATE N_REPLACE N_DELCUBE N_REMIP N_EDITVSLOT N_UNDO N_REDO N_NEWMAP N_GETMAP N_SENDMAP N_CLIPBOARD N_EDITVAR N_MASTERMODE N_KICK N_CLEARBANS N_CURRENTMASTER N_SPECTATOR N_SETMASTER N_SETTEAM N_BASES N_BASEINFO N_BASESCORE N_REPAMMO N_BASEREGEN N_ANNOUNCE N_LISTDEMOS N_SENDDEMOLIST N_GETDEMO N_SENDDEMO N_DEMOPLAYBACK N_RECORDDEMO N_STOPDEMO N_CLEARDEMOS N_TAKEFLAG N_RETURNFLAG N_RESETFLAG N_INVISFLAG N_TRYDROPFLAG N_DROPFLAG N_SCOREFLAG N_INITFLAGS N_SAYTEAM N_CLIENT N_AUTHTRY N_AUTHKICK N_AUTHCHAL N_AUTHANS N_REQAUTH N_PAUSEGAME N_GAMESPEED N_ADDBOT N_DELBOT N_INITAI N_FROMAI N_BOTLIMIT N_BOTBALANCE N_MAPCRC N_CHECKMAPS N_SWITCHNAME N_SWITCHMODEL N_SWITCHTEAM N_INITTOKENS N_TAKETOKEN N_EXPIRETOKENS N_DROPTOKENS N_DEPOSITTOKENS N_STEALTOKENS N_SERVCMD N_DEMOPACKET NUMMSG )
const N_EMPTY MessageCode = -1
func (MessageCode) String ¶
func (e MessageCode) String() string
type MessageProxy ¶
type MessageProxy struct {
// contains filtered or unexported fields
}
func NewMessageProxy ¶
func NewMessageProxy(fromClient bool) *MessageProxy
func (*MessageProxy) Intercept ¶
func (m *MessageProxy) Intercept(codes ...MessageCode) *Handler
func (*MessageProxy) InterceptWith ¶
func (m *MessageProxy) InterceptWith(check func(MessageCode) bool) *Handler
func (*MessageProxy) Next ¶
func (m *MessageProxy) Next(ctx context.Context, codes ...MessageCode) (Message, error)
Wait for a message and drop it.
func (*MessageProxy) NextTimeout ¶
func (m *MessageProxy) NextTimeout( ctx context.Context, timeout time.Duration, codes ...MessageCode, ) (Message, error)
func (*MessageProxy) Remove ¶
func (m *MessageProxy) Remove(handler *Handler)
func (*MessageProxy) Take ¶
func (m *MessageProxy) Take( ctx context.Context, codes ...MessageCode, ) (Message, error)
func (*MessageProxy) Wait ¶
func (m *MessageProxy) Wait(ctx context.Context, codes ...MessageCode) (Message, error)
Wait for a message, but don't prevent it from being transmitted.
func (*MessageProxy) WaitTimeout ¶
func (m *MessageProxy) WaitTimeout( ctx context.Context, timeout time.Duration, codes ...MessageCode, ) (Message, error)
type NewMap ¶
type NewMap struct {
Size int32
}
N_NEWMAP
func (NewMap) Type ¶
func (m NewMap) Type() MessageCode
type Paste ¶
type Paste struct {
Sel Selection
}
N_PASTE
func (Paste) Type ¶
func (m Paste) Type() MessageCode
type PhysicsState ¶
type Ping ¶
type Ping struct {
Cmillis int32
}
N_PING
func (Ping) Type ¶
func (m Ping) Type() MessageCode
type Pong ¶
type Pong struct {
Cmillis int32
}
N_PONG
func (Pong) Type ¶
func (m Pong) Type() MessageCode
type Pos ¶
type Pos struct { Client int32 State PhysicsState }
N_POS
func (Pos) Type ¶
func (m Pos) Type() MessageCode
type ProxiedMessage ¶
type ProxiedMessage struct { Message Message Channel uint8 // contains filtered or unexported fields }
func (*ProxiedMessage) Drop ¶
func (p *ProxiedMessage) Drop()
func (*ProxiedMessage) Pass ¶
func (p *ProxiedMessage) Pass()
func (*ProxiedMessage) Replace ¶
func (p *ProxiedMessage) Replace(message Message)
type RecordDemo ¶
type RecordDemo struct {
Enabled int32
}
N_RECORDDEMO
func (RecordDemo) Type ¶
func (m RecordDemo) Type() MessageCode
type ReplenishAmmo ¶
N_REPAMMO
func (ReplenishAmmo) Type ¶
func (m ReplenishAmmo) Type() MessageCode
type ReqAuth ¶
type ReqAuth struct {
Domain string
}
N_REQAUTH
func (ReqAuth) Type ¶
func (m ReqAuth) Type() MessageCode
type Resume ¶
type Resume struct {
Clients []ClientState `type:"term"`
}
N_RESUME
func (Resume) Type ¶
func (m Resume) Type() MessageCode
type SayTeam ¶
type SayTeam struct {
Text string
}
N_SAYTEAM
func (SayTeam) Type ¶
func (m SayTeam) Type() MessageCode
type ScoreFlag ¶
type ScoreFlag struct { Client int32 Relayflag int32 Relayversion int32 Goalflag int32 Goalversion int32 Goalspawn int32 Team int32 Score int32 Oflags int32 }
N_SCOREFLAG
func (ScoreFlag) Type ¶
func (m ScoreFlag) Type() MessageCode
type SendDemoList ¶
type SendDemoList struct { Demos []struct { Info string } }
N_SENDDEMOLIST
func (SendDemoList) Type ¶
func (m SendDemoList) Type() MessageCode
type SendMap ¶
type SendMap struct {
Map []byte
}
N_SENDMAP
func (SendMap) Type ¶
func (m SendMap) Type() MessageCode
type ServCMD ¶
type ServCMD struct {
Command string
}
N_SERVCMD
func (ServCMD) Type ¶
func (m ServCMD) Type() MessageCode
type ServerInfo ¶
type ServerInfo struct { Client int32 Protocol int32 SessionId int32 HasPassword bool Description string Domain string }
N_SERVINFO
func (ServerInfo) Type ¶
func (m ServerInfo) Type() MessageCode
type ServerInitFlags ¶
func (ServerInitFlags) Type ¶
func (m ServerInitFlags) Type() MessageCode
type ServerMessage ¶
type ServerMessage struct {
Text string
}
N_SERVMSG
func (ServerMessage) Type ¶
func (m ServerMessage) Type() MessageCode
type ServerTakeFlag ¶
N_TAKEFLAG
func (ServerTakeFlag) Type ¶
func (m ServerTakeFlag) Type() MessageCode
type Sound ¶
type Sound struct {
Sound int32
}
N_SOUND
func (Sound) Type ¶
func (m Sound) Type() MessageCode
type SpawnRequest ¶
N_SPAWN <- from client
func (SpawnRequest) Type ¶
func (m SpawnRequest) Type() MessageCode
type SpawnResponse ¶
type SpawnResponse struct {
EntityState
}
N_SPAWN <- from server
func (SpawnResponse) Type ¶
func (m SpawnResponse) Type() MessageCode
type SpawnState ¶
type SpawnState struct { Client int32 EntityState }
func (SpawnState) Type ¶
func (m SpawnState) Type() MessageCode
type StealTokens ¶
type StealTokens struct { Client int32 Team int32 Basenum int32 Enemyteam int32 Score int32 Dropx int32 Dropy int32 Dropz int32 Tokens []struct { Token int32 Team int32 Yaw int32 } `type:"term"` }
N_STEALTOKENS
func (StealTokens) Type ¶
func (m StealTokens) Type() MessageCode
type StopDemo ¶
type StopDemo struct { }
N_STOPDEMO
func (StopDemo) Type ¶
func (m StopDemo) Type() MessageCode
type Suicide ¶
type Suicide struct { }
N_SUICIDE
func (Suicide) Type ¶
func (m Suicide) Type() MessageCode
type SwitchModel ¶
type SwitchModel struct {
Model int32
}
N_SWITCHMODEL
func (SwitchModel) Type ¶
func (m SwitchModel) Type() MessageCode
type SwitchName ¶
type SwitchName struct {
Name string
}
N_SWITCHNAME
func (SwitchName) Type ¶
func (m SwitchName) Type() MessageCode
type SwitchTeam ¶
type SwitchTeam struct {
Team string
}
N_SWITCHTEAM
func (SwitchTeam) Type ¶
func (m SwitchTeam) Type() MessageCode
type TeamInfo ¶
type TeamInfo struct {
Teams []Team `type:"term"`
}
func (TeamInfo) Type ¶
func (m TeamInfo) Type() MessageCode
type Text ¶
type Text struct {
Text string
}
N_TEXT
func (Text) Type ¶
func (m Text) Type() MessageCode
type TimeUp ¶
type TimeUp struct {
Remaining int32
}
N_TIMEUP
func (TimeUp) Type ¶
func (m TimeUp) Type() MessageCode
type TokenState ¶
N_INITTOKENS
type TryDropFlag ¶
type TryDropFlag struct { }
N_TRYDROPFLAG
func (TryDropFlag) Type ¶
func (m TryDropFlag) Type() MessageCode
type TrySpawn ¶
type TrySpawn struct { }
N_TRYSPAWN
func (TrySpawn) Type ¶
func (m TrySpawn) Type() MessageCode