mchess-server/usher/usher.go

46 lines
948 B
Go
Raw Normal View History

package usher
import (
2023-06-25 14:11:29 +00:00
"mchess_server/chess"
lobbies "mchess_server/lobby_registry"
"mchess_server/utils"
)
type Usher struct {
}
var instance *Usher
func newUsher() *Usher {
return &Usher{}
}
func GetUsher() *Usher {
if instance == nil {
instance = newUsher()
}
return instance
}
func (u *Usher) WelcomeNewPlayer(player *chess.Player) *lobbies.Lobby {
lobby := lobbies.GetLobbyRegistry().GetLobbyForPlayer()
return lobby
}
2023-06-29 23:50:04 +00:00
func (u *Usher) CreateNewPrivateLobby(player *chess.Player) *lobbies.Lobby {
lobby := lobbies.GetLobbyRegistry().CreateNewPrivateLobby()
return lobby
2023-06-28 17:51:36 +00:00
}
func (u *Usher) FindExistingPrivateLobby(p utils.Passphrase) *lobbies.Lobby {
2023-06-29 23:50:04 +00:00
lobby := lobbies.GetLobbyRegistry().GetLobbyByPassphrase(p)
2023-07-11 16:21:54 +00:00
if lobby == nil || lobby.IsFull() {
2023-06-29 23:50:04 +00:00
return nil
}
return lobby
}
func (u *Usher) AddPlayerToLobbyAndStartGameIfFull(player *chess.Player, lobby *lobbies.Lobby) {
lobby.AddPlayerAndStartGameIfFull(player)
}