/* EQEmu: EQEmulator Copyright (C) 2001-2026 EQEmu Development Team 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 3 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 . */ #include "packet_dump_file.h" #include "common/eq_stream_intf.h" #include #include #include #include #include #include void FileDumpPacketAscii(const char* filename, const uchar* buf, uint32 size, uint32 cols, uint32 skip) { std::ofstream logfile(filename, std::ios::app); // Output as ASCII for(uint32 i=skip; i 32 && buf[i] < 127) { logfile << buf[i]; } else { logfile << '.'; } } logfile << std::endl << std::endl; } void oldFileDumpPacketHex(const char* filename, const uchar* buf, uint32 size, uint32 cols, uint32 skip) { std::ofstream logfile(filename, std::ios::app); // Output as HEX char output[4]; for(uint32 i=skip; i= 32 && buf[i] < 127) { ascii[j++] = buf[i]; } else { ascii[j++] = '.'; } //logfile << std::setfill(0) << std::setw(2) << std::hex << (int)buf[i] << " "; // unknown intent [CODEBUG] } uint32 k = ((i-skip)-1)%cols; if (k < 8) logfile << " "; for (uint32 h = k+1; h < cols; h++) { logfile << " "; } logfile << " | " << ascii << std::endl; delete[] ascii; } void FileDumpPacketHex(const char* filename, const EQApplicationPacket* app) { FileDumpPacketHex(filename, app->pBuffer, app->size); } void FileDumpPacketAscii(const char* filename, const EQApplicationPacket* app) { FileDumpPacketAscii(filename, app->pBuffer, app->size); } void FileDumpPacket(const char* filename, const uchar* buf, uint32 size) { FilePrintLine(filename, true, "Size: %5i", size); FileDumpPacketHex(filename, buf, size); // FileDumpPacketAscii(filename, buf,size); } void FileDumpPacket(const char* filename, const EQApplicationPacket* app) { FilePrintLine(filename, true, "Size: %5i, OPCode: 0x%04x", app->size, app->GetOpcode()); FileDumpPacketHex(filename, app->pBuffer, app->size); // FileDumpPacketAscii(filename, app->pBuffer, app->size); } /* prints a line to the file. if text = 0, prints a blank line if prefix_timestamp specified, prints the current date/time to the file + ": " + text */ void FilePrintLine(const char* filename, bool prefix_timestamp, const char* text, ...) { std::ofstream logfile(filename, std::ios::app); if (prefix_timestamp) { time_t rawtime; struct tm* gmt_t; time(&rawtime); gmt_t = gmtime(&rawtime); logfile << (gmt_t->tm_year + 1900) << "/" << std::setw(2) << std::setfill('0') << (gmt_t->tm_mon + 1) << "/" << std::setw(2) << std::setfill('0') << gmt_t->tm_mday << " " << std::setw(2) << std::setfill('0') << gmt_t->tm_hour << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_min << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_sec << " GMT"; } if (text != 0) { va_list argptr; char buffer[256]; va_start(argptr, text); vsnprintf(buffer, 256, text, argptr); va_end(argptr); if (prefix_timestamp) logfile << ": "; logfile << buffer; } logfile << std::endl; } void FilePrint(const char* filename, bool newline, bool prefix_timestamp, const char* text, ...) { std::ofstream logfile(filename, std::ios::app); if (prefix_timestamp) { time_t rawtime; struct tm* gmt_t; time(&rawtime); gmt_t = gmtime(&rawtime); logfile << (gmt_t->tm_year + 1900) << "/" << std::setw(2) << std::setfill('0') << (gmt_t->tm_mon + 1) << "/" << std::setw(2) << std::setfill('0') << gmt_t->tm_mday << " " << std::setw(2) << std::setfill('0') << gmt_t->tm_hour << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_min << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_sec << " GMT"; } if (text != 0) { va_list argptr; char buffer[1000]; va_start(argptr, text); vsnprintf(buffer,1000, text, argptr); va_end(argptr); if (prefix_timestamp) logfile << ": "; logfile << buffer; } if (newline) logfile << std::endl; }