game

package
v0.0.0-...-0697ce9 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

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 NewGame

func NewGame() *Game

NewGame builds a new game instance and calls Init()

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

func (g *Game) IsAcceptingConnections() bool

IsAcceptingConnections indicates if the game can accept more player connections

func (*Game) ProcessRequest

func (g *Game) ProcessRequest(connUUID uuid.UUID, request interface{}, requestType reflect.Type)

ProcessRequest informs the game about a request received over a player connection

type IMessageSink

type IMessageSink interface {
	Send(interface{}) error
	Close() error
}

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

type MessageSink struct {
	ConnID     uuid.UUID
	Connection *websocket.Conn
}

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

Jump to

Keyboard shortcuts

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