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

This commit is contained in:
Akkadius 2015-01-31 02:23:58 -06:00
parent 0bdbc5f5c9
commit a6b95aeceb
9 changed files with 81 additions and 14 deletions

View File

@ -24,6 +24,7 @@
#include "platform.h"
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdio.h>
#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();
}

View File

@ -20,6 +20,7 @@
#include "base_packet.h"
#include "platform.h"
#include <iostream>
#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

View File

@ -23,6 +23,7 @@
#include "op_codes.h"
#include "crc16.h"
#include "platform.h"
#include "string_util.h"
#include <string>
#include <iomanip>
@ -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);

View File

@ -88,7 +88,7 @@ namespace Logs{
"AI",
"Aggro",
"Attack",
"Client Server Packet",
"Packet: [Client -> Server]",
"Combat",
"Commands",
"Crash",

View File

@ -17,6 +17,7 @@
*/
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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;

View File

@ -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();