mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 21:01:29 +00:00
Converted a lot of the char[] stuff internally into std:string
in addition I switched over to <string> rather than <string.h>
This commit is contained in:
parent
7560b6b0a7
commit
37b7a49faf
@ -1,9 +1,11 @@
|
||||
#include "debug.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <process.h>
|
||||
|
||||
@ -88,36 +90,39 @@ bool EQEMuLog::open(LogIDs id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
char exename[200] = "";
|
||||
string filename = FileNames[id];
|
||||
|
||||
const EQEmuExePlatform &platform = GetExecutablePlatform();
|
||||
|
||||
if(platform == ExePlatformWorld) {
|
||||
snprintf(exename, sizeof(exename), "_world");
|
||||
filename.append("_world");
|
||||
} else if(platform == ExePlatformZone) {
|
||||
snprintf(exename, sizeof(exename), "_zone");
|
||||
filename.append("_zone");
|
||||
} else if(platform == ExePlatformLaunch) {
|
||||
snprintf(exename, sizeof(exename), "_launch");
|
||||
filename.append("_launch");
|
||||
} else if(platform == ExePlatformUCS) {
|
||||
snprintf(exename, sizeof(exename), "_ucs");
|
||||
filename.append("_ucs");
|
||||
} else if(platform == ExePlatformQueryServ) {
|
||||
snprintf(exename, sizeof(exename), "_queryserv");
|
||||
filename.append("_queryserv");
|
||||
} else if(platform == ExePlatformSharedMemory) {
|
||||
snprintf(exename, sizeof(exename), "_shared_memory");
|
||||
filename.append("_shared_memory");
|
||||
}
|
||||
|
||||
char filename[200];
|
||||
#ifndef NO_PIDLOG
|
||||
snprintf(filename, sizeof(filename), "%s%s_%04i.log", FileNames[id], exename, getpid());
|
||||
#else
|
||||
snprintf(filename, sizeof(filename), "%s%s.log", FileNames[id], exename);
|
||||
// According to http://msdn.microsoft.com/en-us/library/vstudio/ee404875(v=vs.100).aspx
|
||||
// Visual Studio 2010 doesn't have std::to_string(int) but it does have one for
|
||||
// long long. Oh well, it works fine and formats perfectly acceptably.
|
||||
filename.append(to_string((long long)getpid()));
|
||||
#endif
|
||||
fp[id] = fopen(filename, "a");
|
||||
filename.append(".log");
|
||||
fp[id] = fopen(filename.c_str(), "a");
|
||||
if (!fp[id]) {
|
||||
cerr << "Failed to open log file: " << filename << endl;
|
||||
pLogStatus[id] |= 4; // set file state to error
|
||||
return false;
|
||||
}
|
||||
fputs("---------------------------------------------\n",fp[id]);
|
||||
write(id, "Starting Log: %s", filename);
|
||||
write(id, "Starting Log: %s", filename.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -350,36 +355,45 @@ bool EQEMuLog::Dump(LogIDs id, uint8* data, uint32 size, uint32 cols, uint32 ski
|
||||
|
||||
write(id, "Dumping Packet: %i", size);
|
||||
// Output as HEX
|
||||
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)
|
||||
writeNTS(id, dofile, " | %s\n", ascii);
|
||||
writeNTS(id, dofile, "%4i: ", i-skip);
|
||||
memset(ascii, 0, cols+1);
|
||||
j = 0;
|
||||
|
||||
int beginningOfLineOffset = 0;
|
||||
uint32 indexInData;
|
||||
std::string asciiOutput;
|
||||
|
||||
for(indexInData=skip; indexInData<size; indexInData++) {
|
||||
if ((indexInData-skip)%cols==0) {
|
||||
if (indexInData != skip)
|
||||
writeNTS(id, dofile, " | %s\n", asciiOutput.c_str());
|
||||
writeNTS(id, dofile, "%4i: ", indexInData-skip);
|
||||
asciiOutput.clear();
|
||||
beginningOfLineOffset = 0;
|
||||
}
|
||||
else if ((i-skip)%(cols/2) == 0) {
|
||||
else if ((indexInData-skip)%(cols/2) == 0) {
|
||||
writeNTS(id, dofile, "- ");
|
||||
}
|
||||
writeNTS(id, dofile, "%02X ", (unsigned char)data[i]);
|
||||
writeNTS(id, dofile, "%02X ", (unsigned char)data[indexInData]);
|
||||
|
||||
if (data[i] >= 32 && data[i] < 127)
|
||||
ascii[j++] = data[i];
|
||||
if (data[indexInData] >= 32 && data[indexInData] < 127)
|
||||
{
|
||||
// According to http://msdn.microsoft.com/en-us/library/vstudio/ee404875(v=vs.100).aspx
|
||||
// Visual Studio 2010 doesn't have std::to_string(int) but it does have the long long
|
||||
// version.
|
||||
asciiOutput.append(to_string((long long)data[indexInData]));
|
||||
}
|
||||
else
|
||||
ascii[j++] = '.';
|
||||
{
|
||||
asciiOutput.append(".");
|
||||
}
|
||||
}
|
||||
uint32 k = ((i-skip)-1)%cols;
|
||||
uint32 k = ((indexInData-skip)-1)%cols;
|
||||
if (k < 8)
|
||||
writeNTS(id, dofile, " ");
|
||||
for (uint32 h = k+1; h < cols; h++) {
|
||||
writeNTS(id, dofile, " ");
|
||||
}
|
||||
writeNTS(id, dofile, " | %s\n", ascii);
|
||||
writeNTS(id, dofile, " | %s\n", asciiOutput.c_str());
|
||||
if (dofile)
|
||||
fflush(fp[id]);
|
||||
safe_delete_array(ascii);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -436,6 +450,3 @@ void EQEMuLog::SetAllCallbacks(msgCallbackPva proc) {
|
||||
SetCallback((LogIDs)r, proc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -80,8 +80,8 @@ typedef const char Const_char; //for perl XS
|
||||
#define THREAD_RETURN(x) return(x);
|
||||
#endif
|
||||
|
||||
#define safe_delete(d) if(d) { delete d; d=0; }
|
||||
#define safe_delete_array(d) if(d) { delete[] d; d=0; }
|
||||
#define safe_delete(d) if(d) { delete d; d=nullptr; }
|
||||
#define safe_delete_array(d) if(d) { delete[] d; d=nullptr; }
|
||||
#define L32(i) ((uint32) i)
|
||||
#define H32(i) ((uint32) (i >> 32))
|
||||
#define L16(i) ((uint16) i)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user