|
|
@ -4,6 +4,7 @@ import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"daydev.org/shipsgs/internal/config" |
|
|
|
"daydev.org/shipsgs/internal/config" |
|
|
|
"daydev.org/shipsgs/internal/gameServer" |
|
|
|
"daydev.org/shipsgs/internal/gameServer" |
|
|
@ -15,6 +16,9 @@ import ( |
|
|
|
var Logger *utils.Logger |
|
|
|
var Logger *utils.Logger |
|
|
|
var ch_sighup *chan bool |
|
|
|
var ch_sighup *chan bool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//channel to shutdown oneSecUpdater
|
|
|
|
|
|
|
|
var ch_oneSecUpdaterShutdown chan bool |
|
|
|
|
|
|
|
|
|
|
|
//GameServer Public Global Instance
|
|
|
|
//GameServer Public Global Instance
|
|
|
|
var GS *gameServer.GameServer |
|
|
|
var GS *gameServer.GameServer |
|
|
|
|
|
|
|
|
|
|
@ -33,6 +37,8 @@ func main() { |
|
|
|
sighup := make(chan bool) |
|
|
|
sighup := make(chan bool) |
|
|
|
ch_sighup = &sighup |
|
|
|
ch_sighup = &sighup |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ch_oneSecUpdaterShutdown = make(chan bool) |
|
|
|
|
|
|
|
|
|
|
|
//If debug - fill Stdout too - LOG to use?
|
|
|
|
//If debug - fill Stdout too - LOG to use?
|
|
|
|
//Logger = utils.New(os.Stdout, utils.LevelInfo)
|
|
|
|
//Logger = utils.New(os.Stdout, utils.LevelInfo)
|
|
|
|
|
|
|
|
|
|
|
@ -42,10 +48,15 @@ func main() { |
|
|
|
GS.Init(Logger, &config.Config) |
|
|
|
GS.Init(Logger, &config.Config) |
|
|
|
go GS.Update() |
|
|
|
go GS.Update() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Starting oneSecUpdater after GameServer is ready, because oneSecUpdater
|
|
|
|
|
|
|
|
// is depending on GameServer.Shutdown channel which
|
|
|
|
|
|
|
|
// is IF uninitialized we will get "invalid memory address or nil pointer dereference"
|
|
|
|
|
|
|
|
go oneSecUpdater() |
|
|
|
|
|
|
|
|
|
|
|
log.Println("Starting Healthy") |
|
|
|
log.Println("Starting Healthy") |
|
|
|
|
|
|
|
|
|
|
|
//closer.Hold()
|
|
|
|
//closer.Hold()
|
|
|
|
server.SetupAndRun(":8080", ch_sighup) |
|
|
|
server.SetupAndRun(":8080", ch_sighup, GS) |
|
|
|
|
|
|
|
|
|
|
|
GS.WG.Wait() |
|
|
|
GS.WG.Wait() |
|
|
|
|
|
|
|
|
|
|
@ -54,6 +65,9 @@ func main() { |
|
|
|
func cleanup() { |
|
|
|
func cleanup() { |
|
|
|
fmt.Println("Shutting down ") |
|
|
|
fmt.Println("Shutting down ") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Shutting down oneSecUpdater
|
|
|
|
|
|
|
|
ch_oneSecUpdaterShutdown <- true |
|
|
|
|
|
|
|
|
|
|
|
//Investigate why no messages on correct closing
|
|
|
|
//Investigate why no messages on correct closing
|
|
|
|
GS.Shutdown <- true |
|
|
|
GS.Shutdown <- true |
|
|
|
|
|
|
|
|
|
|
@ -65,3 +79,25 @@ func cleanup() { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func oneSecUpdater() { |
|
|
|
|
|
|
|
//The intention here is to awake after 1 second and send an update to GameServer to update everything
|
|
|
|
|
|
|
|
for { |
|
|
|
|
|
|
|
select { |
|
|
|
|
|
|
|
case <-ch_oneSecUpdaterShutdown: |
|
|
|
|
|
|
|
fmt.Println("Shutdown One Sec Updater") |
|
|
|
|
|
|
|
GS.WG.Done() |
|
|
|
|
|
|
|
// Goroutine will wait untill the DEFAULT: will happen before shutdown will take
|
|
|
|
|
|
|
|
// any effect
|
|
|
|
|
|
|
|
case <-time.After(time.Second * 1): |
|
|
|
|
|
|
|
fmt.Println("1 Sec Timer") |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
//*** maybe try this 10 secs in a CASE segment ?
|
|
|
|
|
|
|
|
// This blocks whole goroutine
|
|
|
|
|
|
|
|
<-time.After(time.Second * 2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GS.OneSecond <- true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|