Core/Logging: Restore dumping packets in binary format
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PacketLog.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "ByteBuffer.h"
|
||||||
|
#include "WorldPacket.h"
|
||||||
|
|
||||||
|
PacketLog::PacketLog() : _file(NULL)
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketLog::~PacketLog()
|
||||||
|
{
|
||||||
|
if (_file)
|
||||||
|
fclose(_file);
|
||||||
|
|
||||||
|
_file = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketLog::Initialize()
|
||||||
|
{
|
||||||
|
std::string logsDir = ConfigMgr::GetStringDefault("LogsDir", "");
|
||||||
|
|
||||||
|
if (!logsDir.empty())
|
||||||
|
if ((logsDir.at(logsDir.length()-1) != '/') && (logsDir.at(logsDir.length()-1) != '\\'))
|
||||||
|
logsDir.push_back('/');
|
||||||
|
|
||||||
|
std::string logname = ConfigMgr::GetStringDefault("PacketLogFile", "");
|
||||||
|
if (!logname.empty())
|
||||||
|
_file = fopen((logsDir + logname).c_str(), "wb");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketLog::LogPacket(WorldPacket const& packet, Direction direction)
|
||||||
|
{
|
||||||
|
ByteBuffer data(4+4+4+1+packet.size());
|
||||||
|
data << int32(packet.GetOpcode());
|
||||||
|
data << int32(packet.size());
|
||||||
|
data << uint32(time(NULL));
|
||||||
|
data << uint8(direction);
|
||||||
|
|
||||||
|
for (uint32 i = 0; i < packet.size(); i++)
|
||||||
|
data << const_cast<WorldPacket&>(packet)[i];
|
||||||
|
|
||||||
|
fwrite(data.contents(), 1, data.size(), _file);
|
||||||
|
fflush(_file);
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TRINITY_PACKETLOG_H
|
||||||
|
#define TRINITY_PACKETLOG_H
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
#include <ace/Singleton.h>
|
||||||
|
|
||||||
|
enum Direction
|
||||||
|
{
|
||||||
|
CLIENT_TO_SERVER,
|
||||||
|
SERVER_TO_CLIENT
|
||||||
|
};
|
||||||
|
|
||||||
|
class WorldPacket;
|
||||||
|
|
||||||
|
class PacketLog
|
||||||
|
{
|
||||||
|
friend class ACE_Singleton<PacketLog, ACE_Thread_Mutex>;
|
||||||
|
|
||||||
|
private:
|
||||||
|
PacketLog();
|
||||||
|
~PacketLog();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void Initialize();
|
||||||
|
bool CanLogPacket() const { return (_file != NULL); }
|
||||||
|
void LogPacket(WorldPacket const& packet, Direction direction);
|
||||||
|
|
||||||
|
private:
|
||||||
|
FILE* _file;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define sPacketLog ACE_Singleton<PacketLog, ACE_Thread_Mutex>::instance()
|
||||||
|
#endif
|
||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "WorldSession.h"
|
#include "WorldSession.h"
|
||||||
#include "WorldSocketMgr.h"
|
#include "WorldSocketMgr.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "PacketLog.h"
|
||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
#include "AccountMgr.h"
|
#include "AccountMgr.h"
|
||||||
|
|
||||||
@@ -159,30 +160,8 @@ int WorldSocket::SendPacket(WorldPacket const& pct)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Dump outgoing packet.
|
// Dump outgoing packet.
|
||||||
if (sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE))
|
if (sPacketLog->CanLogPacket())
|
||||||
{
|
sPacketLog->LogPacket(pct, SERVER_TO_CLIENT);
|
||||||
char buff[250];
|
|
||||||
snprintf(buff, 250, "SERVER:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
|
|
||||||
uint32(get_handle()),
|
|
||||||
uint32(pct.size()),
|
|
||||||
LookupOpcodeName (pct.GetOpcode()),
|
|
||||||
pct.GetOpcode());
|
|
||||||
|
|
||||||
std::string data(buff);
|
|
||||||
uint32 p = 0;
|
|
||||||
while (p < pct.size())
|
|
||||||
{
|
|
||||||
for (uint32 j = 0; j < 16 && p < pct.size(); j++)
|
|
||||||
{
|
|
||||||
snprintf(buff, 250, "%.2X ", const_cast<WorldPacket&>(pct)[p++]);
|
|
||||||
data.append(buff);
|
|
||||||
}
|
|
||||||
data.append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
data.append("\n");
|
|
||||||
sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", data.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a copy of the original packet; this is to avoid issues if a hook modifies it.
|
// Create a copy of the original packet; this is to avoid issues if a hook modifies it.
|
||||||
sScriptMgr->OnPacketSend(this, WorldPacket(pct));
|
sScriptMgr->OnPacketSend(this, WorldPacket(pct));
|
||||||
@@ -691,30 +670,9 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
|
|||||||
if (closing_)
|
if (closing_)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE))
|
// Dump received packet.
|
||||||
{
|
if (sPacketLog->CanLogPacket())
|
||||||
char buff[250];
|
sPacketLog->LogPacket(*new_pct, CLIENT_TO_SERVER);
|
||||||
snprintf(buff, 250, "CLIENT:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
|
|
||||||
uint32(get_handle()),
|
|
||||||
uint32(new_pct->size()),
|
|
||||||
LookupOpcodeName (new_pct->GetOpcode()),
|
|
||||||
new_pct->GetOpcode());
|
|
||||||
|
|
||||||
std::string data(buff);
|
|
||||||
uint32 p = 0;
|
|
||||||
while (p < new_pct->size())
|
|
||||||
{
|
|
||||||
for (uint32 j = 0; j < 16 && p < new_pct->size(); j++)
|
|
||||||
{
|
|
||||||
snprintf(buff, 250, "%.2X ", const_cast<WorldPacket&>(*new_pct)[p++]);
|
|
||||||
data.append(buff);
|
|
||||||
}
|
|
||||||
data.append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
data.append("\n");
|
|
||||||
sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", data.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -403,6 +403,15 @@ PersistentCharacterCleanFlags = 0
|
|||||||
|
|
||||||
PidFile = ""
|
PidFile = ""
|
||||||
|
|
||||||
|
#
|
||||||
|
# PacketLogFile
|
||||||
|
# Description: Binary packet logging file for the world server.
|
||||||
|
# Filename extension must be .bin to be parsable with WowPacketParser.
|
||||||
|
# Example: "World.bin" - (Enabled)
|
||||||
|
# Default: "" - (Disabled)
|
||||||
|
|
||||||
|
PacketLogFile = ""
|
||||||
|
|
||||||
#
|
#
|
||||||
# ChatLogs.Channel
|
# ChatLogs.Channel
|
||||||
# Description: Log custom channel chat.
|
# Description: Log custom channel chat.
|
||||||
|
|||||||
Reference in New Issue
Block a user