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