-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
60 lines (51 loc) · 1.24 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
package main
import (
"fmt"
"math/rand"
"os/exec"
"time"
"github.com/blobs-io/blobsgame/database"
"github.com/blobs-io/blobsgame/http/gateway"
"github.com/blobs-io/blobsgame/http/web"
"github.com/blobs-io/blobsgame/models/gamemap"
"github.com/blobs-io/blobsgame/models/room"
"github.com/blobs-io/blobsgame/utils/config"
)
func main() {
rand.Seed(time.Now().UnixNano())
// Log commit hash
res, err := exec.Command("git", "rev-parse", "HEAD").Output()
if err != nil {
panic(err)
}
fmt.Printf("Running hash %s", res)
// Parse config files
err = config.ParseMainConfig("configs/config.json")
if err != nil {
panic(err)
}
err = config.ParseDatabaseConfig("configs/database.json")
if err != nil {
panic(err)
}
err = gamemap.LoadMaps()
if err != nil {
panic(err)
} else if len(gamemap.GameMaps) < 1 {
panic("no maps found")
}
// Init database connection
err = database.Init(config.DatabaseConfig)
if err != nil {
panic(err)
}
// Create rooms
room.Rooms = make(map[string]*room.Room)
for i := 0; i < 3; i++ {
go gateway.WatchRoom(room.New(room.FFAMode))
go gateway.WatchRoom(room.New(room.EliminationMode))
}
fmt.Printf("Created %d rooms\n", len(room.Rooms))
// Init web server
web.Init(config.MainConfig.Port)
}