aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDDuarte <dnpd.dd@gmail.com>2014-07-30 03:44:30 +0100
committerDDuarte <dnpd.dd@gmail.com>2014-07-30 03:45:03 +0100
commit43f868e55ca368d42f3b1dbf763d50cf01233498 (patch)
tree3e94fa7d2834336beb93820252ded997c0242fa1 /src
parent2b6ee6674a4a1314cfa95ce30437ec720e850bbe (diff)
Core/PacketLog: Save session ip and port information in saved packets
This data is put into the "optional data" part of each packet of the PKT 3.1 format It will be used with WPP to debug some networking issues
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Server/Protocol/PacketLog.cpp28
-rw-r--r--src/server/game/Server/Protocol/PacketLog.h3
-rw-r--r--src/server/game/Server/WorldSocket.cpp4
3 files changed, 29 insertions, 6 deletions
diff --git a/src/server/game/Server/Protocol/PacketLog.cpp b/src/server/game/Server/Protocol/PacketLog.cpp
index 23dfb3538bc..62779d3fbf2 100644
--- a/src/server/game/Server/Protocol/PacketLog.cpp
+++ b/src/server/game/Server/Protocol/PacketLog.cpp
@@ -38,11 +38,19 @@ struct LogHeader
struct PacketHeader
{
+ // used to uniquely identify a connection
+ struct OptionalData
+ {
+ uint8 SocketIPBytes[16];
+ uint32 SocketPort;
+ };
+
char Direction[4];
uint32 ConnectionId;
uint32 ArrivalTicks;
uint32 OptionalDataSize;
uint32 Length;
+ OptionalData OptionalData;
uint32 Opcode;
};
@@ -89,14 +97,28 @@ void PacketLog::Initialize()
}
}
-void PacketLog::LogPacket(WorldPacket const& packet, Direction direction)
+void PacketLog::LogPacket(WorldPacket const& packet, Direction direction, boost::asio::ip::address addr, uint16 port)
{
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.OptionalDataSize = sizeof(header.OptionalData);
+ memset(header.OptionalData.SocketIPBytes, 0, sizeof(header.OptionalData.SocketIPBytes));
+ if (addr.is_v4())
+ {
+ auto bytes = addr.to_v4().to_bytes();
+ memcpy(header.OptionalData.SocketIPBytes, bytes.data(), bytes.size());
+ }
+ else if (addr.is_v6())
+ {
+ auto bytes = addr.to_v6().to_bytes();
+ memcpy(header.OptionalData.SocketIPBytes, bytes.data(), bytes.size());
+ }
+
+ header.OptionalData.SocketPort = port;
+ header.Length = packet.size() + sizeof(header.Opcode);
header.Opcode = packet.GetOpcode();
fwrite(&header, sizeof(header), 1, _file);
diff --git a/src/server/game/Server/Protocol/PacketLog.h b/src/server/game/Server/Protocol/PacketLog.h
index 4f298fa3c50..b09e853236a 100644
--- a/src/server/game/Server/Protocol/PacketLog.h
+++ b/src/server/game/Server/Protocol/PacketLog.h
@@ -19,6 +19,7 @@
#define TRINITY_PACKETLOG_H
#include "Common.h"
+#include <boost/asio/ip/address.hpp>
enum Direction
{
@@ -43,7 +44,7 @@ class PacketLog
void Initialize();
bool CanLogPacket() const { return (_file != NULL); }
- void LogPacket(WorldPacket const& packet, Direction direction);
+ void LogPacket(WorldPacket const& packet, Direction direction, boost::asio::ip::address addr, uint16 port);
private:
FILE* _file;
diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp
index e5fea7e6b6b..65a424d5d75 100644
--- a/src/server/game/Server/WorldSocket.cpp
+++ b/src/server/game/Server/WorldSocket.cpp
@@ -92,7 +92,7 @@ void WorldSocket::ReadDataHandler(boost::system::error_code error, size_t transf
}
if (sPacketLog->CanLogPacket())
- sPacketLog->LogPacket(packet, CLIENT_TO_SERVER);
+ sPacketLog->LogPacket(packet, CLIENT_TO_SERVER, GetRemoteIpAddress(), GetRemotePort());
TC_LOG_TRACE("network.opcode", "C->S: %s %s", (_worldSession ? _worldSession->GetPlayerInfo() : GetRemoteIpAddress().to_string()).c_str(), GetOpcodeNameForLogging(opcode).c_str());
@@ -142,7 +142,7 @@ void WorldSocket::ReadDataHandler(boost::system::error_code error, size_t transf
void WorldSocket::AsyncWrite(WorldPacket& packet)
{
if (sPacketLog->CanLogPacket())
- sPacketLog->LogPacket(packet, SERVER_TO_CLIENT);
+ sPacketLog->LogPacket(packet, SERVER_TO_CLIENT, GetRemoteIpAddress(), GetRemotePort());
TC_LOG_TRACE("network.opcode", "S->C: %s %s", (_worldSession ? _worldSession->GetPlayerInfo() : GetRemoteIpAddress().to_string()).c_str(), GetOpcodeNameForLogging(packet.GetOpcode()).c_str());