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.

68 lines
1.2 KiB

1 year ago
package main
import (
"fmt"
"log"
"os"
"daydev.org/shipsgs/internal/config"
"daydev.org/shipsgs/internal/gameServer"
1 year ago
"daydev.org/shipsgs/internal/server"
"daydev.org/shipsgs/internal/utils"
"github.com/xlab/closer"
)
var Logger *utils.Logger
var ch_sighup *chan bool
//GameServer Public Global Instance
var GS *gameServer.GameServer
1 year ago
func main() {
logFile, err := os.OpenFile("runlog.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Println(err)
} else {
log.SetOutput(logFile)
}
defer logFile.Close()
closer.Bind(cleanup)
//Can be optimised to NEW instead of MAKE
1 year ago
sighup := make(chan bool)
ch_sighup = &sighup
//If debug - fill Stdout too - LOG to use?
//Logger = utils.New(os.Stdout, utils.LevelInfo)
config.ReadConfig()
GS = new(gameServer.GameServer)
GS.Init(Logger, &config.Config)
go GS.Update()
1 year ago
log.Println("Starting Healthy")
//closer.Hold()
server.SetupAndRun(":8080", ch_sighup)
GS.WG.Wait()
1 year ago
}
func cleanup() {
fmt.Println("Shutting down ")
//Investigate why no messages on correct closing
GS.Shutdown <- true
// Main function has to be closed the last
*ch_sighup <- true
1 year ago
Logger.PrintInfo("main", map[string]string{
"Info": "Closing Application Normally",
})
}