-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (52 loc) · 1.38 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"comm"
"config"
"flag"
"game"
"io"
"log"
"os"
"path"
"strconv"
"time"
"util"
)
func main() {
genJson := flag.Bool("genjson", false, "Generate protocal json")
// configure options
configPath := flag.String("config", "src/config/default.json", "Path to configuration file")
verbose := flag.Bool("verbose", false, "Whether to log filename and line number out")
debuguser := flag.String("user", "", "Skip login and use this username")
flag.Parse()
if *genJson {
comm.MsgType2Json()
return
}
if *verbose {
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
if *debuguser != "" {
log.Printf("Using username %v for debug", *debuguser)
os.Setenv("RTSUSER", *debuguser)
}
config.Initialize(*configPath)
// Create log directory
if err := os.MkdirAll(config.LogDir, 0755); err != nil {
log.Fatalln("[ERROR] Unable to create log directory")
return
}
log_path := path.Join(config.LogDir, "gamelog_"+strconv.Itoa(int(time.Now().Unix()))+".log")
fileWriter, err := os.OpenFile(log_path, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalln("[ERROR] Unable to create log file")
return
}
log.SetOutput(io.MultiWriter(os.Stdout, fileWriter))
engine, _ := game.NewGameEngine()
engine.LoadTerrain(util.Point{-25, -25}, util.Point{24, 24}, "map_river.json")
engine.Start()
server, _ := comm.NewWsServer()
server.Start(9999)
select {}
}