diff options
| author | Nay <dnpd.dd@gmail.com> | 2012-08-18 17:13:46 +0100 |
|---|---|---|
| committer | Nay <dnpd.dd@gmail.com> | 2012-08-18 17:13:46 +0100 |
| commit | 4e46f7ced6420927e4520bca34f4bee7d1f1c707 (patch) | |
| tree | 02256e0b3e64229a45106a0763e7d68e643d0c4e /src/server/game/Server/Protocol | |
| parent | 0d7b5d07c843829da027ae9ed7b2bf2165882418 (diff) | |
| parent | 19cec23f396c0ab8cb6a574eea5665c73e5ce5a2 (diff) | |
Merge remote-tracking branch 'origin/master' into 4.3.4
Conflicts:
src/server/game/Achievements/AchievementMgr.cpp
src/server/game/Entities/Item/ItemEnchantmentMgr.cpp
src/server/game/Events/GameEventMgr.cpp
src/server/game/Globals/ObjectMgr.cpp
src/server/game/Guilds/GuildMgr.cpp
src/server/game/Loot/LootMgr.cpp
src/server/game/Server/WorldSocket.cpp
src/server/game/Spells/SpellMgr.cpp
src/server/worldserver/worldserver.conf.dist
Diffstat (limited to 'src/server/game/Server/Protocol')
| -rw-r--r-- | src/server/game/Server/Protocol/PacketLog.cpp | 62 | ||||
| -rw-r--r-- | src/server/game/Server/Protocol/PacketLog.h | 50 |
2 files changed, 112 insertions, 0 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 |
