Documentation ¶
Overview ¶
Package state provides the application state. Currently this is only the open lobbies. However, the lobby state itself is managed in the game package. On top of this, we automatically clean up deserted lobbies in this package, as it is much easier in a centralized places and also protects us from flooding the server with goroutines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetActiveLobbyCount ¶
func GetActiveLobbyCount() int
GetActiveLobbyCount indicates how many activate lobby there are. This includes both private and public lobbies and it doesn't matter whether the game is already over, hasn't even started or is still ongoing.
func GetPublicLobbies ¶
GetPublicLobbies returns all lobbies with their public flag set to true. This implies that the lobbies can be found in the lobby browser ob the homepage.
func LaunchCleanupRoutine ¶
func LaunchCleanupRoutine(cfg config.LobbyCleanup)
LaunchCleanupRoutine starts a task to clean up empty lobbies. An empty lobby is a lobby where all players have been disconnected for a certain timeframe. This avoids deleting lobbies when the creator of a lobby accidentally reconnects or needs to refresh. Another scenario might be where the server loses it's connection to all players temporarily. While unlikely, we'll be able to preserve lobbies this way. This method shouldn't be called more than once. Initially this was part of this packages init method, however, in order to avoid side effects in tests, this has been moved into a public function that has to be called manually.
func RemoveLobby ¶
func RemoveLobby(id string)
RemoveLobby deletes a lobby, not allowing anyone to connect to it again.
func ShutdownLobbiesGracefully ¶
func ShutdownLobbiesGracefully()
ShutdownLobbiesGracefully shuts down all lobbies and removes them from the state, preventing reconnects to existing lobbies. New lobbies can technically still be added.
Types ¶
type PageStats ¶ added in v0.8.3
type PageStats struct { ActiveLobbyCount int `json:"activeLobbyCount"` PlayersCount uint64 `json:"playersCount"` OccupiedPlayerSlotCount uint64 `json:"occupiedPlayerSlotCount"` ConnectedPlayersCount uint64 `json:"connectedPlayersCount"` }
PageStats represents dynamic information about the website.
func Stats ¶
func Stats() *PageStats
Stats delivers information about the state of the service. Currently this is lobby and player counts.
func (PageStats) MarshalEasyJSON ¶ added in v0.8.3
MarshalEasyJSON supports easyjson.Marshaler interface
func (PageStats) MarshalJSON ¶ added in v0.8.3
MarshalJSON supports json.Marshaler interface
func (*PageStats) UnmarshalEasyJSON ¶ added in v0.8.3
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*PageStats) UnmarshalJSON ¶ added in v0.8.3
UnmarshalJSON supports json.Unmarshaler interface