This commit is contained in:
shoopea 2020-06-15 15:04:55 +02:00
parent 024fc73fb0
commit 7e0cefb4e8

45
main.go
View File

@ -7,6 +7,11 @@ import (
)
func main() {
var (
clients int = 0
paused bool = true
)
conn, err := net.Dial("tcp", "poop.siteop.biz:3977")
failError(err, "net.Dial")
logInfoDebug("Connected to poop.siteop.biz:3977")
@ -63,13 +68,13 @@ func main() {
switch p.PType {
case AdminPacketServerProtocol:
sp := PacketAdminServerProtocol{
sp := PacketServerProtocol{
Packet: p,
}
sp.Read(b[:p.PLength])
logInfoDebug("AdminPacketServerProtocol :\n- ProtocolVersion: %v\n- FurtherData: %v\n- UpdatePacketType: %v\n- FrequenciesAllowed: %b", sp.ProtocolVersion, sp.FurtherData, sp.UpdatePacketType, sp.FrequenciesAllowed)
case AdminPacketServerWelcome:
sp := PacketAdminServerWelcome{
sp := PacketServerWelcome{
Packet: p,
}
sp.Read(b[:p.PLength])
@ -102,43 +107,48 @@ func main() {
}
_, err = conn.Write(px.Bytes())
case AdminPacketServerDate:
sp := PacketAdminServerDate{
sp := PacketServerDate{
Packet: p,
}
sp.Read(b[:p.PLength])
logInfoDebug("AdminPacketServerDate :\n- Date: %d", sp.Date)
paused = false
case AdminPacketServerClientJoin:
sp := PacketAdminServerClientJoin{
sp := PacketServerClientJoin{
Packet: p,
}
sp.Read(b[:p.PLength])
logInfoDebug("AdminPacketServerClientJoin :\n- ClientID: %d", sp.ClientID)
clients++
case AdminPacketServerClientInfo:
sp := PacketAdminServerClientInfo{
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)
case AdminPacketServerClientError:
sp := PacketAdminServerClientError{
sp := PacketServerClientError{
Packet: p,
}
sp.Read(b[:p.PLength])
logInfoDebug("AdminPacketServerClientError :\n- ClientID: %d\n- ErrorID: %d", sp.ClientID, sp.ErrorID)
case AdminPacketServerClientQuit:
sp := PacketAdminServerClientQuit{
sp := PacketServerClientQuit{
Packet: p,
}
sp.Read(b[:p.PLength])
logInfoDebug("AdminPacketServerClientQuit :\n- ClientID: %d", sp.ClientID)
if clients > 0 {
clients--
}
case AdminPacketServerChat:
sp := PacketAdminServerChat{
sp := PacketServerChat{
Packet: p,
}
sp.Read(b[:p.PLength])
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)
case AdminPacketServerConsole:
sp := PacketAdminServerConsole{
sp := PacketServerConsole{
Packet: p,
}
sp.Read(b[:p.PLength])
@ -151,6 +161,23 @@ func main() {
copy(c, b[p.PLength:])
b = c
read -= int(p.PLength)
if paused && clients > 0 {
paused = false
px = PacketAdminRCon{
Packet: Packet{PType: AdminPacketAdminRCon},
Command: "unpause",
}
_, err = conn.Write(px.Bytes())
}
if !paused && clients == 0 {
paused = true
px = PacketAdminRCon{
Packet: Packet{PType: AdminPacketAdminRCon},
Command: "pause",
}
_, err = conn.Write(px.Bytes())
}
}
}