diff --git a/data/sql/updates/pending_db_world/rev_1760600911436478900.sql b/data/sql/updates/pending_db_world/rev_1760600911436478900.sql new file mode 100644 index 000000000..dc0053199 --- /dev/null +++ b/data/sql/updates/pending_db_world/rev_1760600911436478900.sql @@ -0,0 +1,4 @@ +-- +DELETE FROM `command` WHERE `name` = "packetlog"; +INSERT INTO `command` (`name`, `security`, `help`) VALUES +("packetlog", 2, "Syntax: .packetlog [on/off]\n Toggles to allow the character using the command to start to log their packets into the server, PacketLogFile needs to be set with a valid filename"); diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 412d1a9f6..5ac8895c6 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -1510,3 +1510,9 @@ void WorldSession::InitializeSessionCallback(CharacterDatabaseQueryHolder const& SendClientCacheVersion(clientCacheVersion); SendTutorialsData(); } + +void WorldSession::SetPacketLogging(bool state) +{ + if (m_Socket) + m_Socket->SetPacketLogging(state); +} diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index c4f9ce9fe..feacafb69 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -1138,6 +1138,8 @@ public: // opcodes handlers void InitializeSession(); void InitializeSessionCallback(CharacterDatabaseQueryHolder const& realmHolder, uint32 clientCacheVersion); + void SetPacketLogging(bool state); + private: void ProcessQueryCallbacks(); diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 51705d18e..0641744e8 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -117,7 +117,7 @@ void EncryptableAndCompressiblePacket::CompressIfNeeded() } WorldSocket::WorldSocket(tcp::socket&& socket) - : Socket(std::move(socket)), _OverSpeedPings(0), _worldSession(nullptr), _authed(false), _sendBufferSize(4096) + : Socket(std::move(socket)), _OverSpeedPings(0), _worldSession(nullptr), _authed(false), _sendBufferSize(4096), _loggingPackets(false) { Acore::Crypto::GetRandomBytes(_authSeed); _headerBuffer.Resize(sizeof(ClientPktHeader)); @@ -406,7 +406,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler() WorldPacket packet(opcode, std::move(_packetBuffer)); WorldPacket* packetToQueue; - if (sPacketLog->CanLogPacket()) + if (sPacketLog->CanLogPacket() && IsLoggingPackets()) sPacketLog->LogPacket(packet, CLIENT_TO_SERVER, GetRemoteIpAddress(), GetRemotePort()); std::unique_lock sessionGuard(_worldSessionLock, std::defer_lock); @@ -520,7 +520,7 @@ void WorldSocket::SendPacket(WorldPacket const& packet) if (!IsOpen()) return; - if (sPacketLog->CanLogPacket()) + if (sPacketLog->CanLogPacket() && IsLoggingPackets()) sPacketLog->LogPacket(packet, SERVER_TO_CLIENT, GetRemoteIpAddress(), GetRemotePort()); _bufferQueue.Enqueue(new EncryptableAndCompressiblePacket(packet, _authCrypt.IsInitialized())); diff --git a/src/server/game/Server/WorldSocket.h b/src/server/game/Server/WorldSocket.h index aa65dfa09..56313fd40 100644 --- a/src/server/game/Server/WorldSocket.h +++ b/src/server/game/Server/WorldSocket.h @@ -85,6 +85,9 @@ public: void SetSendBufferSize(std::size_t sendBufferSize) { _sendBufferSize = sendBufferSize; } + bool IsLoggingPackets() const { return _loggingPackets; } + void SetPacketLogging(bool state) { _loggingPackets = state; } + protected: void OnClose() override; void ReadHandler() override; @@ -133,6 +136,8 @@ private: QueryCallbackProcessor _queryProcessor; std::string _ipCountry; + + bool _loggingPackets; }; #endif diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index fe1410492..4fb628606 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -194,7 +194,8 @@ public: { "mailbox", HandleMailBoxCommand, SEC_MODERATOR, Console::No }, { "string", HandleStringCommand, SEC_GAMEMASTER, Console::No }, { "opendoor", HandleOpenDoorCommand, SEC_GAMEMASTER, Console::No }, - { "bm", HandleBMCommand, SEC_GAMEMASTER, Console::No } + { "bm", HandleBMCommand, SEC_GAMEMASTER, Console::No }, + { "packetlog", HandlePacketLog, SEC_GAMEMASTER, Console::No } }; return commandTable; @@ -3108,6 +3109,33 @@ public: return false; } + static bool HandlePacketLog(ChatHandler* handler, Optional enableArg) + { + WorldSession* session = handler->GetSession(); + + if (!session) + return false; + + if (enableArg) + { + if (*enableArg) + { + session->SetPacketLogging(true); + handler->SendNotification(LANG_ON); + return true; + } + else + { + session->SetPacketLogging(false); + handler->SendNotification(LANG_OFF); + return true; + } + } + + handler->SendErrorMessage(LANG_USE_BOL); + return false; + } + }; void AddSC_misc_commandscript()