From 7e0cefb4e89ce7aa5f50a5e88bceb6dae58d1b1e Mon Sep 17 00:00:00 2001 From: shoopea Date: Mon, 15 Jun 2020 15:04:55 +0200 Subject: [PATCH] test --- main.go | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 569327a..ad31cd7 100644 --- a/main.go +++ b/main.go @@ -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()) + } } }