Documentation ¶
Index ¶
- Constants
- Variables
- func AddBot(t *Table)
- func CreateFakeRPCInterface()
- func DestroyFakeRPCInterface()
- func HideCardsForUID(state *pb.TableState, uid uint64) *pb.TableState
- func SetTableConfig(config *TableConfig)
- func Start()
- func UseLogger(l *zap.Logger)
- func WaitGameServerShutdown()
- type Client
- type Flag
- type FrameHandler
- type HandleResult
- type InFrame
- type PlayerState
- func (p PlayerState) CalculateScore() int32
- func (p PlayerState) CardIndex(card uint8) int
- func (p *PlayerState) ClearFlag(flag int32)
- func (p PlayerState) Dump() *pb.UnoPlayer
- func (p PlayerState) IsFlagSet(flag int32) bool
- func (p *PlayerState) ResetForNewGame()
- func (p *PlayerState) SetFlag(flag int32)
- func (p PlayerState) String() string
- type RegisterRequest
- type Table
- type TableConfig
Constants ¶
const ( // FlagOffline indicates the client is disconnected, shall be remove after the game is over FlagOffline = 0x1 // FlagKicked indicates the client is safe to removed from game FlagKicked = 0x2 )
const ( StageIdle = 0 // wait for enough players to start the game StageWait = 1 // the game is about to start in few seconds StagePlaying = 2 // the game is running StageGameOver = 3 // the game is just finished yet, will change to wait in few seconds StagePrepare = 4 // hidden stage for client to show the game start animations, will change to StagePlaying in a few seconds )
Stages
Variables ¶
var ( // Register channel for register client to game server Register chan *RegisterRequest // Unregister channel for unregister client from game server Unregister chan uint64 )
Functions ¶
func CreateFakeRPCInterface ¶
func CreateFakeRPCInterface()
CreateFakeRPCInterface creates two channel as fake rpc interface
func DestroyFakeRPCInterface ¶
func DestroyFakeRPCInterface()
DestroyFakeRPCInterface deletes the two channels
func HideCardsForUID ¶
func HideCardsForUID(state *pb.TableState, uid uint64) *pb.TableState
HideCardsForUID will hide other player's cards for player with given uid
func WaitGameServerShutdown ¶
func WaitGameServerShutdown()
WaitGameServerShutdown waits for game server to shutdown
Types ¶
type Client ¶
type Client struct { // UID user unique ID UID uint64 // In channel for receiving frames from session in agent In chan pb.Frame // Out channel for sending frames to session in agent Out chan pb.Frame // TID ID of the table this client play on TID uint64 // Die channel as signal to indicate game server to remove this client Die chan struct{} // contains filtered or unexported fields }
Client holds client's uid and channels for communicate
func (*Client) ClearFlagKicked ¶
func (c *Client) ClearFlagKicked()
ClearFlagKicked clears the FlagKicked bit
func (*Client) ClearFlagOffline ¶
func (c *Client) ClearFlagOffline()
ClearFlagOffline clears the FlagOffline bit
func (Client) IsFlagKickedSet ¶
IsFlagKickedSet returns true if the FlagKicked is set
func (Client) IsFlagOfflineSet ¶
IsFlagOfflineSet returns true if the FlagOffline is set
func (*Client) SetFlagKicked ¶
func (c *Client) SetFlagKicked()
SetFlagKicked sets the FlagKicked bit
func (*Client) SetFlagOffline ¶
func (c *Client) SetFlagOffline()
SetFlagOffline sets the FlagOffline bit
type FrameHandler ¶
FrameHandler process client frames
func (*FrameHandler) String ¶
func (h *FrameHandler) String() string
type HandleResult ¶
type HandleResult struct { Body []byte Status int32 Events []*pb.SingleEvent GameOver bool Msg string Err error }
HandleResult wraps up handler function results
type PlayerState ¶
type PlayerState struct { UID uint64 // uid Flag int32 // flags Cards []uint8 // cards Timeout bool // timeout Score int32 // player score }
PlayerState holds player status, for it is more related to table not client
func NewPlayerState ¶
func NewPlayerState(uid uint64) *PlayerState
NewPlayerState creates and returns pointer to a new PlayerState instance
func (PlayerState) CalculateScore ¶
func (p PlayerState) CalculateScore() int32
CalculateScore convert cards to score after game over
func (PlayerState) CardIndex ¶
func (p PlayerState) CardIndex(card uint8) int
CardIndex return index of the card, if not exist, -1 will be returned
func (*PlayerState) ClearFlag ¶
func (p *PlayerState) ClearFlag(flag int32)
ClearFlag clear flag bit
func (PlayerState) Dump ¶
func (p PlayerState) Dump() *pb.UnoPlayer
Dump convert PlayerState to pb.UnoPlayer
func (PlayerState) IsFlagSet ¶
func (p PlayerState) IsFlagSet(flag int32) bool
IsFlagSet returns true if flag is set
func (*PlayerState) ResetForNewGame ¶
func (p *PlayerState) ResetForNewGame()
ResetForNewGame reset player state for new game
func (PlayerState) String ¶
func (p PlayerState) String() string
type RegisterRequest ¶
type RegisterRequest struct { // UID user unique ID UID uint64 // ClientEntry to receive client instance ClientEntry chan *Client }
RegisterRequest ...
type Table ¶
type Table struct { // TID table ID TID uint64 // Stage see stage constants Stage int // Clockwise indicates the current order is clockwise, otherwise CCW Clockwise bool // Current color Color uint8 // ChallengeColor for challenge ChallengeColor uint8 // LastPlayer UID of last player LastPlayer uint64 // CurrentPlayer UID of current player CurrentPlayer uint64 // Deck on this table Deck *uno.Deck // Discard holds uno cards that has been discard Discard []uint8 // DeckRecycled indicates if the deck has been recycled DeckRecycled bool // Timeout for the stage, in seconds Timeout int // TimeLeft for seconds left TimeLeft int // States array of player state States []*PlayerState // Clients array of clients Clients []*Client // Register channel for client Register chan *RegisterRequest // InFrames from clients InFrames chan *InFrame // contains filtered or unexported fields }
Table holds state of an uno game
func (Table) DumpState ¶
func (t Table) DumpState() *pb.TableState
DumpState dumps table status and returns in TableState
type TableConfig ¶
type TableConfig struct { TurnTimeout int // timeout of a turn GameOverTimeout int // timeout of game over IdleTimeout int // timeout before adding bots WaitTimeout int // timeout before starting a game PrepareTimeout int // timeout before playing AIAssistantMinTimeout int // minimum timeout for AI to kick in AIAssistantMaxTimeout int // maximum timeout for AI to kick in MinPlayers int // minimum players to start the game MaxPlayers int // maximum players a game can play with FrameQueueSize int // input frame queue size }
TableConfig holds table timeout configs