|
|
|
@ -1,6 +1,9 @@ |
|
|
|
|
package gameServer |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"log" |
|
|
|
|
|
|
|
|
|
"daydev.org/shipsgs/internal/config" |
|
|
|
|
"daydev.org/shipsgs/internal/player" |
|
|
|
|
"daydev.org/shipsgs/internal/utils" |
|
|
|
@ -16,13 +19,14 @@ type GameServer struct { |
|
|
|
|
maxPlayers int |
|
|
|
|
currentPlayers int |
|
|
|
|
|
|
|
|
|
// Channel to register players and their connection
|
|
|
|
|
join chan *player.Player |
|
|
|
|
|
|
|
|
|
// Storing connected Players
|
|
|
|
|
playerConns map[*player.Player]bool |
|
|
|
|
|
|
|
|
|
// Channel to un register players
|
|
|
|
|
// 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) { |
|
|
|
@ -38,11 +42,21 @@ func (m *GameServer) Init(logger *utils.Logger, config *config.S_Config) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *GameServer) Update() { |
|
|
|
|
//p := <-m.join
|
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If room doesnt exist, spawn it, name it
|
|
|
|
|
//Add a player to a room
|
|
|
|
|
//
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *GameServer) Scheduled1S() { |
|
|
|
@ -52,3 +66,16 @@ 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 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|