diff options
| -rw-r--r-- | src/server/game/Server/Protocol/PacketLog.cpp | 62 | ||||
| -rw-r--r-- | src/server/game/Server/Protocol/PacketLog.h | 50 | ||||
| -rwxr-xr-x | src/server/game/Server/WorldSocket.cpp | 54 | ||||
| -rw-r--r-- | src/server/worldserver/worldserver.conf.dist | 9 |
4 files changed, 127 insertions, 48 deletions
diff --git a/src/server/game/Server/Protocol/PacketLog.cpp b/src/server/game/Server/Protocol/PacketLog.cpp new file mode 100644 index 00000000000..cb6dcdbdb9e --- /dev/null +++ b/src/server/game/Server/Protocol/PacketLog.cpp @@ -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); +} diff --git a/src/server/game/Server/Protocol/PacketLog.h b/src/server/game/Server/Protocol/PacketLog.h new file mode 100644 index 00000000000..b899daae198 --- /dev/null +++ b/src/server/game/Server/Protocol/PacketLog.h @@ -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 diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 5b04c3dc714..ed960fd9693 100755 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -42,6 +42,7 @@ #include "WorldSession.h" #include "WorldSocketMgr.h" #include "Log.h" +#include "PacketLog.h" #include "ScriptMgr.h" #include "AccountMgr.h" @@ -159,30 +160,8 @@ int WorldSocket::SendPacket(WorldPacket const& pct) return -1; // Dump outgoing packet. - if (sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) - { - 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()); - } + if (sPacketLog->CanLogPacket()) + sPacketLog->LogPacket(pct, SERVER_TO_CLIENT); // Create a copy of the original packet; this is to avoid issues if a hook modifies it. sScriptMgr->OnPacketSend(this, WorldPacket(pct)); @@ -691,30 +670,9 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct) if (closing_) return -1; - if (sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) - { - char buff[250]; - 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()); - } + // Dump received packet. + if (sPacketLog->CanLogPacket()) + sPacketLog->LogPacket(*new_pct, CLIENT_TO_SERVER); try { diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index 5bdf805fb4f..133fdff3dd0 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -404,6 +404,15 @@ PersistentCharacterCleanFlags = 0 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 # Description: Log custom channel chat. # Default: 0 - (Disabled) |
