helpers

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: 8 Imported by: 0

Documentation

Overview

Package helpers has generic implementations of finicky methods, like Moves(), ListGames() that are appropriate for storage managers who don't get a performance boost from well-crafted queries to use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListGamesHelper

func ListGamesHelper(s AllGamesStorageManager, max int, list listing.Type, userID string, gameType string) []*extendedgame.CombinedStorageRecord

ListGamesHelper is an implementation for ListGames() if the underlying storage manager can't do any better than walking through each game anyway. Note that your StorageManager must implement AllGames().

func MovesHelper

func MovesHelper(s boardgame.StorageManager, gameID string, fromVersion, toVersion int) ([]*boardgame.MoveStorageRecord, error)

MovesHelper is an implementation for Moves() if the underlying storage manager can't do any better than just repeated calls to Move() anyway.

Types

type AllGamesStorageManager

type AllGamesStorageManager interface {
	api.StorageManager
	//AllGames simply returns all games
	AllGames() []*boardgame.GameStorageRecord
}

AllGamesStorageManager wraps normal storage manager but also has an AllGames method.

type ExtendedMemoryStorageManager

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

ExtendedMemoryStorageManager implements the ExtendedGame methods (i.e the methods in server.StorageManager) in memory. Designed to be embedded anonymously in the containing item. Get a new one from NewExtendedMemoryStorageManager.

func NewExtendedMemoryStorageManager

func NewExtendedMemoryStorageManager(checker GameChecker) *ExtendedMemoryStorageManager

NewExtendedMemoryStorageManager returns a new extended memory storage manager. Checker is generally the storage manager you're embedded in.

func (*ExtendedMemoryStorageManager) AgentState

func (s *ExtendedMemoryStorageManager) AgentState(gameID string, player boardgame.PlayerIndex) ([]byte, error)

AgentState implements the AgentState part of the interface.

func (*ExtendedMemoryStorageManager) CleanUp

func (s *ExtendedMemoryStorageManager) CleanUp()

CleanUp is a no op

func (*ExtendedMemoryStorageManager) Close

func (s *ExtendedMemoryStorageManager) Close()

Close is a no op

func (*ExtendedMemoryStorageManager) CombinedGame

CombinedGame implements that part of the server interface.

func (*ExtendedMemoryStorageManager) Connect

func (s *ExtendedMemoryStorageManager) Connect(config string) error

Connect is a no op

func (*ExtendedMemoryStorageManager) ConnectCookieToUser

func (s *ExtendedMemoryStorageManager) ConnectCookieToUser(cookie string, user *users.StorageRecord) error

ConnectCookieToUser implements that part of the server storage interface. 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.

func (*ExtendedMemoryStorageManager) ExtendedGame

ExtendedGame will return extendedgame.DefaultStorageRecord() if the associated game exists.

func (*ExtendedMemoryStorageManager) FetchInjectedDataForGame

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

FetchInjectedDataForGame can just return nil

func (*ExtendedMemoryStorageManager) GetUserByCookie

func (s *ExtendedMemoryStorageManager) GetUserByCookie(cookie string) *users.StorageRecord

GetUserByCookie implements that part of the server storage interface.

func (*ExtendedMemoryStorageManager) GetUserByID

GetUserByID implements that part of the server storage interface.

func (*ExtendedMemoryStorageManager) PlayerMoveApplied

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

PlayerMoveApplied is a no op

func (*ExtendedMemoryStorageManager) SaveAgentState

func (s *ExtendedMemoryStorageManager) SaveAgentState(gameID string, player boardgame.PlayerIndex, state []byte) error

SaveAgentState implements that part of the StorageManager interface.

func (*ExtendedMemoryStorageManager) SetPlayerForGame

func (s *ExtendedMemoryStorageManager) SetPlayerForGame(gameID string, playerIndex boardgame.PlayerIndex, userID string) error

SetPlayerForGame implemnts that part of the server storage interface.

func (*ExtendedMemoryStorageManager) UpdateExtendedGame

func (s *ExtendedMemoryStorageManager) UpdateExtendedGame(id string, eGame *extendedgame.StorageRecord) error

UpdateExtendedGame implements that part of the server storage interface

func (*ExtendedMemoryStorageManager) UpdateUser

UpdateUser stores or update all fields

func (*ExtendedMemoryStorageManager) UserIDsForGame

func (s *ExtendedMemoryStorageManager) UserIDsForGame(gameID string) []string

UserIDsForGame implements that part of the server storage interface.

func (*ExtendedMemoryStorageManager) WithManagers

func (s *ExtendedMemoryStorageManager) WithManagers(managers []*boardgame.GameManager)

WithManagers is a no op

type GameChecker

type GameChecker interface {
	Game(gameID string) (*boardgame.GameStorageRecord, error)
}

GameChecker is just one meethod to fetch a Game given an ID. It's typically just the storage manager you're embedded in but can be other objects in other cases, thus why it's split out separately.

Jump to

Keyboard shortcuts

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