Core/Logging: Changed format of packet log file from .bin to .pkt and restored packet logging - PacketLogFile extension must now be .pkt to allow WowPacketParser to use it
This commit is contained in:
1 parent
7f287b6d50
commit
57cf08f86e
4 files changed
+72
-18
No files matched your search
@@ -17,9 +17,36 @@
|
||||
|
||||
#include "PacketLog.h"
|
||||
#include "Config.h"
|
||||
#include "ByteBuffer.h"
|
||||
#include "WorldPacket.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
// Packet logging structures in PKT 3.1 format
|
||||
struct LogHeader
|
||||
{
|
||||
char Signature[3];
|
||||
uint16 FormatVersion;
|
||||
uint8 SnifferId;
|
||||
uint32 Build;
|
||||
char Locale[4];
|
||||
uint8 SessionKey[40];
|
||||
uint32 SniffStartUnixtime;
|
||||
uint32 SniffStartTicks;
|
||||
uint32 OptionalDataSize;
|
||||
};
|
||||
|
||||
struct PacketHeader
|
||||
{
|
||||
char Direction[4];
|
||||
uint32 ConnectionId;
|
||||
uint32 ArrivalTicks;
|
||||
uint32 OptionalDataSize;
|
||||
uint32 Length;
|
||||
uint32 Opcode;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
PacketLog::PacketLog() : _file(NULL)
|
||||
{
|
||||
Initialize();
|
||||
@@ -38,25 +65,42 @@ void PacketLog::Initialize()
|
||||
std::string logsDir = sConfigMgr->GetStringDefault("LogsDir", "");
|
||||
|
||||
if (!logsDir.empty())
|
||||
if ((logsDir.at(logsDir.length()-1) != '/') && (logsDir.at(logsDir.length()-1) != '\\'))
|
||||
if ((logsDir.at(logsDir.length() - 1) != '/') && (logsDir.at(logsDir.length() - 1) != '\\'))
|
||||
logsDir.push_back('/');
|
||||
|
||||
std::string logname = sConfigMgr->GetStringDefault("PacketLogFile", "");
|
||||
if (!logname.empty())
|
||||
{
|
||||
_file = fopen((logsDir + logname).c_str(), "wb");
|
||||
|
||||
LogHeader header;
|
||||
header.Signature[0] = 'P'; header.Signature[1] = 'K'; header.Signature[2] = 'T';
|
||||
header.FormatVersion = 0x0301;
|
||||
header.SnifferId = 'T';
|
||||
header.Build = 12340;
|
||||
header.Locale[0] = 'e'; header.Locale[1] = 'n'; header.Locale[2] = 'U'; header.Locale[3] = 'S';
|
||||
std::memset(header.SessionKey, 0, sizeof(header.SessionKey));
|
||||
header.SniffStartUnixtime = time(NULL);
|
||||
header.SniffStartTicks = getMSTime();
|
||||
header.OptionalDataSize = 0;
|
||||
|
||||
fwrite(&header, sizeof(header), 1, _file);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
PacketHeader header;
|
||||
*reinterpret_cast<uint32*>(header.Direction) = direction == CLIENT_TO_SERVER ? 0x47534d43 : 0x47534d53;
|
||||
header.ConnectionId = 0;
|
||||
header.ArrivalTicks = getMSTime();
|
||||
header.OptionalDataSize = 0;
|
||||
header.Length = packet.size() + 4;
|
||||
header.Opcode = packet.GetOpcode();
|
||||
|
||||
for (uint32 i = 0; i < packet.size(); i++)
|
||||
data << packet[i];
|
||||
fwrite(&header, sizeof(header), 1, _file);
|
||||
if (!packet.empty())
|
||||
fwrite(packet.contents(), 1, packet.size(), _file);
|
||||
|
||||
fwrite(data.contents(), 1, data.size(), _file);
|
||||
fflush(_file);
|
||||
}
|
||||
Reference in new issue
Block a user