From a6b95aeceb874f0764e6d6ea7268712d29137de8 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 31 Jan 2015 02:23:58 -0600 Subject: [PATCH] At point in which Client -> Server packet logging is working, will do more prechecking to declare that anything actually is subscribed to this category before outputting --- common/eq_packet.cpp | 10 +++++++++ common/eq_packet.h | 3 ++- common/eq_stream.cpp | 4 ++++ common/eqemu_logsys.h | 2 +- common/packet_dump.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++ common/packet_dump.h | 1 + common/string_util.cpp | 2 +- zone/client_packet.cpp | 3 +++ zone/zone.h | 24 ++++++++++++---------- 9 files changed, 81 insertions(+), 14 deletions(-) diff --git a/common/eq_packet.cpp b/common/eq_packet.cpp index ffc3666cb..45eccb7de 100644 --- a/common/eq_packet.cpp +++ b/common/eq_packet.cpp @@ -24,6 +24,7 @@ #include "platform.h" #include #include +#include #include #ifndef STATIC_OPCODE @@ -510,3 +511,12 @@ void DumpPacket(const EQApplicationPacket* app, bool iShowInfo) { // DumpPacketAscii(app->pBuffer, app->size); } +std::string DumpPacketToString(const EQApplicationPacket* app, bool iShowInfo){ + std::ostringstream out; + if (iShowInfo) { + out << "Dumping Applayer: 0x" << std::hex << std::setfill('0') << std::setw(4) << app->GetOpcode() << std::dec; + out << " size:" << app->size << std::endl; + } + out << DumpPacketHexToString(app->pBuffer, app->size); + return out.str(); +} \ No newline at end of file diff --git a/common/eq_packet.h b/common/eq_packet.h index dcd3747a0..e3c8182c6 100644 --- a/common/eq_packet.h +++ b/common/eq_packet.h @@ -20,6 +20,7 @@ #include "base_packet.h" #include "platform.h" +#include #ifdef STATIC_OPCODE typedef unsigned short EmuOpcode; @@ -146,6 +147,6 @@ protected: }; extern void DumpPacket(const EQApplicationPacket* app, bool iShowInfo = false); - +extern std::string DumpPacketToString(const EQApplicationPacket* app, bool iShowInfo = false); #endif diff --git a/common/eq_stream.cpp b/common/eq_stream.cpp index 15a494471..506be72d1 100644 --- a/common/eq_stream.cpp +++ b/common/eq_stream.cpp @@ -23,6 +23,7 @@ #include "op_codes.h" #include "crc16.h" #include "platform.h" +#include "string_util.h" #include #include @@ -558,6 +559,9 @@ void EQStream::SendPacket(uint16 opcode, EQApplicationPacket *p) uint32 chunksize,used; uint32 length; + // std::cout << "[Server -> Client] " << StringFormat("[%s - 0x%04x] [Size: %u]", OpcodeManager::EmuToName(p->GetOpcode()), p->GetOpcode(), p->Size()) << std::endl; + // DumpPacket(p); + // Convert the EQApplicationPacket to 1 or more EQProtocolPackets if (p->size>(MaxLen-8)) { // proto-op(2), seq(2), app-op(2) ... data ... crc(2) Log.Out(Logs::Detail, Logs::Netcode, _L "Making oversized packet, len %d" __L, p->size); diff --git a/common/eqemu_logsys.h b/common/eqemu_logsys.h index 1bd63d5b5..7adad1a3c 100644 --- a/common/eqemu_logsys.h +++ b/common/eqemu_logsys.h @@ -88,7 +88,7 @@ namespace Logs{ "AI", "Aggro", "Attack", - "Client Server Packet", + "Packet: [Client -> Server]", "Combat", "Commands", "Crash", diff --git a/common/packet_dump.cpp b/common/packet_dump.cpp index 3c9dfab4f..4f1c2f5f5 100644 --- a/common/packet_dump.cpp +++ b/common/packet_dump.cpp @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -89,6 +90,51 @@ void DumpPacketHex(const uchar* buf, uint32 size, uint32 cols, uint32 skip) { safe_delete_array(ascii); } +std::string DumpPacketHexToString(const uchar* buf, uint32 size, uint32 cols, uint32 skip) { + std::ostringstream out; + if (size == 0 || size > 39565) + return ""; + // Output as HEX + char output[4]; + int j = 0; + char* ascii = new char[cols + 1]; + memset(ascii, 0, cols + 1); + uint32 i; + for (i = skip; i < size; i++) + { + if ((i - skip) % cols == 0) { + if (i != skip) + out << " | " << ascii << std::endl; + out << std::setw(4) << std::setfill(' ') << i - skip << ": "; + memset(ascii, 0, cols + 1); + j = 0; + } + else if ((i - skip) % (cols / 2) == 0) { + out << "- "; + } + sprintf(output, "%02X ", (unsigned char)buf[i]); + out << output; + + if (buf[i] >= 32 && buf[i] < 127) { + ascii[j++] = buf[i]; + } + else { + ascii[j++] = '.'; + } + // std::cout << std::setfill(0) << std::setw(2) << std::hex << (int)buf[i] << " "; // unknown intent [CODEBUG] + } + uint32 k = ((i - skip) - 1) % cols; + if (k < 8) + out << " "; + for (uint32 h = k + 1; h < cols; h++) { + out << " "; + } + out << " | " << ascii << std::endl; + safe_delete_array(ascii); + + return out.str(); +} + void DumpPacket(const uchar* buf, uint32 size) { DumpPacketHex(buf, size); diff --git a/common/packet_dump.h b/common/packet_dump.h index 7a57597f7..db6e485a4 100644 --- a/common/packet_dump.h +++ b/common/packet_dump.h @@ -24,6 +24,7 @@ class ServerPacket; void DumpPacketAscii(const uchar* buf, uint32 size, uint32 cols=16, uint32 skip=0); void DumpPacketHex(const uchar* buf, uint32 size, uint32 cols=16, uint32 skip=0); +std::string DumpPacketHexToString(const uchar* buf, uint32 size, uint32 cols = 16, uint32 skip = 0); void DumpPacketBin(const void* data, uint32 len); void DumpPacket(const uchar* buf, uint32 size); void DumpPacket(const ServerPacket* pack, bool iShowInfo = false); diff --git a/common/string_util.cpp b/common/string_util.cpp index eb1f333f0..89cad4f67 100644 --- a/common/string_util.cpp +++ b/common/string_util.cpp @@ -71,7 +71,6 @@ const std::string StringFormat(const char* format, ...) return output; } - // normal strncpy doesnt put a null term on copied strings, this one does // ref: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecrt/htm/_wcecrt_strncpy_wcsncpy.asp char* strn0cpy(char* dest, const char* source, uint32 size) { @@ -408,3 +407,4 @@ bool isAlphaNumeric(const char *text) return true; } + diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index ea919f344..bca549925 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -404,6 +404,9 @@ int Client::HandlePacket(const EQApplicationPacket *app) Log.Out(Logs::Detail, Logs::Client_Server_Packet, "Dispatch opcode: %s", buffer); } + // std::cout << "[Client -> Server] " << StringFormat("[%s - 0x%04x] [Size: %u] \n %s", OpcodeManager::EmuToName(app->GetOpcode()), app->GetOpcode(), app->Size(), DumpPacketToString(app).c_str()) << std::endl; + Log.Out(Logs::General, Logs::Client_Server_Packet, "[%s - 0x%04x] [Size: %u] \n %s", OpcodeManager::EmuToName(app->GetOpcode()), app->GetOpcode(), app->Size(), DumpPacketToString(app).c_str()); + EmuOpcode opcode = app->GetOpcode(); if (opcode == OP_AckPacket) { return true; diff --git a/zone/zone.h b/zone/zone.h index 3d1775718..28d25b5de 100644 --- a/zone/zone.h +++ b/zone/zone.h @@ -23,6 +23,7 @@ #include "../common/rulesys.h" #include "../common/types.h" #include "../common/random.h" +#include "../common/string_util.h" #include "qglobals.h" #include "spawn2.h" #include "spawngroup.h" @@ -67,16 +68,6 @@ struct item_tick_struct { std::string qglobal; }; -// static uint32 gmsay_log_message_colors[EQEmuLogSys::MaxLogID] = { -// 15, // "Status", - Yellow -// 15, // "Normal", - Yellow -// 3, // "Error", - Red -// 14, // "Debug", - Light Green -// 4, // "Quest", -// 5, // "Command", -// 3 // "Crash" -// }; - class Client; class Map; class Mob; @@ -266,7 +257,18 @@ public: // random object that provides random values for the zone EQEmu::Random random; - static void GMSayHookCallBackProcess(uint16 log_category, const std::string& message){ entity_list.MessageStatus(0, 80, Log.GetGMSayColorFromCategory(log_category), "%s", message.c_str()); } + static void GMSayHookCallBackProcess(uint16 log_category, const std::string& message){ + if (message.find("\n") != std::string::npos){ + auto message_split = SplitString(message, '\n'); + entity_list.MessageStatus(0, 80, Log.GetGMSayColorFromCategory(log_category), "%s", message_split[0].c_str()); + for (size_t iter = 1; iter < message_split.size(); ++iter) { + entity_list.MessageStatus(0, 80, Log.GetGMSayColorFromCategory(log_category), "--- %s", message_split[iter].c_str()); + } + } + else{ + entity_list.MessageStatus(0, 80, Log.GetGMSayColorFromCategory(log_category), "%s", message.c_str()); + } + } //MODDING HOOKS void mod_init();