-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
146 lines (130 loc) · 3.44 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"database/sql"
"io/ioutil"
"log"
"os"
"os/exec"
"sync"
"time"
)
type Account struct {
SteamID uint64
IsActive bool
Characters map[string]*Character
}
type Character struct {
ID int
Name string
LastName string
CreateTimestamp time.Time
DeleteTimestamp sql.NullInt64
IsActive bool
SteamID uint64
}
type CharacterLinkInfo struct {
ID string
FullName string
}
type AccountResponse struct {
SteamID string
Characters []*CharacterLinkInfo
}
type OnlineCharacterInfo struct {
ID string
FullName string
OnlineTime string
}
type CharacterOnlineHistory struct {
TotalOnlineTime float32
History []string
}
var (
adminPassword string
lastStartTime time.Time
lastStopTime time.Time
serverToken string
exePath string
wineExePath string
worldCfgPath string
worldCfgContents string
localCfgPath string
localCfgContents string
exeFileName string
exeCmd *exec.Cmd
doneChan chan error
gameSrvStatus string
currentSrvVersion string
availableSrvVersion string
gameSrvStatusChan chan string
currentSrvVersionChan chan string
availableSrvVersionChan chan string
gameSrvCanStart bool
gameSrvCanStartChan chan bool
statusPolls map[int]chan string
responseBaseStr string
config map[string]map[string]string
lifdsDirectory string
topicVersion int
indexHtml string
pathSeparator string
dbConn *sql.DB
dbExists bool
accounts map[uint64]*Account
characters map[int]*Character
charKeysSorted []int
accKeysSorted []uint64
sqls map[string]string
fillCharactersMutex *sync.Mutex
fillAccountsMutex *sync.Mutex
)
func init() {
fillCharactersMutex = &sync.Mutex{}
fillAccountsMutex = &sync.Mutex{}
dbExists = false
pathSeparator = string(os.PathSeparator)
sqls = loadSqlQueries()
config = loadConfiguration()
indexHtmlFile, err := ioutil.ReadFile("html/index.html")
indexHtml = string(indexHtmlFile)
if err != nil {
log.Printf("Can't open index.html file")
}
adminPassword = getAdminPassword()
topicVersion = 1
if config["control-panel"]["server-up-at-start"] == "on" {
gameSrvCanStart = true
} else {
gameSrvCanStart = false
}
gameSrvCanStartChan = make(chan bool)
serverToken = "asdf"
doneChan = make(chan error)
gameSrvStatusChan = make(chan string)
currentSrvVersionChan = make(chan string)
availableSrvVersionChan = make(chan string)
availableSrvVersionChan = make(chan string)
accounts = make(map[uint64]*Account)
characters = make(map[int]*Character)
currentSrvVersion = "1"
availableSrvVersion = "1"
statusPolls = make(map[int]chan string)
responseBaseStr = "{\"debug\": %t, \"status\": \"%s\", \"current_version\": \"%s\", \"available_version\": \"%s\", \"topic_version\": %d, \"online_statistics_enabled\": %t}"
log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds)
initDbConnection()
fillDbData()
}
func main() {
go runGameServerLoop()
go runControlServer()
go statusPollsReleaseWorker()
go onlineStatisticsWorker()
for {
select {
case <-doneChan:
if gameSrvStatus == "UP" {
gameSrvStatusChan <- "DOWN (FAULT)"
}
}
}
}