package gameServer import ( "fmt" "log" "sync" "daydev.org/shipsgs/internal/config" "daydev.org/shipsgs/internal/player" "daydev.org/shipsgs/internal/utils" ) type GameServer struct { Logger *utils.Logger Config *config.S_Config maxLobbies int currentLobbies int maxPlayers int currentPlayers int // Storing connected Players playerConns map[*player.Player]bool // Notify Game Server a New Player connection chan *player.Player //Quit the loops correctly and shut down the Game Server Shutdown chan bool //sync threads WG sync.WaitGroup } func (m *GameServer) Init(logger *utils.Logger, config *config.S_Config) { m.Logger = logger m.Config = config m.maxLobbies = m.Config.MaxLobbies m.maxPlayers = m.Config.MaxPlayers m.Shutdown = make(chan bool) m.currentLobbies = 0 m.currentPlayers = 0 m.WG.Add(1) } func (m *GameServer) Update() { for { select { case <-m.Shutdown: m.ShutdownServer() m.WG.Done() } } } func (m *GameServer) Scheduled1S() { } func (m *GameServer) Scheduled10S() { } func (m *GameServer) ShutdownServer() { fmt.Println("shutting down the GameServer") } func (m *GameServer) CreateLobby() { if m.currentLobbies >= m.maxLobbies { log.Fatal("Server cannot spawn more lobbies than it already has") return } }