Documentation ¶
Index ¶
- Constants
- Variables
- type Match
- type MatchDetails
- type MatchGenerator
- type MatchingServer
- func (matchingServer *MatchingServer) LiveMatches() []*Match
- func (matchingServer *MatchingServer) MatchPlayer(player *Player)
- func (matchingServer *MatchingServer) StartCustomMatchServers(maxConcurrentGames int, matchGenerator MatchGenerator, quit chan bool)
- func (matchingServer *MatchingServer) StartMatchServers(maxConcurrentGames int, quit chan bool)
- type Player
- func (player *Player) ClientConnectToPlayer()
- func (player *Player) ClientDisconnectFromPlayer()
- func (player *Player) Color() model.Color
- func (player *Player) GetAsyncUpdate() *ResponseAsync
- func (player *Player) GetMatch() *Match
- func (player *Player) GetSearchingForMatch() bool
- func (player *Player) GetSyncUpdate() *model.MoveRequest
- func (player *Player) HasMatchStarted(ctx context.Context) bool
- func (player *Player) MakeMove(pieceMove model.MoveRequest) bool
- func (player *Player) MakeMoveWS(pieceMove model.MoveRequest)
- func (player *Player) MatchMaxTimeMs() int64
- func (player *Player) MatchedOpponentName() string
- func (player *Player) Name() string
- func (player *Player) RequestAsync(requestAsync RequestAsync)
- func (player *Player) Reset()
- func (player *Player) SetMatch(match *Match)
- func (player *Player) SetSearchingForMatch(searchingForMatch bool)
- func (player *Player) WaitForMatchOver()
- func (player *Player) WaitForMatchStart() error
- type RequestAsync
- type ResponseAsync
- type ResponseSync
- type WebsocketRequest
- type WebsocketRequestType
- type WebsocketResponse
- type WebsocketResponseType
Constants ¶
const ( // NullT is the WS response type for a null response NullT = WebsocketResponseType(iota) // RequestSyncT is the WS request type for a sync request RequestSyncT = WebsocketRequestType(iota) // RequestAsyncT is the WS request type for an async request RequestAsyncT = WebsocketRequestType(iota) // ResponseSyncT is the WS response type for a sync response ResponseSyncT = WebsocketResponseType(iota) // ResponseAsyncT is the WS response type for an async response ResponseAsyncT = WebsocketResponseType(iota) // OpponentPlayedMoveT is the WS response type for an opponent's move OpponentPlayedMoveT = WebsocketResponseType(iota) )
Variables ¶
var ( // PollingDefaultTimeout is the default timeout for http requests PollingDefaultTimeout time.Duration = 10 * time.Second )
Functions ¶
This section is empty.
Types ¶
type Match ¶
Match is a struct representing a game between two players
func DefaultMatchGenerator ¶
DefaultMatchGenerator default match generator
func (*Match) GetRequestedDraw ¶
GetRequestedDraw get the current player who has requested a draw
func (*Match) PlayerName ¶
PlayerName get the player name corresponding to the input color
func (*Match) PlayerRemainingTimeMs ¶
PlayerRemainingTimeMs get the player corresponding to the input color
func (*Match) SetRequestedDraw ¶
SetRequestedDraw store the fact that the player has requested a draw
type MatchDetails ¶
MatchDetails is a struct for the matched response
type MatchGenerator ¶
MatchGenerator takes two players and creates a match
func CreateCustomMatchGenerator ¶
func CreateCustomMatchGenerator(matchPlayerTimeSeconds int) MatchGenerator
CreateCustomMatchGenerator create a generator that creates matches with a custom match length in seconds
type MatchingServer ¶
type MatchingServer struct {
// contains filtered or unexported fields
}
MatchingServer handles matching players and carrying out the game
func NewMatchingServer ¶
func NewMatchingServer() MatchingServer
NewMatchingServer create a matching server with no engine
func NewMatchingServerWithEngine ¶
func NewMatchingServerWithEngine( engineAddr string, maxMatchingDuration time.Duration, engineConnTimeout time.Duration, ) MatchingServer
NewMatchingServerWithEngine create a matching server with an engine
func (*MatchingServer) LiveMatches ¶
func (matchingServer *MatchingServer) LiveMatches() []*Match
LiveMatches current matches being played
func (*MatchingServer) MatchPlayer ¶
func (matchingServer *MatchingServer) MatchPlayer(player *Player)
MatchPlayer queues the player for matching
func (*MatchingServer) StartCustomMatchServers ¶
func (matchingServer *MatchingServer) StartCustomMatchServers( maxConcurrentGames int, matchGenerator MatchGenerator, quit chan bool, )
StartCustomMatchServers using custom match generator
func (*MatchingServer) StartMatchServers ¶
func (matchingServer *MatchingServer) StartMatchServers( maxConcurrentGames int, quit chan bool, )
StartMatchServers using default match generator
type Player ¶
type Player struct { ResponseChanSync chan ResponseSync RequestChanAsync chan RequestAsync ResponseChanAsync chan ResponseAsync OpponentPlayedMove chan model.MoveRequest // contains filtered or unexported fields }
Player is a struct representing a matchserver client, containing channels for communications between the client and the the matchserver
func (*Player) ClientConnectToPlayer ¶
func (player *Player) ClientConnectToPlayer()
ClientConnectToPlayer ensures that only one client is connected to the player at a time (even if two client's have the session token)
func (*Player) ClientDisconnectFromPlayer ¶
func (player *Player) ClientDisconnectFromPlayer()
ClientDisconnectFromPlayer ensures that only one client is connected to the player at a time (even if two client's have the session token)
func (*Player) GetAsyncUpdate ¶
func (player *Player) GetAsyncUpdate() *ResponseAsync
GetAsyncUpdate get the next async update for a player
func (*Player) GetSearchingForMatch ¶
GetSearchingForMatch get searching for match
func (*Player) GetSyncUpdate ¶
func (player *Player) GetSyncUpdate() *model.MoveRequest
GetSyncUpdate get the next sync update for a player
func (*Player) HasMatchStarted ¶
HasMatchStarted player checks if their match has started
func (*Player) MakeMove ¶
func (player *Player) MakeMove(pieceMove model.MoveRequest) bool
MakeMove player makes a move
func (*Player) MakeMoveWS ¶
func (player *Player) MakeMoveWS(pieceMove model.MoveRequest)
MakeMoveWS player (websocket client) make a move
func (*Player) MatchMaxTimeMs ¶
MatchMaxTimeMs returns players max time in ms
func (*Player) MatchedOpponentName ¶
MatchedOpponentName returns the matched opponent name
func (*Player) RequestAsync ¶
func (player *Player) RequestAsync(requestAsync RequestAsync)
RequestAsync player makes an async request
func (*Player) SetSearchingForMatch ¶
SetSearchingForMatch set searching for match
func (*Player) WaitForMatchOver ¶
func (player *Player) WaitForMatchOver()
WaitForMatchOver used by client servers to synchronize around match ending
func (*Player) WaitForMatchStart ¶
WaitForMatchStart player waits for match start
type RequestAsync ¶
type RequestAsync struct {
Match, RequestToDraw, Resign bool
}
RequestAsync represents a request from the client unrelated to a move
type ResponseAsync ¶
type ResponseAsync struct {
GameOver, RequestToDraw, Draw, Resignation, Timeout, Matched bool
Winner string
MatchDetails MatchDetails
}
ResponseAsync represents a response to the client unrelated to a move
type ResponseSync ¶
ResponseSync represents a response to the client related to a move
type WebsocketRequest ¶
type WebsocketRequest struct { WebsocketRequestType WebsocketRequestType RequestSync model.MoveRequest RequestAsync RequestAsync }
WebsocketRequest is a struct for a request over the WS conn
type WebsocketRequestType ¶
type WebsocketRequestType uint8
WebsocketRequestType represents the different type of requests supported over the WS conn
type WebsocketResponse ¶
type WebsocketResponse struct { WebsocketResponseType WebsocketResponseType ResponseSync ResponseSync ResponseAsync ResponseAsync OpponentPlayedMove model.MoveRequest }
WebsocketResponse is a struct for a response over the WS conn
type WebsocketResponseType ¶
type WebsocketResponseType uint8
WebsocketResponseType represents the different type of responses supported over the WS conn