Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectionHandler ¶
func ConnectionHandler(game IMessageSource) func(w http.ResponseWriter, r *http.Request)
ConnectionHandler provides incoming message and ping "pump" logic for a given connection
Types ¶
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game encapsulates the core game logic and high-level comms to players
func (*Game) ConnectionStateChanged ¶
func (g *Game) ConnectionStateChanged(connUUID uuid.UUID, conn IMessageSink, state connState)
ConnectionStateChanged informs the game of a new or expired player connection
func (*Game) Init ¶
func (g *Game) Init()
Init initialises the game instance - do not call this if NewGame was used
func (*Game) IsAcceptingConnections ¶
IsAcceptingConnections indicates if the game can accept more player connections
type IMessageSink ¶
IMessageSink defines how the game interfaces with the underlying sockets
type IMessageSource ¶
type IMessageSource interface { IsAcceptingConnections() bool ConnectionStateChanged(uuid.UUID, IMessageSink, connState) ProcessRequest(uuid.UUID, interface{}, reflect.Type) }
IMessageSource defines how the ingress socket events are pumped to the game
type Message ¶
type Message struct { Kind string `json:"kind"` // Data is a base64-encoded JSON string whose decoded bytes can be marshalled into a request or response type Data string `json:"data"` }
Message represents a request or response that can travel over a connection
type MessageSink ¶
MessageSink provides an implementation of the IMessageSink interface
func (MessageSink) Close ¶
func (m MessageSink) Close() error
Close closes the underlying connection
func (MessageSink) Send ¶
func (m MessageSink) Send(response interface{}) error
Send attempts to send a response-type message through the underlying connection