2023-05-31 21:55:40 +00:00
|
|
|
package usher
|
|
|
|
|
|
|
|
import (
|
2023-06-25 14:11:29 +00:00
|
|
|
"mchess_server/chess"
|
|
|
|
lobbies "mchess_server/lobby_registry"
|
2023-06-29 20:20:41 +00:00
|
|
|
"mchess_server/utils"
|
2023-05-31 21:55:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Usher struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
var instance *Usher
|
|
|
|
|
2023-06-29 20:20:41 +00:00
|
|
|
func newUsher() *Usher {
|
2023-05-31 21:55:40 +00:00
|
|
|
return &Usher{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetUsher() *Usher {
|
|
|
|
if instance == nil {
|
2023-06-29 20:20:41 +00:00
|
|
|
instance = newUsher()
|
2023-05-31 21:55:40 +00:00
|
|
|
}
|
|
|
|
return instance
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *Usher) WelcomeNewPlayer(player *chess.Player) *lobbies.Lobby {
|
|
|
|
lobby := lobbies.GetLobbyRegistry().GetLobbyForPlayer()
|
|
|
|
return lobby
|
|
|
|
}
|
|
|
|
|
2023-06-28 17:51:36 +00:00
|
|
|
func (u*Usher) FindNewPrivateLobby(player *chess.Player) *lobbies.Lobby {
|
|
|
|
lobby := lobbies.NewEmptyLobbyWithPassphrase()
|
|
|
|
return lobby
|
|
|
|
}
|
|
|
|
|
2023-06-29 20:20:41 +00:00
|
|
|
func (u *Usher) FindExistingPrivateLobby(p utils.Passphrase) *lobbies.Lobby {
|
|
|
|
return lobbies.GetLobbyRegistry().GetLobbyByPassphrase(p)
|
|
|
|
}
|
|
|
|
|
2023-06-02 19:14:02 +00:00
|
|
|
func (u *Usher) AddPlayerToLobbyAndStartGameIfFull(player *chess.Player, lobby *lobbies.Lobby) {
|
|
|
|
lobby.AddPlayerAndStartGameIfFull(player)
|
2023-05-31 21:55:40 +00:00
|
|
|
}
|