core

package
v0.0.0-...-3ed2db9 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func NewClient

func NewClient(ws *websocket.Conn, handlers []*CommandHandler) *Client

NewClient creates

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

type ResponseJSON struct {
	Cmd    string  `json:"cmd"`
	Result *Result `json:"result"`
}

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) Listen

func (r *Router) Listen(conn *websocket.Conn)

Listen handles web socket read

func (*Router) Send

func (r *Router) Send(cmd string, data interface{})

Send data to client

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

type StatisticsInfo struct {
	GamesPlayed      int64
	ClientsConnected int64
	Uptime           string
}

StatisticsInfo is serialized Statistics

Jump to

Keyboard shortcuts

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