Documentation ¶
Overview ¶
Package extinfo provides easy access to the state information of a Sauerbraten game server (called 'extinfo' in the Sauerbraten source code).
Index ¶
- Constants
- func IsTeamMode(mode string) bool
- type BasicInfo
- type BasicInfoRaw
- type ClientInfo
- type ClientInfoRaw
- type Server
- func (s *Server) GetAllClientInfo() (allClientInfo map[int]ClientInfo, err error)
- func (s *Server) GetBasicInfo() (BasicInfo, error)
- func (s *Server) GetBasicInfoRaw() (basicInfoRaw BasicInfoRaw, err error)
- func (s *Server) GetClientInfo(clientNum int) (clientInfo ClientInfo, err error)
- func (s *Server) GetClientInfoRaw(clientNum int) (clientInfoRaw ClientInfoRaw, err error)
- func (s *Server) GetServerMod() (serverMod string, err error)
- func (s *Server) GetTeamScores() (TeamScores, error)
- func (s *Server) GetTeamScoresRaw() (teamScoresRaw TeamScoresRaw, err error)
- func (s *Server) GetUptime() (uptime int, err error)
- type TeamScore
- type TeamScores
- type TeamScoresRaw
Constants ¶
const ( // Constants describing the type of information to query for InfoTypeExtended byte = 0x00 InfoTypeBasic byte = 0x01 // Constants used in responses to extended info queries ExtInfoACK byte = 0xFF // -1 ExtInfoVersion byte = 105 ExtInfoError byte = 0x01 // Constants describing the type of extended information to query for ExtInfoTypeUptime byte = 0x00 ExtInfoTypeClientInfo byte = 0x01 ExtInfoTypeTeamScores byte = 0x02 // Constants used in responses to client info queries ClientInfoResponseTypeCNs byte = 0xF6 // -10 ClientInfoResponseTypeInfo byte = 0xF5 // -11 )
Protocol constants
const ( MaxPlayerCN = 127 // Highest CN an actual player can have; bots' CNs start at 128 MaxPacketLength = 512 // better to be safe )
Constants generally useful in this package
Variables ¶
This section is empty.
Functions ¶
func IsTeamMode ¶
IsTeamMode returns true when mode is a team mode, false otherwise.
Types ¶
type BasicInfo ¶
type BasicInfo struct { BasicInfoRaw GameMode string `json:"gameMode"` // current game mode MasterMode string `json:"masterMode"` // the current master mode of the server }
BasicInfo contains the parsed information sent back from the server, i.e. game mode and master mode are translated into human readable strings.
type BasicInfoRaw ¶
type BasicInfoRaw struct { NumberOfClients int `json:"numberOfClients"` // the number of clients currently connected to the server (players and spectators) ProtocolVersion int `json:"protocolVersion"` // version number of the protocol in use by the server GameMode int `json:"gameMode"` // current game mode SecsLeft int `json:"secsLeft"` // the time left until intermission in seconds MaxNumberOfClients int `json:"maxNumberOfClients"` // the maximum number of clients the server allows MasterMode int `json:"masterMode"` // the current master mode of the server Paused bool `json:"paused"` // wether the game is paused or not GameSpeed int `json:"gameSpeed"` // the gamespeed Map string `json:"map"` // current map Description string `json:"description"` // server description }
BasicInfoRaw contains the information sent back from the server in their raw form, i.e. no translation from ints to strings, even if possible.
type ClientInfo ¶
type ClientInfo struct { ClientInfoRaw Weapon string `json:"weapon"` // weapon the client currently has selected Privilege string `json:"privilege"` // "none", "master" or "admin" State string `json:"state"` // client state, e.g. "dead" or "spectator" }
ClientInfo contains the parsed information sent back from the server, i.e. weapon, state and privilege are translated into human readable strings.
type ClientInfoRaw ¶
type ClientInfoRaw struct { ClientNum int `json:"clientNum"` // client number or cn Ping int `json:"ping"` // client's ping to server Name string `json:"name"` // Team string `json:"team"` // name of the team the client is on, e.g. "good" Frags int `json:"frags"` // kills Flags int `json:"flags"` // number of flags the player scored Deaths int `json:"deaths"` // Teamkills int `json:"teamkills"` // Accuracy int `json:"accuracy"` // damage the client could have dealt * 100 / damage actually dealt by the client Health int `json:"health"` // remaining HP (health points) Armour int `json:"armour"` // remaining armour Weapon int `json:"weapon"` // weapon the client currently has selected Privilege int `json:"privilege"` // 0 ("none"), 1 ("master"), 2 ("auth") or 3 ("admin") State int `json:"state"` // client state, e.g. 1 ("alive") or 5 ("spectator"), see names.go for int -> string mapping IP net.IP `json:"ip"` // client IP (only the first 3 bytes) }
ClientInfoRaw contains the raw information sent back from the server, i.e. state and privilege are ints.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents a Sauerbraten game server.
func (*Server) GetAllClientInfo ¶
func (s *Server) GetAllClientInfo() (allClientInfo map[int]ClientInfo, err error)
GetAllClientInfo returns the ClientInfo of all Players (including spectators) as a []ClientInfo
func (*Server) GetBasicInfo ¶
GetBasicInfo queries a Sauerbraten server at addr on port and returns the parsed response or an error in case something went wrong. Parsed response means that the int values sent as game mode and master mode are translated into the human readable name, e.g. '12' -> "insta ctf".
func (*Server) GetBasicInfoRaw ¶
func (s *Server) GetBasicInfoRaw() (basicInfoRaw BasicInfoRaw, err error)
GetBasicInfoRaw queries a Sauerbraten server at addr on port and returns the raw response or an error in case something went wrong. Raw response means that the int values sent as game mode and master mode are NOT translated into the human readable name.
func (*Server) GetClientInfo ¶
func (s *Server) GetClientInfo(clientNum int) (clientInfo ClientInfo, err error)
GetClientInfo returns the parsed information about the client with the given clientNum.
func (*Server) GetClientInfoRaw ¶
func (s *Server) GetClientInfoRaw(clientNum int) (clientInfoRaw ClientInfoRaw, err error)
GetClientInfoRaw returns the raw information about the client with the given clientNum.
func (*Server) GetServerMod ¶
GetServerMod returns the name of the mod in use at this server.
func (*Server) GetTeamScores ¶
func (s *Server) GetTeamScores() (TeamScores, error)
GetTeamScores queries a Sauerbraten server at addr on port for the teams' names and scores and returns the parsed response and/or an error in case something went wrong or the server is not running a team mode. Parsed response means that the int value sent as game mode is translated into the human readable name, e.g. '12' -> "insta ctf".
func (*Server) GetTeamScoresRaw ¶
func (s *Server) GetTeamScoresRaw() (teamScoresRaw TeamScoresRaw, err error)
GetTeamScoresRaw queries a Sauerbraten server at addr on port for the teams' names and scores and returns the raw response and/or an error in case something went wrong or the server is not running a team mode.
type TeamScore ¶
type TeamScore struct { Name string `json:"name"` // name of the team, e.g. "good" Score int `json:"score"` // flags in ctf modes, frags in deathmatch modes, points in capture, skulls in collect Bases []int `json:"bases"` // the numbers/IDs of the bases the team possesses (only used in capture modes) }
TeamScore contains the name of the team and the score, i.e. flags scored in flag modes / points gained for holding bases in capture modes / frags achieved in DM modes / skulls collected
type TeamScores ¶
type TeamScores struct { TeamScoresRaw GameMode string `json:"gameMode"` // current game mode }
TeamScores contains the game mode as human readable string, the seconds left in the game, and a slice of TeamScores
type TeamScoresRaw ¶
type TeamScoresRaw struct { GameMode int `json:"gameMode"` // current game mode SecsLeft int `json:"secsLeft"` // the time left until intermission in seconds Scores map[string]TeamScore `json:"scores"` // a team score for each team, mapped to the team's name }
TeamScoresRaw contains the game mode as raw int, the seconds left in the game, and a slice of TeamScores