You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.3 KiB
81 lines
1.3 KiB
package gameServer |
|
|
|
import ( |
|
"fmt" |
|
"log" |
|
|
|
"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 |
|
} |
|
|
|
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.currentLobbies = 0 |
|
m.currentPlayers = 0 |
|
|
|
} |
|
|
|
func (m *GameServer) Update() { |
|
for { |
|
// select - go through the messages |
|
select { |
|
case c := <-m.connection: |
|
fmt.Println("a new connection", c) |
|
} |
|
|
|
//default shutdown |
|
if m.Shutdown == nil { |
|
m.ShutdownServer() |
|
break |
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
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 |
|
} |
|
|
|
}
|
|
|