state

package
v0.8.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

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 AddLobby

func AddLobby(lobby *game.Lobby)

AddLobby adds a lobby to the instance, making it visible for GetLobby calls.

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 GetLobby

func GetLobby(id string) *game.Lobby

GetLobby returns a Lobby that has a matching ID or no Lobby if none could be found.

func GetPublicLobbies

func GetPublicLobbies() []*game.Lobby

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

func (v PageStats) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (PageStats) MarshalJSON added in v0.8.3

func (v PageStats) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*PageStats) UnmarshalEasyJSON added in v0.8.3

func (v *PageStats) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*PageStats) UnmarshalJSON added in v0.8.3

func (v *PageStats) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

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