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