mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
feat(Core/Network): Per-user togglable packet logging (#23254)
Co-authored-by: Ryan Turner <16946913+TheSCREWEDSoftware@users.noreply.github.com>
This commit is contained in:
@@ -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");
|
||||
@@ -1510,3 +1510,9 @@ void WorldSession::InitializeSessionCallback(CharacterDatabaseQueryHolder const&
|
||||
SendClientCacheVersion(clientCacheVersion);
|
||||
SendTutorialsData();
|
||||
}
|
||||
|
||||
void WorldSession::SetPacketLogging(bool state)
|
||||
{
|
||||
if (m_Socket)
|
||||
m_Socket->SetPacketLogging(state);
|
||||
}
|
||||
|
||||
@@ -1138,6 +1138,8 @@ public: // opcodes handlers
|
||||
void InitializeSession();
|
||||
void InitializeSessionCallback(CharacterDatabaseQueryHolder const& realmHolder, uint32 clientCacheVersion);
|
||||
|
||||
void SetPacketLogging(bool state);
|
||||
|
||||
private:
|
||||
void ProcessQueryCallbacks();
|
||||
|
||||
|
||||
@@ -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<std::mutex> 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()));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<bool> 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()
|
||||
|
||||
Reference in New Issue
Block a user