Documentation ¶
Index ¶
- Constants
- func KeepRegistered(ctx context.Context, l Registerer, update <-chan time.Time, h GameHost) error
- type Client
- type Game
- type GameAccess
- type GameHost
- type GameInfo
- type GameMode
- type IPResp
- type Lister
- type Lobby
- type PlayerInfo
- type PlayersInfo
- type QuestInfo
- type Registerer
- type Resolution
- type Response
- type Server
- type ServerListResp
- type Service
Constants ¶
const ( ModeKOTR = GameMode("kotr") ModeCTF = GameMode("ctf") ModeFlagBall = GameMode("flagball") ModeChat = GameMode("chat") ModeArena = GameMode("arena") ModeElimination = GameMode("elimination") ModeQuest = GameMode("quest") ModeCoop = GameMode("coop") ModeCustom = GameMode("custom") )
const ( AccessOpen = GameAccess("open") AccessPassword = GameAccess("pass") AccessClosed = GameAccess("closed") )
const (
// DefaultGamePort is a default UDP port for Nox games.
DefaultGamePort = 18590
)
const (
DefaultTimeout = time.Minute
)
Variables ¶
This section is empty.
Functions ¶
func KeepRegistered ¶
KeepRegistered keeps registering server so that it doesn't expire.
The update channel sets a pace for updates. If it's set to nil, a default duration will be used.
Once the channel triggers, GameHost.GameInfo is called to acquire fresh game info.
The function returns when context is canceled, if an error is returned from GameHost.GameInfo, or if lobby becomes unavailable.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an HTTP Nox lobby client.
func NewClientWith ¶
NewClientWith accepts URL and custom HTTP client to use.
func (*Client) RegisterGame ¶
RegisterGame implements Lobby.
func (*Client) SetUserAgent ¶
SetUserAgent sets the User-Agent header for requests. Format should be "AppName/1.2.3". It is advised to set this to something unique for each app using this library.
type Game ¶
type Game struct { Name string `json:"name"` Address string `json:"addr,omitempty"` Port int `json:"port,omitempty"` Map string `json:"map"` Mode GameMode `json:"mode"` Access GameAccess `json:"access,omitempty"` Vers string `json:"vers,omitempty"` Res Resolution `json:"res,omitempty"` Players PlayersInfo `json:"players"` Quest *QuestInfo `json:"quest,omitempty"` }
Game is an information about the Nox game, as provided by the server hosting it. See GameInfo for an information returned by the lobby server.
func GameFromXWIS ¶
GameFromXWIS convert xwis.GameInfo to Game type defined by lobby.
type GameAccess ¶
type GameAccess string
GameAccess specifies access for the game (open, password-protected, etc).
type GameHost ¶
type GameHost interface { // GameInfo returns current information about the active game. GameInfo(ctx context.Context) (*Game, error) }
GameHost is an interface for the game server.
type GameInfo ¶
GameInfo is a full information for a registered Nox game, as returned by the Lobby. It extends Game with additional information.
type IPResp ¶
type IPResp struct {
IP string `json:"ip"`
}
IPResp represents a response to the address request.
type Lister ¶
type Lister interface { // ListGames returns a sorted list of games registered on this lobby. ListGames(ctx context.Context) ([]GameInfo, error) }
Lister is an interface for listing Nox games registered on lobby server.
func Cache ¶
Cache creates a cache over a game Lister. Expiration time controls how often the cache is invalidated.
func NewXWISWithClient ¶
NewXWISWithClient creates a Lister for a Nox XWIS lobby using an existing xwis.Client.
type Lobby ¶
type Lobby interface { Registerer Lister }
Lobby is a Nox game lobby for listing and registering games.
type PlayerInfo ¶
PlayerInfo is an information about a specific player.
type PlayersInfo ¶
type PlayersInfo struct { Cur int `json:"cur"` Max int `json:"max"` List []PlayerInfo `json:"list,omitempty"` }
PlayersInfo is an information about players in a specific game.
func (*PlayersInfo) Clone ¶
func (v *PlayersInfo) Clone() *PlayersInfo
type QuestInfo ¶
type QuestInfo struct {
Stage int `json:"stage"`
}
QuestInfo is additional information for Nox Quest game mode.
type Registerer ¶
type Registerer interface { // RegisterGame registers new game or updates the registration for existing game. // The client must call this method periodically to not let the game registration to expire. // Using a duration smaller than DefaultTimeout is advised. RegisterGame(ctx context.Context, s *Game) error }
Registerer is an interface for registering Nox games on lobby server.
type Resolution ¶
type Resolution struct { HighRes bool `json:"high_res,omitempty"` Width int `json:"width,omitempty"` Height int `json:"height,omitempty"` }
Resolution is a max resolution used for the game. Historically Nox used a limited resolution. For HD-aware servers, HighRes should be set.
func (*Resolution) Clone ¶
func (v *Resolution) Clone() *Resolution
type Response ¶
type Response struct { Result interface{} `json:"data,omitempty"` Err string `json:"error,omitempty"` }
Response wraps all other HTTP responses to separate errors from the rest of the response.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP Nox lobby server.
func (*Server) RegisterServer ¶
func (api *Server) RegisterServer(w http.ResponseWriter, r *http.Request)
func (*Server) ServersList ¶
func (api *Server) ServersList(w http.ResponseWriter, r *http.Request)
type ServerListResp ¶
type ServerListResp []GameInfo
ServerListResp represents a response to the server list request.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is an in-memory implementation of a Lobby.
func (*Service) RegisterGame ¶
RegisterGame implements Lobby.
func (*Service) SetTimeout ¶
SetTimeout sets an expiration time for game registrations.