This commit is contained in:
shoopea 2020-06-21 21:14:36 +02:00
parent 9796ec9a47
commit b441028e15

26
main.go
View File

@ -20,10 +20,11 @@ type Client struct {
}
var (
bot *tb.Bot
clients map[uint32]*Client
paused bool = true
forcePaused bool = true
bot *tb.Bot
clients map[uint32]*Client
paused bool = true
forcePaused bool = true
forcePausedBy string
githash string
buildstamp string
@ -203,11 +204,11 @@ func main() {
if sp.Message == "!unpause" {
logInfoDebug("AdminPacketServerChat : Unpausing")
forcePaused = false
sendChat(-436055948, fmt.Sprintf("Game unpaused by %s", clients[sp.ClientID].Name))
forcePausedBy = clients[sp.ClientID].Name
} else if sp.Message == "!pause" {
logInfoDebug("AdminPacketServerChat : Pausing")
forcePaused = true
sendChat(-436055948, fmt.Sprintf("Game paused by %s", clients[sp.ClientID].Name))
forcePausedBy = clients[sp.ClientID].Name
} else {
logInfoDebug("AdminPacketServerChat :\n- ActionID: %d\n- DestinationID: %d\n- ClientID: %d\n- Message: %s\n- Amount: %d", sp.ActionID, sp.DestinationID, sp.ClientID, sp.Message, sp.Amount)
}
@ -282,6 +283,11 @@ func main() {
Command: "pause",
}
_, err = conn.Write(px.Bytes())
logInfoDebug("Force pausing")
if pausedBy != "" {
sendChat(-436055948, fmt.Sprintf("Game paused by %s", pausedBy))
pausedBy = ""
}
}
if paused && !forcePaused && len(clients) > 1 { // server is client #1
paused = false
@ -290,7 +296,11 @@ func main() {
Command: "unpause",
}
_, err = conn.Write(px.Bytes())
sendChat(-436055948, "Game unpaused.")
logInfoDebug("Force unpausing")
if pausedBy != "" {
sendChat(-436055948, fmt.Sprintf("Game unpaused by %s", pausedBy))
pausedBy = ""
}
}
if !paused && len(clients) == 1 { // server is client #1
paused = true
@ -300,6 +310,8 @@ func main() {
}
_, err = conn.Write(px.Bytes())
logInfoDebug("Pausing")
sendChat(-436055948, "No players. Game paused.")
}
}