-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclientactions.go
194 lines (154 loc) · 4.72 KB
/
clientactions.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
)
func serverStartAction(w http.ResponseWriter, params map[string]string) {
if exeCmd != nil && exeCmd.ProcessState == nil {
log.Println("Preventing double start")
return
}
gameSrvCanStartChan <- true
message := "GETTING UP (MANUALLY)"
gameSrvStatusChan <- message
fmt.Fprint(w, "success")
}
func serverStopAction(w http.ResponseWriter, params map[string]string) {
if exeCmd != nil && exeCmd.ProcessState != nil {
log.Println("Preventing double kill")
return
}
gameSrvCanStart = false
message := "GETTING DOWN (MANUALLY)"
gameSrvStatusChan <- message
exeCmd.Process.Kill()
message = "DOWN (MANUALLY)"
gameSrvStatusChan <- message
fmt.Fprint(w, "success")
}
func serverRestartAction(w http.ResponseWriter, params map[string]string) {
if exeCmd != nil && exeCmd.ProcessState != nil {
log.Println("Preventing double kill")
return
}
gameSrvCanStart = true
exeCmd.Process.Kill()
message := "RESTARTING (MANUALLY)"
gameSrvStatusChan <- message
fmt.Fprint(w, "success")
}
func getActiveAccountsAction(w http.ResponseWriter, params map[string]string) {
log.Println("Getting active accounts...")
fillDbData()
activeAccsSlice := getAccounts(true)
activeAccs := make([]*AccountResponse, len(activeAccsSlice))
i := 0
for _, activeAcc := range activeAccsSlice {
j := 0
bA := new(AccountResponse)
bA.SteamID = fmt.Sprintf("%v", activeAcc.SteamID)
bA.Characters = make([]*CharacterLinkInfo, len(activeAcc.Characters))
for _, charItem := range activeAcc.Characters {
charLinkInfo := new(CharacterLinkInfo)
charLinkInfo.ID = strconv.Itoa(charItem.ID)
charLinkInfo.FullName = charItem.Name + " " + charItem.LastName
bA.Characters[j] = charLinkInfo
j++
}
activeAccs[i] = bA
i++
}
stringified, err := json.Marshal(activeAccs)
if err != nil {
log.Panic("Stringification failed")
}
fmt.Fprint(w, string(stringified))
}
func getBannedAccountsAction(w http.ResponseWriter, params map[string]string) {
log.Println("Getting banned accounts...")
fillDbData()
bannedAccsSlice := getAccounts(false)
bannedAccs := make([]*AccountResponse, len(bannedAccsSlice))
i := 0
for _, bannedAcc := range bannedAccsSlice {
j := 0
bA := new(AccountResponse)
bA.SteamID = fmt.Sprintf("%v", bannedAcc.SteamID)
bA.Characters = make([]*CharacterLinkInfo, len(bannedAcc.Characters))
for _, charItem := range bannedAcc.Characters {
charLinkInfo := new(CharacterLinkInfo)
charLinkInfo.ID = strconv.Itoa(charItem.ID)
charLinkInfo.FullName = charItem.Name + " " + charItem.LastName
bA.Characters[j] = charLinkInfo
j++
}
bannedAccs[i] = bA
i++
}
stringified, err := json.Marshal(bannedAccs)
if err != nil {
log.Panic("Stringification failed")
}
fmt.Fprint(w, string(stringified))
}
func getCharacterSkillsAction(w http.ResponseWriter, params map[string]string) {
charId, err := strconv.Atoi(params["char_id"])
if err != nil {
fmt.Fprint(w, "{\"error\": \"char_id has wrong symbols\"}")
}
charSkills := getCharacterSkills(charId)
stringified, err := json.Marshal(charSkills)
if err != nil {
fmt.Fprint(w, "{\"error\": \"Stringification failed\"}")
log.Println(err)
}
fmt.Fprint(w, string(stringified))
}
func getCharacterDeathLogAction(w http.ResponseWriter, params map[string]string) {
fillDbData()
charId, err := strconv.Atoi(params["char_id"])
if err != nil {
fmt.Fprint(w, "{\"error\": \"char_id has wrong symbols\"}")
}
charLog := getCharacterDeathLog(charId)
stringified, err := json.Marshal(charLog)
if err != nil {
fmt.Fprint(w, "{\"error\": \"Stringification failed\"}")
log.Println(err)
}
fmt.Fprint(w, string(stringified))
}
func getCharacterOnlineHistoryAction(w http.ResponseWriter, params map[string]string) {
fillDbData()
charId, err := strconv.Atoi(params["char_id"])
if err != nil {
fmt.Fprint(w, "{\"error\": \"char_id has wrong symbols\"}")
}
onlineHistory := new(CharacterOnlineHistory)
onlineHistory.History = getCharacterOnlineHistory(charId)
onlineHistory.TotalOnlineTime = getTotalCharacterOnlineTime(charId)
stringified, err := json.Marshal(onlineHistory)
if err != nil {
fmt.Fprint(w, "{\"error\": \"Stringification failed\"}")
log.Println(err)
}
fmt.Fprint(w, string(stringified))
}
func getOnlineCharactersListAction(w http.ResponseWriter) {
if config["control-panel"]["online-statistics"] == "off" {
log.Println("online-statistics is unavailable")
fmt.Fprint(w, "[]")
return
}
onlineCharsList := getOnlineCharactersList()
log.Println("Online characters list:", onlineCharsList)
stringified, err := json.Marshal(onlineCharsList)
if err != nil {
fmt.Fprint(w, "{\"error\": \"Stringification failed\"}")
log.Println(err)
}
fmt.Fprint(w, string(stringified))
}