-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (45 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"encoding/json"
"os"
"strconv"
"time"
"github.com/code-game-project/go-server/cg"
"github.com/spf13/pflag"
"github.com/code-game-project/tic-tac-toe-simple/tictactoesimple"
)
func main() {
var port int
pflag.IntVarP(&port, "port", "p", 0, "The network port of the game server.")
pflag.Parse()
if port == 0 {
portStr, ok := os.LookupEnv("CG_PORT")
if ok {
port, _ = strconv.Atoi(portStr)
}
}
if port == 0 {
port = 8080
}
server := cg.NewServer("tic-tac-toe-simple", cg.ServerConfig{
DisplayName: "Tic-Tac-Toe Simple",
Version: "0.3",
MaxPlayersPerGame: 2,
Description: "A simple implementation of tic-tac-toe for CodeGame. This game is ideal for familiarizing yourself with CodeGame.",
RepositoryURL: "https://github.com/code-game-project/tic-tac-toe-simple",
Port: port,
CGEFilepath: "events.cge",
DeleteInactiveGameDelay: 5 * time.Minute,
KickInactivePlayerDelay: 15 * time.Minute,
})
server.Run(func(cgGame *cg.Game, config json.RawMessage) {
var gameConfig tictactoesimple.GameConfig
err := json.Unmarshal(config, &gameConfig)
if err == nil {
cgGame.SetConfig(gameConfig)
} else {
cgGame.Log.Error("Failed to unmarshal game config: %s", err)
}
tictactoesimple.NewGame(cgGame, gameConfig).Run()
})
}