From 37b7a49faf94e584c27ec30195543563ab3777fe Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sun, 5 May 2013 16:40:03 -0700 Subject: [PATCH 1/2] Converted a lot of the char[] stuff internally into std:string in addition I switched over to rather than --- common/debug.cpp | 79 +++++++++++++++++++++++++++--------------------- common/types.h | 4 +-- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/common/debug.cpp b/common/debug.cpp index ebeed542f..5d906aeb4 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -1,9 +1,11 @@ #include "debug.h" #include +#include using namespace std; + #include -#include + #ifdef _WINDOWS #include @@ -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= 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); } } - - - diff --git a/common/types.h b/common/types.h index 21f530467..db5cd49d0 100644 --- a/common/types.h +++ b/common/types.h @@ -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) From d7dff7d7a61098739dc2af682c2327c2c83c3049 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sun, 5 May 2013 16:58:16 -0700 Subject: [PATCH 2/2] Removed the _MSC_VER special cases for Visual Studio 2008 and lower. We no longer support 2008 and lower so these defines will never be used. --- common/MiscFunctions.cpp | 3 --- common/TCPConnection.h | 3 --- common/debug.cpp | 3 --- common/debug.h | 20 +++++--------------- common/packet_dump_file.cpp | 3 --- common/types.h | 3 --- world/LoginServer.cpp | 3 --- world/client.cpp | 3 --- world/console.cpp | 3 --- world/net.cpp | 3 --- zone/PlayerCorpse.cpp | 9 +++------ zone/beacon.cpp | 9 +++------ zone/client.cpp | 21 +++++++++------------ zone/client_packet.cpp | 3 --- zone/client_process.cpp | 3 --- zone/entity.cpp | 9 +++------ zone/net.cpp | 12 +++++------- zone/petitions.cpp | 9 +++------ zone/tribute.cpp | 15 ++++++--------- zone/worldserver.cpp | 3 --- 20 files changed, 37 insertions(+), 103 deletions(-) diff --git a/common/MiscFunctions.cpp b/common/MiscFunctions.cpp index f6cd00e63..e6089dfba 100644 --- a/common/MiscFunctions.cpp +++ b/common/MiscFunctions.cpp @@ -38,9 +38,6 @@ using namespace std; #include #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #else diff --git a/common/TCPConnection.h b/common/TCPConnection.h index d2f942c5e..1715ce04d 100644 --- a/common/TCPConnection.h +++ b/common/TCPConnection.h @@ -24,9 +24,6 @@ #ifdef _WINDOWS #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp diff --git a/common/debug.cpp b/common/debug.cpp index 5d906aeb4..e6d290fa2 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -10,9 +10,6 @@ using namespace std; #include #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #else diff --git a/common/debug.h b/common/debug.h index 62641f53a..b7f0847c0 100644 --- a/common/debug.h +++ b/common/debug.h @@ -1,5 +1,5 @@ /* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) + Copyright (C) 2001-2013 EQEMu Development Team (http://eqemu.org) 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 @@ -45,22 +45,9 @@ #ifndef _CRTDBG_MAP_ALLOC #include #include - #if (_MSC_VER < 1300) - #include - #include - #define _CRTDBG_MAP_ALLOC - #define new new(_NORMAL_BLOCK, __FILE__, __LINE__) - #define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__) - #endif #endif #endif -#ifdef _WINDOWS - // VS6 doesn't like the length of STL generated names: disabling - #pragma warning(disable:4786) - #pragma warning(disable:4996) -#endif - #ifndef EQDEBUG_H #define EQDEBUG_H @@ -82,6 +69,7 @@ #include "logsys.h" #include "common_profile.h" + #ifdef ZONE #include "../zone/zone_profile.h" #endif @@ -160,5 +148,7 @@ public: LARGE_INTEGER tmp; int64* p; }; + #endif -#endif + +#endif \ No newline at end of file diff --git a/common/packet_dump_file.cpp b/common/packet_dump_file.cpp index e02de9348..85b0075fd 100644 --- a/common/packet_dump_file.cpp +++ b/common/packet_dump_file.cpp @@ -29,9 +29,6 @@ #ifdef _WINDOWS #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #else diff --git a/common/types.h b/common/types.h index db5cd49d0..16019ba86 100644 --- a/common/types.h +++ b/common/types.h @@ -68,9 +68,6 @@ typedef const char Const_char; //for perl XS #ifdef _WINDOWS #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp typedef void ThreadReturnType; diff --git a/world/LoginServer.cpp b/world/LoginServer.cpp index bb1c671da..00855edb8 100644 --- a/world/LoginServer.cpp +++ b/world/LoginServer.cpp @@ -31,9 +31,6 @@ using namespace std; #include #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #else // Pyro: fix for linux diff --git a/world/client.cpp b/world/client.cpp index f082a22e7..3b162c6d9 100644 --- a/world/client.cpp +++ b/world/client.cpp @@ -20,9 +20,6 @@ using namespace std; #include #include #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #else diff --git a/world/console.cpp b/world/console.cpp index d6b1a2414..103a5c7e3 100644 --- a/world/console.cpp +++ b/world/console.cpp @@ -49,9 +49,6 @@ using namespace std; #ifdef _WINDOWS #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #endif diff --git a/world/net.cpp b/world/net.cpp index 4be92a893..3a7639f52 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -47,9 +47,6 @@ using namespace std; #ifdef _WINDOWS #include #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #include diff --git a/zone/PlayerCorpse.cpp b/zone/PlayerCorpse.cpp index 6e4fb74f3..79a44e2fe 100644 --- a/zone/PlayerCorpse.cpp +++ b/zone/PlayerCorpse.cpp @@ -28,12 +28,9 @@ Child of the Mob class. #include using namespace std; #ifdef _WINDOWS -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define snprintf _snprintf + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #endif #include "masterentity.h" diff --git a/zone/beacon.cpp b/zone/beacon.cpp index 5ed82f8a8..5d5d56480 100644 --- a/zone/beacon.cpp +++ b/zone/beacon.cpp @@ -25,12 +25,9 @@ target to center around. #include "../common/debug.h" #ifdef _WINDOWS -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define snprintf _snprintf + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #endif #include "masterentity.h" diff --git a/zone/client.cpp b/zone/client.cpp index 04f15841c..ff2c767b7 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -28,19 +28,16 @@ using namespace std; // for windows compile #ifdef _WINDOWS -#define abs64 _abs64 -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define abs64 _abs64 + #define snprintf _snprintf + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #else -#include -#include -#include -#include "../common/unix.h" -#define abs64 abs + #include + #include + #include + #include "../common/unix.h" + #define abs64 abs #endif extern volatile bool RunLoops; diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 731f10f47..56296eee4 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -29,9 +29,6 @@ #ifdef _WINDOWS #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #else diff --git a/zone/client_process.cpp b/zone/client_process.cpp index 597684aa1..9b278e57f 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -32,9 +32,6 @@ #include #include #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #else diff --git a/zone/entity.cpp b/zone/entity.cpp index 6026329fd..9429772f7 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -49,12 +49,9 @@ using namespace std; #include "QuestParserCollection.h" #ifdef _WINDOWS -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define snprintf _snprintf + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #endif extern Zone* zone; diff --git a/zone/net.cpp b/zone/net.cpp index e7d7ddf1c..65a698009 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -33,14 +33,12 @@ using namespace std; #define new new(_NORMAL_BLOCK, __FILE__, __LINE__) #endif using namespace std; + #ifdef _WINDOWS -#include -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #include + #define snprintf _snprintf + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #endif volatile bool RunLoops = true; diff --git a/zone/petitions.cpp b/zone/petitions.cpp index 13954df17..ef3a9f113 100644 --- a/zone/petitions.cpp +++ b/zone/petitions.cpp @@ -28,12 +28,9 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) #endif #ifdef _WINDOWS -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define snprintf _snprintf + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #endif #include "../common/packet_functions.h" #include "../common/packet_dump.h" diff --git a/zone/tribute.cpp b/zone/tribute.cpp index acfab14f0..ce6695c40 100644 --- a/zone/tribute.cpp +++ b/zone/tribute.cpp @@ -27,16 +27,13 @@ using namespace std; #ifdef _WINDOWS -#include -#include -#include + #include + #include + #include -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define snprintf _snprintf + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #else #include #include diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index c25af347e..1ce93b078 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -29,9 +29,6 @@ using namespace std; #include #define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif #define strncasecmp _strnicmp #define strcasecmp _stricmp #endif