Documentation ¶
Index ¶
- Constants
- type Player
- type Server
- func (g *Server) BroadcastAndPersistStatusUpdate()
- func (g *Server) BroadcastKickUser(userID string)
- func (g *Server) ChangeTopic(newTopic string, newTopicLink string)
- func (g *Server) GetHostIDs() []string
- func (g *Server) GetPlayerStatus() map[string]messaging.CardDeckCards
- func (g *Server) HandleDisconnect(playerID string, reason string) error
- func (g *Server) HandleIncomingHostUpdate(msg *messaging.Container)
- func (g *Server) HandleIncomingPlayerUpdate(msg *messaging.Container)
- func (g *Server) HandleNewPlayer(userID string, hosting bool)
- func (g *Server) LoadFromState() error
- func (g *Server) PersistGameState() error
- func (g *Server) PlayerExists(playerName string) bool
- func (g *Server) PlayerJoinedMajorityVote(msg *messaging.Container) bool
- func (g *Server) ResetPlayerCards()
- func (g *Server) Run()
- func (g *Server) Shutdown(reason string)
- func (g *Server) UpdateGameStatus(playerJoinedMajority bool)
Constants ¶
const ( // TimeFormat is the time format used for storing game updates TimeFormat = "2006-01-02T15:04:05" // IdleTimeout is the timeout after which a game will get terminated automatically after inactivity IdleTimeout = time.Minute * 60 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Player ¶
type Player struct { ID string Card messaging.CardDeckCards IsHost bool }
Player represents one connected client to a game server
type Server ¶
type Server struct { ID string Title string CardDeck messaging.CardDeckType Topic string TopicLink string Players map[string]*Player State messaging.GameStatus Round int32 HighlightedPlayers []string MajorityJoinedPlayers []string MajorityVotedCard messaging.CardDeckCards UnanimousVote bool IncomingMessage chan []byte OutgoingMessage chan *messaging.Container RedisClient *redis.Client Log *log.Entry StartTS time.Time LastUpdatedTS time.Time // contains filtered or unexported fields }
Server represents an instance of a game
func NewServer ¶
func NewServer(title string, cardDeck messaging.CardDeckType, overrideID string, outgoingMessage chan *messaging.Container, redisClient *redis.Client, metricsCollector *instrumentation.MetricsCollector, sessionsURL string) *Server
NewServer creates a new game server object
func (*Server) BroadcastAndPersistStatusUpdate ¶
func (g *Server) BroadcastAndPersistStatusUpdate()
BroadcastAndPersistStatusUpdate broadcasts a status update
func (*Server) BroadcastKickUser ¶
BroadcastKickUser broadcasts a kicked user event to the gateway
func (*Server) ChangeTopic ¶
ChangeTopic changes the topic of a game and starts a fresh round
func (*Server) GetHostIDs ¶
GetHostIDs returns all IDs of a host
func (*Server) GetPlayerStatus ¶
func (g *Server) GetPlayerStatus() map[string]messaging.CardDeckCards
GetPlayerStatus returns a map containing all player states
func (*Server) HandleDisconnect ¶
HandleDisconnect handles the disconnect event of a player
func (*Server) HandleIncomingHostUpdate ¶
HandleIncomingHostUpdate handles an imcoming update of a host
func (*Server) HandleIncomingPlayerUpdate ¶
HandleIncomingPlayerUpdate handles an incoming update of a player
func (*Server) HandleNewPlayer ¶
HandleNewPlayer creates a new player for the game and broadcasts a status update
func (*Server) LoadFromState ¶
LoadFromState loads a game state from redis
func (*Server) PersistGameState ¶
PersistGameState persists the current game state to redis
func (*Server) PlayerExists ¶
PlayerExists determines whether a player exists in the game
func (*Server) PlayerJoinedMajorityVote ¶
PlayerJoinedMajorityVote checks whether a player joined the majority and updates the chosen card accordingly
func (*Server) ResetPlayerCards ¶
func (g *Server) ResetPlayerCards()
ResetPlayerCards sets all player cards to the not chosen state
func (*Server) Run ¶
func (g *Server) Run()
Run orchestrates the main game logic via incoming messages
func (*Server) UpdateGameStatus ¶
UpdateGameStatus calculates the status of a game