forked from xiaonanln/goworld
/
reload.go
33 lines (26 loc) · 804 Bytes
/
reload.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
package main
import (
"os"
"github.com/xiaonanln/goworld/engine/binutil"
"github.com/xiaonanln/goworld/engine/config"
)
func reload(sid ServerID) {
err := os.Chdir(env.GoWorldRoot)
checkErrorOrQuit(err, "chdir to goworld directory failed")
ss := detectServerStatus()
showServerStatus(ss)
if !ss.IsRunning() {
// server is not running
showMsgAndQuit("no server is running currently")
}
if ss.ServerID != "" && ss.ServerID != sid {
showMsgAndQuit("another server is running: %s", ss.ServerID)
}
if ss.NumGamesRunning == 0 {
showMsgAndQuit("no game is running")
} else if ss.NumGamesRunning != config.GetGamesNum() {
showMsgAndQuit("found %d games, but should have %d", ss.NumGamesRunning, config.GetGamesNum())
}
stopGames(ss, binutil.FreezeSignal)
startGames(sid, true)
}