|
|
|
@ -3,6 +3,7 @@ package gameServer |
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"log" |
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
"daydev.org/shipsgs/internal/config" |
|
|
|
|
"daydev.org/shipsgs/internal/player" |
|
|
|
@ -27,6 +28,9 @@ type GameServer struct { |
|
|
|
|
|
|
|
|
|
//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) { |
|
|
|
@ -36,27 +40,23 @@ func (m *GameServer) Init(logger *utils.Logger, config *config.S_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 - go through the messages
|
|
|
|
|
select { |
|
|
|
|
case c := <-m.connection: |
|
|
|
|
fmt.Println("a new connection", c) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//default shutdown
|
|
|
|
|
if m.Shutdown == nil { |
|
|
|
|
case <-m.Shutdown: |
|
|
|
|
m.ShutdownServer() |
|
|
|
|
break |
|
|
|
|
m.WG.Done() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *GameServer) Scheduled1S() { |
|
|
|
|