api

package
v0.0.0-...-6b15219 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the main server object.

func NewServer

func NewServer(storage *ServerStorageManager, delegates ...boardgame.GameDelegate) *Server

NewServer returns a new server. Get it to run by calling Start(). storage should a *ServerStorageManager, which can be created either from NewServerStorageManager.

Use it like so:

func main() {
	storage := server.NewServerStorageManager(bolt.NewStorageManager(".database"))
	defer storage.Close()
	server.NewServer(storage, mygame.NewManager(storage)).Start()
}

func (*Server) AddOverrides

func (s *Server) AddOverrides(overrides []config.OptionOverrider) *Server

AddOverrides defines overrides that will be applied on top of the config we load. We return a reference to ourself to allow chaining of configurations.

func (*Server) Start

func (s *Server) Start()

Start is where you start the server, and it never returns until it's time to shut down.

type ServerStorageManager

type ServerStorageManager struct {
	StorageManager
	// contains filtered or unexported fields
}

ServerStorageManager implements the ServerStorage interface by wrapping an object that supports StorageManager.

func NewServerStorageManager

func NewServerStorageManager(manager StorageManager) *ServerStorageManager

NewServerStorageManager takes an object that implements StorageManager and wraps it.

func (*ServerStorageManager) FetchInjectedDataForGame

func (s *ServerStorageManager) FetchInjectedDataForGame(gameID string, dataType string) interface{}

FetchInjectedDataForGame is where the server signals to SeatPlayer that there's a player to be seated.

func (*ServerStorageManager) PlayerMoveApplied

func (s *ServerStorageManager) PlayerMoveApplied(game *boardgame.GameStorageRecord) error

PlayerMoveApplied notifies all clients connected vie an active WebSocket for that game that the game has been modified.

type StorageManager

type StorageManager interface {

	//StorageManager extends the boardgame.StorageManager interface. Those
	//methods have two additional semantic expectations, however:
	//SaveGameAndCurrentState should create an ExtendedGameStorageRecord on
	//the first save of a game.
	boardgame.StorageManager

	//Name returns the name of the storage manager type, for example "memory", "bolt", or "mysql"
	Name() string

	//WithManagers is called during set up with references to all of the
	//managers. Will be called before Connect() is called.
	WithManagers(managers []*boardgame.GameManager)

	//Connect will be called before issuing any other substantive calls. The
	//config string is specific to the type of storage layer, which can be
	//interrogated with Nmae().
	Connect(config string) error

	//ExtendedGame is like Game(), but it returns an extended storage record
	//with additional fields necessary for Server.
	ExtendedGame(id string) (*extendedgame.StorageRecord, error)

	CombinedGame(id string) (*extendedgame.CombinedStorageRecord, error)

	//UpdateExtendedGame updates the extended game with the given Id.
	UpdateExtendedGame(id string, eGame *extendedgame.StorageRecord) error

	//Close should be called before the server is shut down.
	Close()

	//ListGames should list up to max games, in descending order based on the
	//LastActivity. If gameType is not "", only returns games that are that
	//gameType. If gameType is "", all gametypes are fine.
	ListGames(max int, list listing.Type, userID string, gameType string) []*extendedgame.CombinedStorageRecord

	//UserIDsForGame returns an array whose length equals game.NumPlayers.
	//Each one is either empty if there is no user in that slot yet, or the
	//uid representing the user.
	UserIDsForGame(gameID string) []string

	SetPlayerForGame(gameID string, playerIndex boardgame.PlayerIndex, userID string) error

	//Store or update all fields
	UpdateUser(user *users.StorageRecord) error

	GetUserByID(uid string) *users.StorageRecord

	GetUserByCookie(cookie string) *users.StorageRecord

	//If user is nil, the cookie should be deleted if it exists. If the user
	//does not yet exist, it should be added to the database.
	ConnectCookieToUser(cookie string, user *users.StorageRecord) error
}

StorageManager extends the base boardgame.StorageManager with a few more methods necessary to make server work. When creating a new Server, you need to pass in a ServerStorageManager, which wraps one of these objects and thus implements these methods, too.

Directories

Path Synopsis
Package extendedgame is the definition of a StorageRecord for ExtendedGame.
Package extendedgame is the definition of a StorageRecord for ExtendedGame.
Package listing is a simple package of constants for listing of games, primarily in a separate package to avoid circular dependencies.
Package listing is a simple package of constants for listing of games, primarily in a separate package to avoid circular dependencies.

Jump to

Keyboard shortcuts

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