46 lines
948 B
Go
46 lines
948 B
Go
package usher
|
|
|
|
import (
|
|
"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
|
|
}
|
|
|
|
func (u *Usher) CreateNewPrivateLobby(player *chess.Player) *lobbies.Lobby {
|
|
lobby := lobbies.GetLobbyRegistry().CreateNewPrivateLobby()
|
|
return lobby
|
|
}
|
|
|
|
func (u *Usher) FindExistingPrivateLobby(p utils.Passphrase) *lobbies.Lobby {
|
|
lobby := lobbies.GetLobbyRegistry().GetLobbyByPassphrase(p)
|
|
if lobby == nil || lobby.IsFull() {
|
|
return nil
|
|
}
|
|
return lobby
|
|
}
|
|
|
|
func (u *Usher) AddPlayerToLobbyAndStartGameIfFull(player *chess.Player, lobby *lobbies.Lobby) {
|
|
lobby.AddPlayerAndStartGameIfFull(player)
|
|
}
|