42 lines
872 B
Go
42 lines
872 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) FindNewPrivateLobby(player *chess.Player) *lobbies.Lobby {
|
|
lobby := lobbies.NewEmptyLobbyWithPassphrase()
|
|
return lobby
|
|
}
|
|
|
|
func (u *Usher) FindExistingPrivateLobby(p utils.Passphrase) *lobbies.Lobby {
|
|
return lobbies.GetLobbyRegistry().GetLobbyByPassphrase(p)
|
|
}
|
|
|
|
func (u *Usher) AddPlayerToLobbyAndStartGameIfFull(player *chess.Player, lobby *lobbies.Lobby) {
|
|
lobby.AddPlayerAndStartGameIfFull(player)
|
|
}
|