Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var GameStats = Statistics{ // contains filtered or unexported fields }
GameStats holds current game statistics
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Name string Router *Router DefaultHandlers []*CommandHandler }
Client stoers websocket and current routing data
type Command ¶
type Command struct { Cmd string `json:"cmd"` Data interface{} `json:"data"` }
Command is internal command structure, command usually are sent from server to client
type CommandHandler ¶
type CommandHandler struct { Name string Handle func(Data *json.RawMessage, p *Client) *Result }
CommandHandler handles one command
type CommandJSON ¶
type CommandJSON struct { Cmd string `json:"cmd"` Data *json.RawMessage `json:"data"` }
CommandJSON is model for network commands
type ResponseJSON ¶
ResponseJSON is sent over the web socket to client
type Result ¶
type Result struct { Status int `json:"status"` Data interface{} `json:"data"` }
Result is internal response from command handler
func NewErrorResult ¶
func NewErrorResult(data interface{}) *Result
NewErrorResult creates result with error
func NewSuccessResult ¶
func NewSuccessResult(data interface{}) *Result
NewSuccessResult creates success result
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is set of command handlers
func NewRouter ¶
func NewRouter(handlers []*CommandHandler, c *Client) *Router
NewRouter creates new router instance
func (*Router) SetHandlers ¶
func (r *Router) SetHandlers(handlers []*CommandHandler)
SetHandlers set new handlers for the router
type Statistics ¶
type Statistics struct {
// contains filtered or unexported fields
}
Statistics hold game stats
func (*Statistics) AddPlayedGame ¶
func (s *Statistics) AddPlayedGame()
AddPlayedGame increments played games count
func (*Statistics) OnClientConnected ¶
func (s *Statistics) OnClientConnected()
OnClientConnected - call when client has connected
func (*Statistics) OnClientDisconnected ¶
func (s *Statistics) OnClientDisconnected()
OnClientDisconnected - call when client disconnected
func (*Statistics) ToInfo ¶
func (s *Statistics) ToInfo() *StatisticsInfo
ToInfo get StatisticsInfo intance for current Statistics
type StatisticsInfo ¶
StatisticsInfo is serialized Statistics