package gameServer import ( "fmt" "log" "sync" "daydev.org/shipsgs/internal/config" "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]bool // Notify Game Server a New Player Connection chan *Player //Quit the loops correctly and shut down the Game Server Shutdown chan bool //1 Second Update planning OneSecond 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.OneSecond = make(chan bool) m.currentLobbies = 0 m.currentPlayers = 0 m.Connection = make(chan *Player) m.playerConns = make(map[*Player]bool) m.WG.Add(2) } func (m *GameServer) Update() { for { select { case pl := <-m.Connection: m.playerConns[pl] = true go pl.Receiver() case <-m.Shutdown: m.ShutdownServer() m.WG.Done() case <-m.OneSecond: fmt.Println("OneSecond yikes") fmt.Println(m.playerConns) default: // default actions } } } 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 } }