manager

package
v0.0.0-...-81cb1c0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClientToGame

func AddClientToGame(s *structs.Server, gameid string, client *structs.Client)

AddClientToGame adds the given client to the game with the given ID. If the game does not exist, it is created. The client is appended to the game's client slice. The function is thread-safe.

func AddClientToLobby

func AddClientToLobby(s *structs.Server, lobbyid string, gameid string, client *structs.Client)

AddClientToLobby adds a client to a lobby in a game on a server, or creates the lobby if it doesn't exist. It does nothing if the client is already in the lobby.

func CreateSession

func CreateSession(s *structs.Server, client *structs.Client) error

CreateSession creates a new session for the given client on the server. It returns an error if a session for the client already exists. The function is thread-safe.

func DeleteRelay

func DeleteRelay(s *structs.Server, peer *structs.Client)

DeleteRelay gracefully shuts down a relay peer and then deletes it from the server. This function is thread-safe and can be called from any goroutine.

func DeleteSession

func DeleteSession(s *structs.Server, client *structs.Client) error

DeleteSession deletes a session associated with the given client from the server. It returns an error if the session does not exist. The function is thread-safe.

func DestroyLobby

func DestroyLobby(s *structs.Server, gameid string, lobbyid string)

DestroyLobby destroys a lobby in a game on a server, removing it from the server's Games map. It does nothing if the lobby doesn't exist. It locks the server's Games map and the specific game's Lobbies map for thread safety.

func DoesGameExist

func DoesGameExist(s *structs.Server, gameid string) bool

DoesGameExist checks if a game with the given ID exists on the server. It returns true if the game exists, otherwise false.

func DoesLobbyExist

func DoesLobbyExist(s *structs.Server, lobbyid string, gameid string) bool

DoesLobbyExist checks if a lobby with the given lobbyid exists in a game with the given gameid on the server. It returns true if the lobby exists, otherwise false. The function acquires a read lock on the server's Games map for thread safety while performing the existence checks.

func DoesPeerExist

func DoesPeerExist(s *structs.Server, id string) bool

DoesPeerExist checks if a peer session with the given ID exists on the server. It returns true if the session exists, otherwise false.

func GetAllLobbies

func GetAllLobbies(s *structs.Server, gameid string) []string

GetAllLobbies retrieves all lobbies for a given game, excluding the default lobby entry.

func GetByULID

func GetByULID(s *structs.Server, id string) *structs.Client

GetByULID returns the client associated with the given ULID, or an error if no such client exists.

func GetGamePeers

func GetGamePeers(s *structs.Server, gameid string) []*structs.Client

GetGamePeers returns a slice of all clients in the specified game. The function will panic if the game does not exist. The function is thread-safe.

func GetLobbyHost

func GetLobbyHost(s *structs.Server, lobbyid string, gameid string) (*structs.Client, error)

GetLobbyHost retrieves the host client of a specified lobby in a given game on the server. It returns a pointer to the host client if the lobby exists, or an error if the lobby does not exist. The function locks the server's Games map and the specific lobby's Mutex for thread safety.

func GetLobbyPeers

func GetLobbyPeers(s *structs.Server, lobbyid string, gameid string) []*structs.Client

GetLobbyPeers retrieves all clients in a given lobby in a given game on a server. It returns a slice of client pointers if the game and lobby exist, an empty slice otherwise.

func GetLobbySettings

func GetLobbySettings(s *structs.Server, lobbyid string, gameid string) *structs.LobbySettings

GetLobbySettings retrieves the settings for a specified lobby in a given game on the server. It returns a pointer to the LobbySettings if the lobby exists, or nil if the lobby does not exist. The function locks the server's Games map and the specific lobby's Mutex for thread safety.

func GetRelay

func GetRelay(s *structs.Server, peer *structs.Client) *structs.Relay

GetRelay gets a relay peer from the server. The returned relay is guaranteed to still exist for the duration of the RLock.

func GetRelayPeers

func GetRelayPeers(s *structs.Server, lobbyid string, gameid string) []*structs.Relay

func GetSession

func GetSession(s *structs.Server, id string) *structs.Session

GetSession retrieves the session associated with the given ID from the server. It returns a pointer to the structs.Session if the session exists, or nil if the session does not exist. The function is thread-safe.

func IsClientInGame

func IsClientInGame(s *structs.Server, gameid string, client *structs.Client) bool

IsClientInGame checks if a client is in the specified game on the server. It will panic if the game does not exist. The function is thread-safe.

func IsClientInLobby

func IsClientInLobby(s *structs.Server, lobbyid string, gameid string, client *structs.Client) bool

IsClientInLobby checks if a given client is in a given lobby in a given game on a server. It returns true if the client is in the lobby, false otherwise.

func RemoveClientFromGame

func RemoveClientFromGame(s *structs.Server, gameid string, client *structs.Client)

RemoveClientFromGame removes a client from the specified game on the server. If the game does not exist, the function will panic. The function locks the game's client slice for thread safety while ensuring the client is present before attempting removal.

func RemoveClientFromLobby

func RemoveClientFromLobby(s *structs.Server, lobbyid string, gameid string, client *structs.Client)

RemoveClientFromLobby removes a client from a lobby in a game on a server, if it exists. It does nothing if the client is not in the lobby or if the lobby doesn't exist. It also does nothing if the client doesn't exist on the server.

func RemoveLobbyHost

func RemoveLobbyHost(s *structs.Server, lobbyid string, gameid string, client *structs.Client)

RemoveLobbyHost removes the host of a lobby in a game on a server. It does nothing if the lobby doesn't exist. It locks the server's Games map and the specific game's Lobbies map for thread safety.

func SetLobbyHost

func SetLobbyHost(s *structs.Server, lobbyid string, gameid string, client *structs.Client)

SetLobbyHost sets the host of a lobby in a game on a server. It does nothing if the lobby doesn't exist. It locks the server's Games map and the specific game's Lobbies map for thread safety.

func SetLobbySettings

func SetLobbySettings(s *structs.Server, lobbyid string, gameid string, settings *structs.LobbySettings)

SetLobbySettings sets the settings of a lobby in a game on a server. It panics if the lobby doesn't exist. It locks the server's Games map and the specific lobby's Mutex for thread safety.

func SetRelay

func SetRelay(s *structs.Server, peer *structs.Client, relay *structs.Relay)

SetRelay sets a relay peer for the given peer on the server. The function is thread-safe and can be called from any goroutine. The relay is guaranteed to exist for the duration of the Lock.

func VerifyRelayState

func VerifyRelayState(r *structs.Relay, packet *structs.RelayPacket) error

VerifyRelayState checks the validity of a relay packet's state. It ensures that the recipient field is set and that the recipient exists as a peer on the server. It then verifies whether the recipient peer can be retrieved using its ULID and is part of the same lobby as the relay. Returns an error if any of these validations fail.

func WithoutPeer

func WithoutPeer(clients []*structs.Client, client *structs.Client) []*structs.Client

WithoutPeer returns a slice of all elements in the given slice of clients that are not equal to the given client. Nil elements are also ignored. The returned slice is a new slice and does not modify the original slice in any way.

func WithoutRelay

func WithoutRelay(relays []*structs.Relay, relay *structs.Relay) []*structs.Relay

WithoutRelay returns a slice of all elements in the given slice of relays that are not equal to the given relay. Nil elements are also ignored. The returned slice is a new slice and does not modify the original slice in any way.

Types

This section is empty.

Jump to

Keyboard shortcuts

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