This commit is contained in:
shoopea 2020-06-21 16:10:45 +02:00
parent 8ee33e8d75
commit 916bab8943

28
main.go
View File

@ -7,9 +7,16 @@ import (
"regexp" "regexp"
) )
type Client struct {
ClientID uint32
Name string
Address string
CompanyID uint8
}
func main() { func main() {
var ( var (
clients int = -1 clients map[uint32]Client
paused bool = true paused bool = true
forcePaused bool = true forcePaused bool = true
) )
@ -121,13 +128,20 @@ func main() {
} }
sp.Read(b[:p.PLength]) sp.Read(b[:p.PLength])
logInfoDebug("AdminPacketServerClientJoin :\n- ClientID: %d", sp.ClientID) logInfoDebug("AdminPacketServerClientJoin :\n- ClientID: %d", sp.ClientID)
clients++
case AdminPacketServerClientInfo: case AdminPacketServerClientInfo:
sp := PacketServerClientInfo{ sp := PacketServerClientInfo{
Packet: p, Packet: p,
} }
sp.Read(b[:p.PLength]) sp.Read(b[:p.PLength])
logInfoDebug("AdminPacketServerClientInfo :\n- ClientID: %d\n- Address: %s\n- Name: %s\n- Lang: %d\n- Date: %d\n- CompanyID: %d", sp.ClientID, sp.Address, sp.Name, sp.Lang, sp.Date, sp.CompanyID) logInfoDebug("AdminPacketServerClientInfo :\n- ClientID: %d\n- Address: %s\n- Name: %s\n- Lang: %d\n- Date: %d\n- CompanyID: %d", sp.ClientID, sp.Address, sp.Name, sp.Lang, sp.Date, sp.CompanyID)
clt := Client{
ClientID: sp.ClientID,
Name: sp.Name,
Address: sp.Address,
CompanyID: sp.CompanyID,
}
clients[sp.ClientID] = clt
logInfoDebug("Clients : %v", clients)
case AdminPacketServerClientError: case AdminPacketServerClientError:
sp := PacketServerClientError{ sp := PacketServerClientError{
Packet: p, Packet: p,
@ -140,9 +154,7 @@ func main() {
} }
sp.Read(b[:p.PLength]) sp.Read(b[:p.PLength])
logInfoDebug("AdminPacketServerClientQuit :\n- ClientID: %d", sp.ClientID) logInfoDebug("AdminPacketServerClientQuit :\n- ClientID: %d", sp.ClientID)
if clients > 0 { delete(clients, sp.ClientID)
clients--
}
case AdminPacketServerChat: case AdminPacketServerChat:
sp := PacketServerChat{ sp := PacketServerChat{
Packet: p, Packet: p,
@ -191,7 +203,7 @@ func main() {
b = c b = c
read -= int(p.PLength) read -= int(p.PLength)
if clients < 0 { if len(clients) == 0 {
px := PacketAdminRCon{ px := PacketAdminRCon{
Packet: Packet{PType: AdminPacketAdminRCon}, Packet: Packet{PType: AdminPacketAdminRCon},
Command: "clients", Command: "clients",
@ -208,7 +220,7 @@ func main() {
} }
_, err = conn.Write(px.Bytes()) _, err = conn.Write(px.Bytes())
} }
if paused && !forcePaused && clients > 0 { if paused && !forcePaused && len(clients) > 1 { // server is client #1
paused = false paused = false
px := PacketAdminRCon{ px := PacketAdminRCon{
Packet: Packet{PType: AdminPacketAdminRCon}, Packet: Packet{PType: AdminPacketAdminRCon},
@ -216,7 +228,7 @@ func main() {
} }
_, err = conn.Write(px.Bytes()) _, err = conn.Write(px.Bytes())
} }
if !paused && clients == 0 { if !paused && len(clients) == 1 { // server is client #1
paused = true paused = true
px := PacketAdminRCon{ px := PacketAdminRCon{
Packet: Packet{PType: AdminPacketAdminRCon}, Packet: Packet{PType: AdminPacketAdminRCon},