mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-24 13:47:46 +00:00
Ported beautiful packet printing from classic
This commit is contained in:
parent
9cac3a6952
commit
4428ad3033
4 changed files with 68 additions and 15 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <time.h>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include "Server_Common/Util/Util.h"
|
||||
|
||||
Core::Network::Packets::GamePacket::GamePacket( uint16_t subType, uint16_t size, uint32_t id1, uint32_t id2, uint16_t type )
|
||||
{
|
||||
|
@ -97,16 +98,5 @@ void Core::Network::Packets::GamePacket::savePacket()
|
|||
|
||||
std::string Core::Network::Packets::GamePacket::toString() const
|
||||
{
|
||||
|
||||
std::string str = "\n";
|
||||
for( uint32_t i = 0; i < getSize(); i++ )
|
||||
{
|
||||
str += boost::str( boost::format( "%|02X|" ) % ( int32_t ) ( m_dataBuf[i] & 0xFF ) ) + " ";
|
||||
|
||||
if( ( i + 1 ) % 16 == 0 )
|
||||
str += "\n";
|
||||
}
|
||||
str += "\n";
|
||||
|
||||
return str;
|
||||
return Core::Util::binaryToHexDump( const_cast<uint8_t *>(&m_dataBuf[0]), getSize() );
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "Util.h"
|
||||
#include <chrono>
|
||||
#include <boost/variant/detail/substitute.hpp>
|
||||
|
||||
std::string Core::Util::binaryToHexString(uint8_t* pBinData, uint16_t size)
|
||||
{
|
||||
|
||||
std::string outStr;
|
||||
|
||||
for( uint32_t i = 0; i < size; i++ )
|
||||
|
@ -15,6 +15,67 @@ std::string Core::Util::binaryToHexString( uint8_t* pBinData, uint16_t size )
|
|||
|
||||
}
|
||||
|
||||
std::string Core::Util::binaryToHexDump( uint8_t* pBinData, uint16_t size )
|
||||
{
|
||||
int bytesPerLine = 16;
|
||||
std::string hexChars = "0123456789ABCDEF";
|
||||
|
||||
int offsetBlock = 8 + 3;
|
||||
int byteBlock = offsetBlock + bytesPerLine * 3 + ( bytesPerLine - 1 ) / 8 + 2;
|
||||
int lineLength = byteBlock + bytesPerLine + 1;
|
||||
|
||||
std::string line ( lineLength, ' ' );
|
||||
int numLines = ( size + bytesPerLine - 1 ) / bytesPerLine;
|
||||
|
||||
|
||||
std::string outStr;
|
||||
|
||||
for( uint32_t i = 0; i < size; i += bytesPerLine )
|
||||
{
|
||||
line[0] = hexChars[( i >> 28 ) & 0xF];
|
||||
line[1] = hexChars[( i >> 24 ) & 0xF];
|
||||
line[2] = hexChars[( i >> 20 ) & 0xF];
|
||||
line[3] = hexChars[( i >> 16 ) & 0xF];
|
||||
line[4] = hexChars[( i >> 12 ) & 0xF];
|
||||
line[5] = hexChars[( i >> 8 ) & 0xF];
|
||||
line[6] = hexChars[( i >> 4 ) & 0xF];
|
||||
line[7] = hexChars[( i >> 0 ) & 0xF];
|
||||
|
||||
int hexColumn = offsetBlock;
|
||||
int charColumn = byteBlock;
|
||||
|
||||
for( int j = 0; j < bytesPerLine; j++ )
|
||||
{
|
||||
if( j > 0 && ( j & 7 ) == 0)
|
||||
{
|
||||
hexColumn++;
|
||||
}
|
||||
|
||||
if( i + j >= size )
|
||||
{
|
||||
line[hexColumn] = ' ';
|
||||
line[hexColumn + 1] = ' ';
|
||||
line[charColumn] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t by = pBinData[i + j];
|
||||
line[hexColumn] = hexChars[( by >> 4 ) & 0xF];
|
||||
line[hexColumn + 1] = hexChars[by & 0xF];
|
||||
line[charColumn] = by < 32 ? '.' : static_cast<char>(by);
|
||||
}
|
||||
|
||||
hexColumn += 3;
|
||||
charColumn++;
|
||||
}
|
||||
|
||||
outStr += line + "\n";
|
||||
}
|
||||
|
||||
return outStr;
|
||||
|
||||
}
|
||||
|
||||
uint64_t Core::Util::getTimeMs()
|
||||
{
|
||||
std::chrono::milliseconds epoch = std::chrono::duration_cast< std::chrono::milliseconds >(std::chrono::system_clock::now().time_since_epoch());
|
||||
|
|
|
@ -9,6 +9,8 @@ namespace Util {
|
|||
|
||||
std::string binaryToHexString( uint8_t* pBinData, uint16_t size );
|
||||
|
||||
std::string binaryToHexDump(uint8_t* pBinData, uint16_t size);
|
||||
|
||||
uint64_t getTimeMs();
|
||||
|
||||
uint64_t getTimeSeconds();
|
||||
|
|
|
@ -206,7 +206,7 @@ void Core::Network::GameConnection::handleZonePacket( const Packets::GamePacket&
|
|||
g_log.debug( sessionStr + " Undefined Zone IPC : Unknown ( " +
|
||||
boost::str( boost::format( "%|04X|" ) %
|
||||
static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + " )" );
|
||||
g_log.debug( pPacket.toString() );
|
||||
g_log.debug( "\n" + pPacket.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue