From 37b7a49faf94e584c27ec30195543563ab3777fe Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sun, 5 May 2013 16:40:03 -0700 Subject: [PATCH 01/10] 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 02/10] 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 From c6ca89907c475dd0f51972519e70ce6e3bdbbafe Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sun, 5 May 2013 16:40:03 -0700 Subject: [PATCH 03/10] 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 23c524812d2764b7b054fc4be5980ccad7f8a118 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sun, 5 May 2013 16:58:16 -0700 Subject: [PATCH 04/10] 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 21431836e..e84fb8c68 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 1f96a2122..6205b9ba6 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 9724dec22..df01534ac 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 1a68970ac..b07060c9d 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 e6a350b3b..2173e449e 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 8cf493969..8afc9785a 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 From 273cb928bf6a5a6d37c45c9dcc461076680949a8 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 8 May 2013 18:13:33 -0700 Subject: [PATCH 05/10] removed using namespace std --- common/debug.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/debug.cpp b/common/debug.cpp index e6d290fa2..fabe0ce17 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -2,7 +2,6 @@ #include #include -using namespace std; #include @@ -72,6 +71,7 @@ EQEMuLog::~EQEMuLog() { } bool EQEMuLog::open(LogIDs id) { + if (!logFileValid) { return false; } @@ -87,7 +87,7 @@ bool EQEMuLog::open(LogIDs id) { return true; } - string filename = FileNames[id]; + std::string filename = FileNames[id]; const EQEmuExePlatform &platform = GetExecutablePlatform(); @@ -109,12 +109,12 @@ bool EQEMuLog::open(LogIDs id) { // 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())); + filename.append(std::to_string((long long)getpid())); #endif filename.append(".log"); fp[id] = fopen(filename.c_str(), "a"); if (!fp[id]) { - cerr << "Failed to open log file: " << filename << endl; + std::cerr << "Failed to open log file: " << filename << std::endl; pLogStatus[id] |= 4; // set file state to error return false; } @@ -328,6 +328,7 @@ bool EQEMuLog::writeNTS(LogIDs id, bool dofile, const char *fmt, ...) { }; bool EQEMuLog::Dump(LogIDs id, uint8* data, uint32 size, uint32 cols, uint32 skip) { + if (!logFileValid) { #if EQDEBUG >= 10 cerr << "Error: Dump() from null pointer"< Date: Fri, 10 May 2013 23:18:00 -0700 Subject: [PATCH 06/10] Added StringUtil h/cpp which contains StringFormat --- common/StringUtil.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++ common/StringUtil.h | 23 ++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 common/StringUtil.cpp create mode 100644 common/StringUtil.h diff --git a/common/StringUtil.cpp b/common/StringUtil.cpp new file mode 100644 index 000000000..2371d5148 --- /dev/null +++ b/common/StringUtil.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2013 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "StringUtil.h" +#include +#include +#include + +#ifdef _WINDOWS + #include + + #define snprintf _snprintf + #define strncasecmp _strnicmp + #define strcasecmp _stricmp +#else + #include +#endif + + +// original source: +// https://github.com/facebook/folly/blob/master/folly/String.cpp +// +void StringFormat(std::string& output, const char* format, ...) +{ + va_list args; + // Tru to the space at the end of output for our output buffer. + // Find out write point then inflate its size temporarily to its + // capacity; we will later shrink it to the size needed to represent + // the formatted string. If this buffer isn't large enough, we do a + // resize and try again. + + const auto write_point = output.size(); + auto remaining = output.capacity() - write_point; + output.resize(output.capacity()); + + va_start(args, format); + int bytes_used = vsnprintf(&output[write_point], remaining, format,args); + va_end(args); + if (bytes_used < 0) { + + std::string errorMessage("Invalid format string; snprintf returned negative with format string: "); + errorMessage.append(format); + + throw std::runtime_error(errorMessage); + } + else if ((unsigned int)bytes_used < remaining) { + // There was enough room, just shrink and return. + output.resize(write_point + bytes_used); + } + else { + output.resize(write_point + bytes_used + 1); + remaining = bytes_used + 1; + + va_start(args, format); + bytes_used = vsnprintf(&output[write_point], remaining, format, args); + va_end(args); + + if ((unsigned int)(bytes_used + 1) != remaining) { + + std::string errorMessage("vsnprint retry did not manage to work with format string: "); + errorMessage.append(format); + + throw std::runtime_error(errorMessage); + } + + output.resize(write_point + bytes_used); + } +} diff --git a/common/StringUtil.h b/common/StringUtil.h new file mode 100644 index 000000000..226aa82f2 --- /dev/null +++ b/common/StringUtil.h @@ -0,0 +1,23 @@ +/* + * Copyright 2013 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _STRINGUTIL_H_ +#define _STRINGUTIL_H_ + +#include + +void StringFormat(std::string& output, const char* format, ...); + +#endif From 373ff6624001721f5817acc0ca1072b115fd5b7b Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sat, 11 May 2013 00:05:11 -0700 Subject: [PATCH 07/10] moved string functions from MiscFunctions to StringUtil --- common/CMakeLists.txt | 2 + common/MiscFunctions.cpp | 236 ---------------------------------- common/MiscFunctions.h | 28 +--- common/StringUtil.cpp | 241 +++++++++++++++++++++++++++++++++++ common/StringUtil.h | 32 +++++ common/database.cpp | 3 +- common/dbasync.cpp | 3 +- common/debug.cpp | 28 ++-- common/guild_base.cpp | 3 +- common/md5.cpp | 2 +- common/patches/Client62.cpp | 1 + common/patches/RoF.cpp | 1 + common/patches/SoD.cpp | 1 + common/patches/SoF.cpp | 2 +- common/patches/Titanium.cpp | 2 +- common/patches/Underfoot.cpp | 1 + common/ptimer.cpp | 2 +- common/rulesys.cpp | 2 +- common/shareddb.cpp | 2 +- eqlaunch/worldserver.cpp | 1 + queryserv/database.cpp | 2 +- queryserv/lfguild.cpp | 2 +- ucs/chatchannel.cpp | 2 +- ucs/clientlist.cpp | 2 +- ucs/database.cpp | 1 + world/Adventure.cpp | 3 +- world/AdventureManager.cpp | 1 + world/EQLConfig.cpp | 2 +- world/EQW.cpp | 2 +- world/LauncherLink.cpp | 1 + world/LoginServer.cpp | 2 +- world/client.cpp | 2 +- world/cliententry.cpp | 1 + world/clientlist.cpp | 1 + world/console.cpp | 1 + world/worlddb.cpp | 2 +- world/zonelist.cpp | 2 +- world/zoneserver.cpp | 2 +- zone/AA.cpp | 2 +- zone/MobAI.cpp | 2 +- zone/Object.cpp | 2 +- zone/PlayerCorpse.cpp | 1 + zone/QGlobals.cpp | 2 +- zone/attack.cpp | 2 +- zone/bot.cpp | 1 + zone/botspellsai.cpp | 1 + zone/client.cpp | 2 +- zone/client_packet.cpp | 2 +- zone/client_process.cpp | 2 +- zone/command.cpp | 2 +- zone/doors.cpp | 2 +- zone/embparser.cpp | 2 +- zone/forage.cpp | 2 +- zone/groups.cpp | 2 +- zone/guild.cpp | 2 +- zone/guild_mgr.cpp | 1 + zone/horse.cpp | 2 +- zone/inventory.cpp | 1 + zone/merc.cpp | 2 +- zone/mob.cpp | 1 + zone/npc.cpp | 2 +- zone/parser.cpp | 1 + zone/petitions.cpp | 1 + zone/pets.cpp | 2 +- zone/questmgr.cpp | 2 +- zone/raids.cpp | 2 +- zone/spawn2.cpp | 1 + zone/spawngroup.cpp | 1 + zone/spells.cpp | 8 +- zone/tasks.cpp | 2 +- zone/titles.cpp | 2 +- zone/tradeskills.cpp | 2 +- zone/trading.cpp | 2 +- zone/trap.cpp | 2 +- zone/watermap.cpp | 3 +- zone/waypoints.cpp | 2 +- zone/zone.cpp | 2 +- zone/zonedb.cpp | 2 +- zone/zonedbasync.cpp | 2 +- zone/zoning.cpp | 1 + 80 files changed, 381 insertions(+), 323 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 2cb7a8a70..1d364c4a7 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -55,6 +55,7 @@ SET(common_sources serverinfo.cpp shareddb.cpp spdat.cpp + StringUtil.cpp StructStrategy.cpp TCPConnection.cpp TCPServer.cpp @@ -170,6 +171,7 @@ SET(common_headers shareddb.h skills.h spdat.h + StringUtil.h StructStrategy.h TCPBasicServer.h TCPConnection.h diff --git a/common/MiscFunctions.cpp b/common/MiscFunctions.cpp index e6089dfba..734a48fd5 100644 --- a/common/MiscFunctions.cpp +++ b/common/MiscFunctions.cpp @@ -89,201 +89,7 @@ void CoutTimestamp(bool ms) { cout << " GMT"; } -// normal strncpy doesnt put a null term on copied strings, this one does -// ref: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecrt/htm/_wcecrt_strncpy_wcsncpy.asp -char* strn0cpy(char* dest, const char* source, uint32 size) { - if (!dest) - return 0; - if (size == 0 || source == 0) { - dest[0] = 0; - return dest; - } - strncpy(dest, source, size); - dest[size - 1] = 0; - return dest; -} -// String N w/null Copy Truncated? -// return value =true if entire string(source) fit, false if it was truncated -bool strn0cpyt(char* dest, const char* source, uint32 size) { - if (!dest) - return 0; - if (size == 0 || source == 0) { - dest[0] = 0; - return false; - } - strncpy(dest, source, size); - dest[size - 1] = 0; - return (bool) (source[strlen(dest)] == 0); -} - -const char *MakeUpperString(const char *source) { - static char str[128]; - if (!source) - return nullptr; - MakeUpperString(source, str); - return str; -} - -void MakeUpperString(const char *source, char *target) { - if (!source || !target) { - *target=0; - return; - } - while (*source) - { - *target = toupper(*source); - target++;source++; - } - *target = 0; -} - -const char *MakeLowerString(const char *source) { - static char str[128]; - if (!source) - return nullptr; - MakeLowerString(source, str); - return str; -} - -void MakeLowerString(const char *source, char *target) { - if (!source || !target) { - *target=0; - return; - } - while (*source) - { - *target = tolower(*source); - target++;source++; - } - *target = 0; -} - -int MakeAnyLenString(char** ret, const char* format, ...) { - int buf_len = 128; - int chars = -1; - va_list argptr, tmpargptr; - va_start(argptr, format); - while (chars == -1 || chars >= buf_len) { - safe_delete_array(*ret); - if (chars == -1) - buf_len *= 2; - else - buf_len = chars + 1; - *ret = new char[buf_len]; - va_copy(tmpargptr, argptr); - chars = vsnprintf(*ret, buf_len, format, tmpargptr); - } - va_end(argptr); - return chars; -} - -uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const char* format, ...) { - if (*bufsize == 0) - *bufsize = 256; - if (*ret == 0) - *strlen = 0; - int chars = -1; - char* oldret = 0; - va_list argptr, tmpargptr; - va_start(argptr, format); - while (chars == -1 || chars >= (int32)(*bufsize-*strlen)) { - if (chars == -1) - *bufsize += 256; - else - *bufsize += chars + 25; - oldret = *ret; - *ret = new char[*bufsize]; - if (oldret) { - if (*strlen) - memcpy(*ret, oldret, *strlen); - safe_delete_array(oldret); - } - va_copy(tmpargptr, argptr); - chars = vsnprintf(&(*ret)[*strlen], (*bufsize-*strlen), format, tmpargptr); - } - va_end(argptr); - *strlen += chars; - return *strlen; -} - -uint32 hextoi(char* num) { - int len = strlen(num); - if (len < 3) - return 0; - - if (num[0] != '0' || (num[1] != 'x' && num[1] != 'X')) - return 0; - - uint32 ret = 0; - int mul = 1; - for (int i=len-1; i>=2; i--) { - if (num[i] >= 'A' && num[i] <= 'F') - ret += ((num[i] - 'A') + 10) * mul; - else if (num[i] >= 'a' && num[i] <= 'f') - ret += ((num[i] - 'a') + 10) * mul; - else if (num[i] >= '0' && num[i] <= '9') - ret += (num[i] - '0') * mul; - else - return 0; - mul *= 16; - } - return ret; -} - -uint64 hextoi64(char* num) { - int len = strlen(num); - if (len < 3) - return 0; - - if (num[0] != '0' || (num[1] != 'x' && num[1] != 'X')) - return 0; - - uint64 ret = 0; - int mul = 1; - for (int i=len-1; i>=2; i--) { - if (num[i] >= 'A' && num[i] <= 'F') - ret += ((num[i] - 'A') + 10) * mul; - else if (num[i] >= 'a' && num[i] <= 'f') - ret += ((num[i] - 'a') + 10) * mul; - else if (num[i] >= '0' && num[i] <= '9') - ret += (num[i] - '0') * mul; - else - return 0; - mul *= 16; - } - return ret; -} - -bool atobool(char* iBool) { - if (!strcasecmp(iBool, "true")) - return true; - if (!strcasecmp(iBool, "false")) - return false; - if (!strcasecmp(iBool, "yes")) - return true; - if (!strcasecmp(iBool, "no")) - return false; - if (!strcasecmp(iBool, "on")) - return true; - if (!strcasecmp(iBool, "off")) - return false; - if (!strcasecmp(iBool, "enable")) - return true; - if (!strcasecmp(iBool, "disable")) - return false; - if (!strcasecmp(iBool, "enabled")) - return true; - if (!strcasecmp(iBool, "disabled")) - return false; - if (!strcasecmp(iBool, "y")) - return true; - if (!strcasecmp(iBool, "n")) - return false; - if (atoi(iBool)) - return true; - return false; -} int32 filesize(FILE* fp) { #ifdef _WINDOWS @@ -546,28 +352,6 @@ static unsigned int case_6 (void){ // end WELL RNG code -// solar: removes the crap and turns the underscores into spaces. -char *CleanMobName(const char *in, char *out) -{ - unsigned i, j; - - for(i = j = 0; i < strlen(in); i++) - { - // convert _ to space.. any other conversions like this? I *think* this - // is the only non alpha char that's not stripped but converted. - if(in[i] == '_') - { - out[j++] = ' '; - } - else - { - if(isalpha(in[i]) || (in[i] == '`')) // numbers, #, or any other crap just gets skipped - out[j++] = in[i]; - } - } - out[j] = 0; // terimnate the string before returning it - return out; -} const char *ConvertArray(int input, char *returnchar) { @@ -625,23 +409,3 @@ float EQHtoFloat(int d) return(360.0f - float((d * 360) >> 11)); } -void RemoveApostrophes(std::string &s) -{ - for(unsigned int i = 0; i < s.length(); ++i) - if(s[i] == '\'') - s[i] = '_'; -} - -char *RemoveApostrophes(const char *s) -{ - char *NewString = new char[strlen(s) + 1]; - - strcpy(NewString, s); - - for(unsigned int i = 0 ; i < strlen(NewString); ++i) - if(NewString[i] == '\'') - NewString[i] = '_'; - - return NewString; -} - diff --git a/common/MiscFunctions.h b/common/MiscFunctions.h index 2ed8a8954..cebc04d32 100644 --- a/common/MiscFunctions.h +++ b/common/MiscFunctions.h @@ -86,37 +86,16 @@ #define BITMASK 0x41180000 -////////////////////////////////////////////////////////////////////// -// -// MakeUpperString -// i : source - allocated null-terminated string -// return: pointer to static buffer with the target string -const char *MakeUpperString(const char *source); -const char *MakeLowerString(const char *source); -////////////////////////////////////////////////////////////////////// -// -// MakeUpperString -// i : source - allocated null-terminated string -// io: target - allocated buffer, at least of size strlen(source)+1 -void MakeUpperString(const char *source, char *target); -void MakeLowerString(const char *source, char *target); -int MakeAnyLenString(char** ret, const char* format, ...); -uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const char* format, ...); -uint32 hextoi(char* num); -uint64 hextoi64(char* num); -bool atobool(char* iBool); int32 filesize(FILE* fp); uint32 ResolveIP(const char* hostname, char* errbuf = 0); bool ParseAddress(const char* iAddress, uint32* oIP, uint16* oPort, char* errbuf = 0); void CoutTimestamp(bool ms = true); -char* strn0cpy(char* dest, const char* source, uint32 size); - // return value =true if entire string(source) fit, false if it was truncated -bool strn0cpyt(char* dest, const char* source, uint32 size); + int MakeRandomInt(int low, int high); double MakeRandomFloat(double low, double high); -char *CleanMobName(const char *in, char *out); + const char *ConvertArray(int input, char *returnchar); const char *ConvertArrayF(float input, char *returnchar); float EQ13toFloat(int d); @@ -127,8 +106,7 @@ int FloatToEQ13(float d); int NewFloatToEQ13(float d); int FloatToEQ19(float d); int FloatToEQH(float d); -void RemoveApostrophes(std::string &s); -char *RemoveApostrophes(const char *s); + diff --git a/common/StringUtil.cpp b/common/StringUtil.cpp index 2371d5148..bfe923487 100644 --- a/common/StringUtil.cpp +++ b/common/StringUtil.cpp @@ -16,6 +16,7 @@ #include "StringUtil.h" #include +#include // for strncpy #include #include @@ -79,3 +80,243 @@ void StringFormat(std::string& output, const char* format, ...) output.resize(write_point + bytes_used); } } + +// normal strncpy doesnt put a null term on copied strings, this one does +// ref: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecrt/htm/_wcecrt_strncpy_wcsncpy.asp +char* strn0cpy(char* dest, const char* source, uint32 size) { + if (!dest) + return 0; + if (size == 0 || source == 0) { + dest[0] = 0; + return dest; + } + strncpy(dest, source, size); + dest[size - 1] = 0; + return dest; +} + +// String N w/null Copy Truncated? +// return value =true if entire string(source) fit, false if it was truncated +bool strn0cpyt(char* dest, const char* source, uint32 size) { + if (!dest) + return 0; + if (size == 0 || source == 0) { + dest[0] = 0; + return false; + } + strncpy(dest, source, size); + dest[size - 1] = 0; + return (bool) (source[strlen(dest)] == 0); +} + +const char *MakeUpperString(const char *source) { + static char str[128]; + if (!source) + return nullptr; + MakeUpperString(source, str); + return str; +} + +void MakeUpperString(const char *source, char *target) { + if (!source || !target) { + *target=0; + return; + } + while (*source) + { + *target = toupper(*source); + target++;source++; + } + *target = 0; +} + +const char *MakeLowerString(const char *source) { + static char str[128]; + if (!source) + return nullptr; + MakeLowerString(source, str); + return str; +} + +void MakeLowerString(const char *source, char *target) { + if (!source || !target) { + *target=0; + return; + } + while (*source) + { + *target = tolower(*source); + target++;source++; + } + *target = 0; +} + +int MakeAnyLenString(char** ret, const char* format, ...) { + int buf_len = 128; + int chars = -1; + va_list argptr, tmpargptr; + va_start(argptr, format); + while (chars == -1 || chars >= buf_len) { + safe_delete_array(*ret); + if (chars == -1) + buf_len *= 2; + else + buf_len = chars + 1; + *ret = new char[buf_len]; + va_copy(tmpargptr, argptr); + chars = vsnprintf(*ret, buf_len, format, tmpargptr); + } + va_end(argptr); + return chars; +} + +uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const char* format, ...) { + if (*bufsize == 0) + *bufsize = 256; + if (*ret == 0) + *strlen = 0; + int chars = -1; + char* oldret = 0; + va_list argptr, tmpargptr; + va_start(argptr, format); + while (chars == -1 || chars >= (int32)(*bufsize-*strlen)) { + if (chars == -1) + *bufsize += 256; + else + *bufsize += chars + 25; + oldret = *ret; + *ret = new char[*bufsize]; + if (oldret) { + if (*strlen) + memcpy(*ret, oldret, *strlen); + safe_delete_array(oldret); + } + va_copy(tmpargptr, argptr); + chars = vsnprintf(&(*ret)[*strlen], (*bufsize-*strlen), format, tmpargptr); + } + va_end(argptr); + *strlen += chars; + return *strlen; +} + +uint32 hextoi(char* num) { + int len = strlen(num); + if (len < 3) + return 0; + + if (num[0] != '0' || (num[1] != 'x' && num[1] != 'X')) + return 0; + + uint32 ret = 0; + int mul = 1; + for (int i=len-1; i>=2; i--) { + if (num[i] >= 'A' && num[i] <= 'F') + ret += ((num[i] - 'A') + 10) * mul; + else if (num[i] >= 'a' && num[i] <= 'f') + ret += ((num[i] - 'a') + 10) * mul; + else if (num[i] >= '0' && num[i] <= '9') + ret += (num[i] - '0') * mul; + else + return 0; + mul *= 16; + } + return ret; +} + +uint64 hextoi64(char* num) { + int len = strlen(num); + if (len < 3) + return 0; + + if (num[0] != '0' || (num[1] != 'x' && num[1] != 'X')) + return 0; + + uint64 ret = 0; + int mul = 1; + for (int i=len-1; i>=2; i--) { + if (num[i] >= 'A' && num[i] <= 'F') + ret += ((num[i] - 'A') + 10) * mul; + else if (num[i] >= 'a' && num[i] <= 'f') + ret += ((num[i] - 'a') + 10) * mul; + else if (num[i] >= '0' && num[i] <= '9') + ret += (num[i] - '0') * mul; + else + return 0; + mul *= 16; + } + return ret; +} + +bool atobool(char* iBool) { + if (!strcasecmp(iBool, "true")) + return true; + if (!strcasecmp(iBool, "false")) + return false; + if (!strcasecmp(iBool, "yes")) + return true; + if (!strcasecmp(iBool, "no")) + return false; + if (!strcasecmp(iBool, "on")) + return true; + if (!strcasecmp(iBool, "off")) + return false; + if (!strcasecmp(iBool, "enable")) + return true; + if (!strcasecmp(iBool, "disable")) + return false; + if (!strcasecmp(iBool, "enabled")) + return true; + if (!strcasecmp(iBool, "disabled")) + return false; + if (!strcasecmp(iBool, "y")) + return true; + if (!strcasecmp(iBool, "n")) + return false; + if (atoi(iBool)) + return true; + return false; +} + +// solar: removes the crap and turns the underscores into spaces. +char *CleanMobName(const char *in, char *out) +{ + unsigned i, j; + + for(i = j = 0; i < strlen(in); i++) + { + // convert _ to space.. any other conversions like this? I *think* this + // is the only non alpha char that's not stripped but converted. + if(in[i] == '_') + { + out[j++] = ' '; + } + else + { + if(isalpha(in[i]) || (in[i] == '`')) // numbers, #, or any other crap just gets skipped + out[j++] = in[i]; + } + } + out[j] = 0; // terimnate the string before returning it + return out; +} + + +void RemoveApostrophes(std::string &s) +{ + for(unsigned int i = 0; i < s.length(); ++i) + if(s[i] == '\'') + s[i] = '_'; +} + +char *RemoveApostrophes(const char *s) +{ + char *NewString = new char[strlen(s) + 1]; + + strcpy(NewString, s); + + for(unsigned int i = 0 ; i < strlen(NewString); ++i) + if(NewString[i] == '\'') + NewString[i] = '_'; + + return NewString; +} diff --git a/common/StringUtil.h b/common/StringUtil.h index 226aa82f2..ef757e24f 100644 --- a/common/StringUtil.h +++ b/common/StringUtil.h @@ -17,7 +17,39 @@ #define _STRINGUTIL_H_ #include +#include "types.h" void StringFormat(std::string& output, const char* format, ...); +////////////////////////////////////////////////////////////////////// +// +// MakeUpperString +// i : source - allocated null-terminated string +// return: pointer to static buffer with the target string +const char *MakeUpperString(const char *source); +const char *MakeLowerString(const char *source); +////////////////////////////////////////////////////////////////////// +// +// MakeUpperString +// i : source - allocated null-terminated string +// io: target - allocated buffer, at least of size strlen(source)+1 +void MakeUpperString(const char *source, char *target); +void MakeLowerString(const char *source, char *target); + + +int MakeAnyLenString(char** ret, const char* format, ...); +uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const char* format, ...); + +uint32 hextoi(char* num); +uint64 hextoi64(char* num); +bool atobool(char* iBool); + +char* strn0cpy(char* dest, const char* source, uint32 size); + // return value =true if entire string(source) fit, false if it was truncated +bool strn0cpyt(char* dest, const char* source, uint32 size); + +char *CleanMobName(const char *in, char *out); + +void RemoveApostrophes(std::string &s); +char *RemoveApostrophes(const char *s); #endif diff --git a/common/database.cpp b/common/database.cpp index 8960a58e0..e47abe887 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -44,7 +44,8 @@ using namespace std; #include "database.h" #include "eq_packet_structs.h" #include "guilds.h" -#include "MiscFunctions.h" +//#include "MiscFunctions.h" +#include "StringUtil.h" #include "extprofile.h" extern Client client; diff --git a/common/dbasync.cpp b/common/dbasync.cpp index 31e956180..773090436 100644 --- a/common/dbasync.cpp +++ b/common/dbasync.cpp @@ -14,7 +14,8 @@ using namespace std; #include "dbcore.h" #include "common_profile.h" #include -#include "../common/MiscFunctions.h" +//#include "../common/MiscFunctions.h" +#include "StringUtil.h" #define ASYNC_LOOP_GRANULARITY 4 //# of ms between checking our work bool DBAsyncCB_LoadVariables(DBAsyncWork* iWork) { diff --git a/common/debug.cpp b/common/debug.cpp index fabe0ce17..92e17bf24 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -16,6 +16,8 @@ #include #include #endif + +#include "../common/StringUtil.h" #include "../common/MiscFunctions.h" #include "../common/platform.h" @@ -155,39 +157,49 @@ bool EQEMuLog::write(LogIDs id, const char *fmt, ...) { va_list argptr, tmpargptr; va_start(argptr, fmt); + if (dofile) { va_copy(tmpargptr, argptr); vfprintf( fp[id], fmt, tmpargptr ); } + if(logCallbackFmt[id]) { msgCallbackFmt p = logCallbackFmt[id]; va_copy(tmpargptr, argptr); p(id, fmt, tmpargptr ); } + + std::string outputMessage; + StringFormat(outputMessage, fmt, argptr); + if (pLogStatus[id] & 2) { if (pLogStatus[id] & 8) { - fprintf(stderr, "[%s] ", LogNames[id]); - vfprintf( stderr, fmt, argptr ); + + std::cerr << "[" << LogNames[id] << "] "; + std::cerr << outputMessage; } else { - fprintf(stdout, "[%s] ", LogNames[id]); - vfprintf( stdout, fmt, argptr ); + std::cout << "[" << LogNames[id] << "] "; + std::cout << outputMessage; } } + va_end(argptr); + if (dofile) fprintf(fp[id], "\n"); + if (pLogStatus[id] & 2) { if (pLogStatus[id] & 8) { - fprintf(stderr, "\n"); - fflush(stderr); + std::cerr << std::endl; } else { - fprintf(stdout, "\n"); - fflush(stdout); + std::cout << std::endl; } } + if(dofile) fflush(fp[id]); + return true; } diff --git a/common/guild_base.cpp b/common/guild_base.cpp index 7a97adeba..23c6df9ab 100644 --- a/common/guild_base.cpp +++ b/common/guild_base.cpp @@ -20,7 +20,8 @@ #include "guild_base.h" #include "database.h" #include "logsys.h" -#include "MiscFunctions.h" +//#include "MiscFunctions.h" +#include "StringUtil.h" #include #include diff --git a/common/md5.cpp b/common/md5.cpp index f44b590bb..a357ea3c0 100644 --- a/common/md5.cpp +++ b/common/md5.cpp @@ -9,7 +9,7 @@ */ #include /* for memcpy() */ #include "../common/md5.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/seperator.h" MD5::MD5() { diff --git a/common/patches/Client62.cpp b/common/patches/Client62.cpp index 1a535a7f0..f503a57fe 100644 --- a/common/patches/Client62.cpp +++ b/common/patches/Client62.cpp @@ -8,6 +8,7 @@ #include "../eq_packet_structs.h" #include "../MiscFunctions.h" +#include "../StringUtil.h" #include "../Item.h" #include "../clientversions.h" #include "Client62_structs.h" diff --git a/common/patches/RoF.cpp b/common/patches/RoF.cpp index f9bd001b3..9dc1cf1b5 100644 --- a/common/patches/RoF.cpp +++ b/common/patches/RoF.cpp @@ -8,6 +8,7 @@ #include "../eq_packet_structs.h" #include "../MiscFunctions.h" +#include "../StringUtil.h" #include "../Item.h" #include "RoF_structs.h" #include "../rulesys.h" diff --git a/common/patches/SoD.cpp b/common/patches/SoD.cpp index cfbfba2ef..334e2f1cb 100644 --- a/common/patches/SoD.cpp +++ b/common/patches/SoD.cpp @@ -8,6 +8,7 @@ #include "../eq_packet_structs.h" #include "../MiscFunctions.h" +#include "../StringUtil.h" #include "../Item.h" #include "SoD_structs.h" #include "../rulesys.h" diff --git a/common/patches/SoF.cpp b/common/patches/SoF.cpp index 823f62d11..39a12352f 100644 --- a/common/patches/SoF.cpp +++ b/common/patches/SoF.cpp @@ -7,7 +7,7 @@ #include "../crc32.h" #include "../eq_packet_structs.h" -#include "../MiscFunctions.h" +#include "../StringUtil.h" #include "../Item.h" #include "SoF_structs.h" #include "../rulesys.h" diff --git a/common/patches/Titanium.cpp b/common/patches/Titanium.cpp index bfc88040d..d3ec53da8 100644 --- a/common/patches/Titanium.cpp +++ b/common/patches/Titanium.cpp @@ -8,7 +8,7 @@ #include "../races.h" #include "../eq_packet_structs.h" -#include "../MiscFunctions.h" +#include "../StringUtil.h" #include "../Item.h" #include "Titanium_structs.h" #include diff --git a/common/patches/Underfoot.cpp b/common/patches/Underfoot.cpp index f84eec93a..ee0a2b3e5 100644 --- a/common/patches/Underfoot.cpp +++ b/common/patches/Underfoot.cpp @@ -8,6 +8,7 @@ #include "../eq_packet_structs.h" #include "../MiscFunctions.h" +#include "../StringUtil.h" #include "../Item.h" #include "Underfoot_structs.h" #include "../rulesys.h" diff --git a/common/ptimer.cpp b/common/ptimer.cpp index 85acf6e6b..607c32b8a 100644 --- a/common/ptimer.cpp +++ b/common/ptimer.cpp @@ -20,7 +20,7 @@ #include "timer.h" #include "ptimer.h" #include "database.h" -#include "MiscFunctions.h" +#include "StringUtil.h" #include #include #include diff --git a/common/rulesys.cpp b/common/rulesys.cpp index a6ec1a708..c097175ef 100644 --- a/common/rulesys.cpp +++ b/common/rulesys.cpp @@ -19,7 +19,7 @@ #include "rulesys.h" #include "logsys.h" #include "database.h" -#include "MiscFunctions.h" +#include "StringUtil.h" #include #include diff --git a/common/shareddb.cpp b/common/shareddb.cpp index 6fc251374..2562c7ab4 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -7,7 +7,7 @@ #include "classes.h" #include "rulesys.h" #include "seperator.h" -#include "MiscFunctions.h" +#include "StringUtil.h" #include "eq_packet_structs.h" #include "guilds.h" #include "extprofile.h" diff --git a/eqlaunch/worldserver.cpp b/eqlaunch/worldserver.cpp index 1f314bd8f..f3adcd832 100644 --- a/eqlaunch/worldserver.cpp +++ b/eqlaunch/worldserver.cpp @@ -20,6 +20,7 @@ #include "../common/servertalk.h" #include "ZoneLaunch.h" #include "../common/EQEmuConfig.h" +#include "../common/StringUtil.h" WorldServer::WorldServer(map &zones, const char *name, const EQEmuConfig *config) diff --git a/queryserv/database.cpp b/queryserv/database.cpp index 4e5f5a95c..5fbd8c92b 100644 --- a/queryserv/database.cpp +++ b/queryserv/database.cpp @@ -46,7 +46,7 @@ using namespace std; #include "database.h" #include "../common/eq_packet_structs.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/servertalk.h" Database::Database () diff --git a/queryserv/lfguild.cpp b/queryserv/lfguild.cpp index af44817a9..88e059c6c 100644 --- a/queryserv/lfguild.cpp +++ b/queryserv/lfguild.cpp @@ -2,7 +2,7 @@ #include "lfguild.h" #include "database.h" #include "worldserver.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/packet_dump.h" #include "../common/rulesys.h" diff --git a/ucs/chatchannel.cpp b/ucs/chatchannel.cpp index 6167c7e05..3e4642600 100644 --- a/ucs/chatchannel.cpp +++ b/ucs/chatchannel.cpp @@ -22,7 +22,7 @@ #include "chatchannel.h" #include "clientlist.h" #include "database.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include extern Database database; diff --git a/ucs/clientlist.cpp b/ucs/clientlist.cpp index 9a857c3cd..71948c0ca 100644 --- a/ucs/clientlist.cpp +++ b/ucs/clientlist.cpp @@ -20,7 +20,7 @@ */ #include "../common/debug.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "clientlist.h" #include "database.h" diff --git a/ucs/database.cpp b/ucs/database.cpp index e03339b0b..275aa07cc 100644 --- a/ucs/database.cpp +++ b/ucs/database.cpp @@ -47,6 +47,7 @@ using namespace std; #include "database.h" #include "../common/eq_packet_structs.h" #include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "chatchannel.h" extern Clientlist *CL; diff --git a/world/Adventure.cpp b/world/Adventure.cpp index 98a480073..d501ec796 100644 --- a/world/Adventure.cpp +++ b/world/Adventure.cpp @@ -3,6 +3,7 @@ #include "../common/extprofile.h" #include "../common/rulesys.h" #include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "Adventure.h" #include "AdventureManager.h" #include "worlddb.h" @@ -435,4 +436,4 @@ void Adventure::MoveCorpsesToGraveyard() iter++; c_iter++; } -} \ No newline at end of file +} diff --git a/world/AdventureManager.cpp b/world/AdventureManager.cpp index d6e03ee0e..3782b2e31 100644 --- a/world/AdventureManager.cpp +++ b/world/AdventureManager.cpp @@ -1,5 +1,6 @@ #include "../common/debug.h" #include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/servertalk.h" #include "../common/rulesys.h" #include "Adventure.h" diff --git a/world/EQLConfig.cpp b/world/EQLConfig.cpp index fe88008d6..4dd6b2680 100644 --- a/world/EQLConfig.cpp +++ b/world/EQLConfig.cpp @@ -20,7 +20,7 @@ #include "worlddb.h" #include "LauncherLink.h" #include "LauncherList.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include #include diff --git a/world/EQW.cpp b/world/EQW.cpp index cdf264310..49b2ee341 100644 --- a/world/EQW.cpp +++ b/world/EQW.cpp @@ -25,7 +25,7 @@ #include "../common/races.h" #include "../common/classes.h" #include "../common/misc.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "zoneserver.h" #include "zonelist.h" #include "clientlist.h" diff --git a/world/LauncherLink.cpp b/world/LauncherLink.cpp index 186124929..636c4eda7 100644 --- a/world/LauncherLink.cpp +++ b/world/LauncherLink.cpp @@ -25,6 +25,7 @@ #include "../common/packet_dump.h" #include "../common/servertalk.h" #include "../common/EmuTCPConnection.h" +#include "../common/StringUtil.h" #include "worlddb.h" #include "EQLConfig.h" diff --git a/world/LoginServer.cpp b/world/LoginServer.cpp index 00855edb8..dadf952d5 100644 --- a/world/LoginServer.cpp +++ b/world/LoginServer.cpp @@ -58,7 +58,7 @@ using namespace std; #include "LoginServerList.h" #include "../common/eq_packet_structs.h" #include "../common/packet_dump.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "zoneserver.h" #include "worlddb.h" #include "zonelist.h" diff --git a/world/client.cpp b/world/client.cpp index 3b162c6d9..9db2e8c01 100644 --- a/world/client.cpp +++ b/world/client.cpp @@ -45,7 +45,7 @@ using namespace std; #include "../common/languages.h" #include "../common/skills.h" #include "../common/extprofile.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "WorldConfig.h" #include "LoginServer.h" #include "LoginServerList.h" diff --git a/world/cliententry.cpp b/world/cliententry.cpp index 0ea413cc1..0e95e31b7 100644 --- a/world/cliententry.cpp +++ b/world/cliententry.cpp @@ -24,6 +24,7 @@ #include "zoneserver.h" #include "WorldConfig.h" #include "../common/guilds.h" +#include "../common/StringUtil.h" extern uint32 numplayers; extern LoginServerList loginserverlist; diff --git a/world/clientlist.cpp b/world/clientlist.cpp index 986f763e7..03d06b4f0 100644 --- a/world/clientlist.cpp +++ b/world/clientlist.cpp @@ -22,6 +22,7 @@ #include "client.h" #include "console.h" #include "worlddb.h" +#include "../common/StringUtil.h" #include "../common/guilds.h" #include "../common/races.h" #include "../common/classes.h" diff --git a/world/console.cpp b/world/console.cpp index e84fb8c68..2ce8131a1 100644 --- a/world/console.cpp +++ b/world/console.cpp @@ -39,6 +39,7 @@ using namespace std; #include "../common/opcodemgr.h" #include "../common/rulesys.h" #include "../common/ruletypes.h" +#include "../common/StringUtil.h" #include "WorldConfig.h" #include "zoneserver.h" #include "zonelist.h" diff --git a/world/worlddb.cpp b/world/worlddb.cpp index 7f98746e2..fced87256 100644 --- a/world/worlddb.cpp +++ b/world/worlddb.cpp @@ -18,7 +18,7 @@ #include "worlddb.h" //#include "../common/Item.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/eq_packet_structs.h" #include "../common/Item.h" #include "../common/dbasync.h" diff --git a/world/zonelist.cpp b/world/zonelist.cpp index f8ffe4578..b05c9c5ec 100644 --- a/world/zonelist.cpp +++ b/world/zonelist.cpp @@ -23,7 +23,7 @@ #include "console.h" #include "WorldConfig.h" #include "../common/servertalk.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" extern uint32 numzones; extern bool holdzones; diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index 9be2c410d..b1bbebbf3 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -29,7 +29,7 @@ #include "../common/guilds.h" #include "../common/packet_dump.h" #include "../common/misc.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "cliententry.h" #include "wguild_mgr.h" #include "lfplist.h" diff --git a/zone/AA.cpp b/zone/AA.cpp index cb1c90f92..cc0696ade 100644 --- a/zone/AA.cpp +++ b/zone/AA.cpp @@ -34,7 +34,7 @@ Copyright (C) 2001-2004 EQEMu Development Team (http://eqemulator.net) #include "../common/classes.h" #include "../common/eq_packet_structs.h" #include "../common/packet_dump.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/logsys.h" #include "zonedb.h" #include "StringIDs.h" diff --git a/zone/MobAI.cpp b/zone/MobAI.cpp index 5aaf7e04d..83aa82ba7 100644 --- a/zone/MobAI.cpp +++ b/zone/MobAI.cpp @@ -30,7 +30,7 @@ using namespace std; #include "../common/moremath.h" #include "parser.h" #include "StringIDs.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "../common/features.h" #include "QuestParserCollection.h" diff --git a/zone/Object.cpp b/zone/Object.cpp index 77b01b7cd..891f7a2ee 100644 --- a/zone/Object.cpp +++ b/zone/Object.cpp @@ -24,7 +24,7 @@ #include "zonedb.h" #include "../common/packet_functions.h" #include "../common/packet_dump.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/features.h" #include "StringIDs.h" using namespace std; diff --git a/zone/PlayerCorpse.cpp b/zone/PlayerCorpse.cpp index 79a44e2fe..3c7ea2d91 100644 --- a/zone/PlayerCorpse.cpp +++ b/zone/PlayerCorpse.cpp @@ -35,6 +35,7 @@ using namespace std; #include "masterentity.h" #include "../common/packet_functions.h" +#include "../common/StringUtil.h" #include "../common/crc32.h" #include "StringIDs.h" #include "worldserver.h" diff --git a/zone/QGlobals.cpp b/zone/QGlobals.cpp index 67bba76f0..54a081cc5 100644 --- a/zone/QGlobals.cpp +++ b/zone/QGlobals.cpp @@ -1,5 +1,5 @@ #include "../common/debug.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "QGlobals.h" #include "zonedb.h" diff --git a/zone/attack.cpp b/zone/attack.cpp index 170ed0fe7..a3693b4eb 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -38,7 +38,7 @@ using namespace std; #include "../common/spdat.h" #include "zone.h" #include "StringIDs.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "QuestParserCollection.h" #include "watermap.h" diff --git a/zone/bot.cpp b/zone/bot.cpp index 47f974444..2f2cdf0bd 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -4,6 +4,7 @@ #include "object.h" #include "doors.h" #include "QuestParserCollection.h" +#include "../common/StringUtil.h" extern volatile bool ZoneLoaded; diff --git a/zone/botspellsai.cpp b/zone/botspellsai.cpp index 5bae0b60b..47e704888 100644 --- a/zone/botspellsai.cpp +++ b/zone/botspellsai.cpp @@ -1,6 +1,7 @@ #ifdef BOTS #include "bot.h" +#include "../common/StringUtil.h" bool Bot::AICastSpell(Mob* tar, uint8 iChance, uint16 iSpellTypes) { _ZP(Bot_AICastSpell); diff --git a/zone/client.cpp b/zone/client.cpp index 6205b9ba6..c023e318d 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -58,7 +58,7 @@ extern volatile bool RunLoops; #include "../common/guilds.h" #include "../common/breakdowns.h" #include "../common/rulesys.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "forage.h" #include "command.h" #include "StringIDs.h" diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index df01534ac..e80b8aca8 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -45,7 +45,7 @@ #include "worldserver.h" #include "../common/rdtsc.h" #include "../common/packet_dump_file.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/breakdowns.h" #include "../common/guilds.h" #include "../common/rulesys.h" diff --git a/zone/client_process.cpp b/zone/client_process.cpp index b07060c9d..2e637c59d 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -47,7 +47,7 @@ #include "../common/packet_dump.h" #include "worldserver.h" #include "../common/packet_dump_file.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/spdat.h" #include "petitions.h" #include "NpcAI.h" diff --git a/zone/command.cpp b/zone/command.cpp index 276caf8da..4759ec3dc 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -50,7 +50,7 @@ #include "../common/EQPacket.h" #include "../common/guilds.h" #include "../common/rulesys.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" //#include "../common/servertalk.h" // for oocmute and revoke #include "worldserver.h" #include "masterentity.h" diff --git a/zone/doors.cpp b/zone/doors.cpp index 2c9b2fd7e..35cb01c41 100644 --- a/zone/doors.cpp +++ b/zone/doors.cpp @@ -26,7 +26,7 @@ using namespace std; #include "zonedb.h" #include "../common/packet_functions.h" #include "../common/packet_dump.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "guild_mgr.h" #define OPEN_DOOR 0x02 diff --git a/zone/embparser.cpp b/zone/embparser.cpp index d138aff93..cefe5bd5e 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -30,7 +30,7 @@ #include "questmgr.h" #include "command.h" #include "../common/seperator.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "QGlobals.h" #include "zone.h" diff --git a/zone/forage.cpp b/zone/forage.cpp index 175fb06c9..cf8de9219 100644 --- a/zone/forage.cpp +++ b/zone/forage.cpp @@ -32,7 +32,7 @@ using namespace std; #include "watermap.h" #include "titles.h" #include "StringIDs.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "zonedb.h" diff --git a/zone/groups.cpp b/zone/groups.cpp index 5d0168607..8b63bae0c 100644 --- a/zone/groups.cpp +++ b/zone/groups.cpp @@ -20,7 +20,7 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) #include "NpcAI.h" #include "../common/packet_functions.h" #include "../common/packet_dump.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "worldserver.h" extern EntityList entity_list; extern WorldServer worldserver; diff --git a/zone/guild.cpp b/zone/guild.cpp index f2238e0ca..83706340b 100644 --- a/zone/guild.cpp +++ b/zone/guild.cpp @@ -28,7 +28,7 @@ #include "../common/ZoneNumbers.h" #include "../common/moremath.h" #include "../common/guilds.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "guild_mgr.h" #include "StringIDs.h" #include "NpcAI.h" diff --git a/zone/guild_mgr.cpp b/zone/guild_mgr.cpp index b040acdfc..3884bb736 100644 --- a/zone/guild_mgr.cpp +++ b/zone/guild_mgr.cpp @@ -20,6 +20,7 @@ #include "zonedb.h" #include "worldserver.h" #include "../common/servertalk.h" +#include "../common/StringUtil.h" #include "client.h" #include "entity.h" diff --git a/zone/horse.cpp b/zone/horse.cpp index 3ccf30525..dd0ac9bf2 100644 --- a/zone/horse.cpp +++ b/zone/horse.cpp @@ -22,7 +22,7 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) #include "masterentity.h" #include "../common/Item.h" #include "../common/linked_list.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include #include #include "worldserver.h" diff --git a/zone/inventory.cpp b/zone/inventory.cpp index cbf9503ba..b6d34b429 100644 --- a/zone/inventory.cpp +++ b/zone/inventory.cpp @@ -29,6 +29,7 @@ #include "../common/moremath.h" #include "../common/guilds.h" #include "../common/logsys.h" +#include "../common/StringUtil.h" #include "StringIDs.h" #include "NpcAI.h" extern WorldServer worldserver; diff --git a/zone/merc.cpp b/zone/merc.cpp index 6f7c8142f..582eb54a9 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -8,7 +8,7 @@ #include "../common/spdat.h" #include "zone.h" #include "StringIDs.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "QuestParserCollection.h" #include "watermap.h" diff --git a/zone/mob.cpp b/zone/mob.cpp index 6782a8826..5756cb078 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -21,6 +21,7 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) #include "StringIDs.h" #include "worldserver.h" #include "QuestParserCollection.h" +#include "../common/StringUtil.h" #include #include diff --git a/zone/npc.cpp b/zone/npc.cpp index afba99199..f5dd0a7c8 100644 --- a/zone/npc.cpp +++ b/zone/npc.cpp @@ -41,7 +41,7 @@ using namespace std; #include "../common/spdat.h" #include "../common/bodytypes.h" #include "spawngroup.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "StringIDs.h" diff --git a/zone/parser.cpp b/zone/parser.cpp index 4ff3a0f56..3af1a3c02 100644 --- a/zone/parser.cpp +++ b/zone/parser.cpp @@ -24,6 +24,7 @@ using namespace std; #include "zonedb.h" #include "../common/spdat.h" #include "../common/packet_functions.h" +#include "../common/StringUtil.h" #include "spawn2.h" #include "zone.h" #include "event_codes.h" diff --git a/zone/petitions.cpp b/zone/petitions.cpp index ef3a9f113..b96908a98 100644 --- a/zone/petitions.cpp +++ b/zone/petitions.cpp @@ -32,6 +32,7 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) #define strncasecmp _strnicmp #define strcasecmp _stricmp #endif +#include "../common/StringUtil.h" #include "../common/packet_functions.h" #include "../common/packet_dump.h" #include "../common/packet_dump_file.h" diff --git a/zone/pets.cpp b/zone/pets.cpp index f7b3fa357..b28e33632 100644 --- a/zone/pets.cpp +++ b/zone/pets.cpp @@ -26,7 +26,7 @@ Copyright (C) 2001-2004 EQEMu Development Team (http://eqemu.org) #include "../common/skills.h" #include "../common/bodytypes.h" #include "../common/classes.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "pets.h" #include #include diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index d29e99e87..c76b8c364 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -68,7 +68,7 @@ using namespace std; #include "zonedb.h" #include "../common/spdat.h" #include "../common/packet_functions.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "spawn2.h" #include "zone.h" #include "parser.h" diff --git a/zone/raids.cpp b/zone/raids.cpp index b1518701b..27bfa59ba 100644 --- a/zone/raids.cpp +++ b/zone/raids.cpp @@ -20,7 +20,7 @@ #include "NpcAI.h" #include "../common/packet_functions.h" #include "../common/packet_dump.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "worldserver.h" extern EntityList entity_list; extern WorldServer worldserver; diff --git a/zone/spawn2.cpp b/zone/spawn2.cpp index c0fa5a986..55bafd86e 100644 --- a/zone/spawn2.cpp +++ b/zone/spawn2.cpp @@ -16,6 +16,7 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "../common/debug.h" +#include "../common/StringUtil.h" #include #include "spawn2.h" #include "entity.h" diff --git a/zone/spawngroup.cpp b/zone/spawngroup.cpp index 4af61d9a1..b99bee767 100644 --- a/zone/spawngroup.cpp +++ b/zone/spawngroup.cpp @@ -25,6 +25,7 @@ using namespace std; #include "../common/types.h" #include "zonedb.h" #include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" extern EntityList entity_list; diff --git a/zone/spells.cpp b/zone/spells.cpp index af27d92fa..b589ba4eb 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -83,13 +83,15 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) #include "../common/bodytypes.h" #include "../common/classes.h" #include "../common/rulesys.h" +#include "../common/StringUtil.h" #include #include + #ifndef WIN32 -// #include -#include -#include "../common/unix.h" + #include + #include "../common/unix.h" #endif + #ifdef _GOTFRAGS #include "../common/packet_dump_file.h" #endif diff --git a/zone/tasks.cpp b/zone/tasks.cpp index 34b64c1db..10d7dcf0d 100644 --- a/zone/tasks.cpp +++ b/zone/tasks.cpp @@ -27,7 +27,7 @@ Copyright (C) 2001-2008 EQEMu Development Team (http://eqemulator.net) #define strcasecmp _stricmp #endif -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "masterentity.h" #include "../common/features.h" diff --git a/zone/titles.cpp b/zone/titles.cpp index e6a2e5f61..9695a7078 100644 --- a/zone/titles.cpp +++ b/zone/titles.cpp @@ -19,7 +19,7 @@ #include "../common/eq_packet_structs.h" #include "masterentity.h" #include "titles.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "worldserver.h" extern WorldServer worldserver; diff --git a/zone/tradeskills.cpp b/zone/tradeskills.cpp index 57e047ffb..6a2fb7693 100644 --- a/zone/tradeskills.cpp +++ b/zone/tradeskills.cpp @@ -30,7 +30,7 @@ #include "../common/packet_dump.h" #include "titles.h" #include "StringIDs.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "QuestParserCollection.h" diff --git a/zone/trading.cpp b/zone/trading.cpp index 363faff69..872f62a14 100644 --- a/zone/trading.cpp +++ b/zone/trading.cpp @@ -18,7 +18,7 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) #include "../common/debug.h" #include "masterentity.h" #include "StringIDs.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "QuestParserCollection.h" #include "worldserver.h" diff --git a/zone/trap.cpp b/zone/trap.cpp index 9a8a143cd..c6aa3e09b 100644 --- a/zone/trap.cpp +++ b/zone/trap.cpp @@ -20,7 +20,7 @@ #include "entity.h" #include "masterentity.h" #include "../common/spdat.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" /* diff --git a/zone/watermap.cpp b/zone/watermap.cpp index 8196c360d..36b6dc32e 100644 --- a/zone/watermap.cpp +++ b/zone/watermap.cpp @@ -23,7 +23,8 @@ #include #include "watermap.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" + #ifdef _WINDOWS #define snprintf _snprintf #endif diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index d2bdd9616..c2b34a1a2 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -31,7 +31,7 @@ using namespace std; #include "../common/moremath.h" #include "parser.h" #include "StringIDs.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "../common/features.h" #include "QuestParserCollection.h" diff --git a/zone/zone.cpp b/zone/zone.cpp index 146da03c6..2781ac88b 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -46,7 +46,7 @@ using namespace std; #include "../common/packet_dump_file.h" #include "../common/EQStreamFactory.h" #include "../common/EQStream.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "ZoneConfig.h" #include "../common/breakdowns.h" #include "map.h" diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 36e74c5f2..b7584696d 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1,7 +1,7 @@ #include "zonedb.h" #include "../common/Item.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/extprofile.h" #include "../common/guilds.h" #include "../common/rulesys.h" diff --git a/zone/zonedbasync.cpp b/zone/zonedbasync.cpp index 587f94240..09e879cad 100644 --- a/zone/zonedbasync.cpp +++ b/zone/zonedbasync.cpp @@ -3,7 +3,7 @@ using namespace std; #include "entity.h" #include "masterentity.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/breakdowns.h" #include diff --git a/zone/zoning.cpp b/zone/zoning.cpp index 84c3e4e3a..0a0e9acea 100644 --- a/zone/zoning.cpp +++ b/zone/zoning.cpp @@ -22,6 +22,7 @@ #include "masterentity.h" #include "../common/packet_dump.h" #include "../common/rulesys.h" +#include "../common/StringUtil.h" #include "StringIDs.h" #include "QuestParserCollection.h" From 9a139a7604caa188589e0f7f386a8a6fa28dd1bd Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sat, 11 May 2013 00:17:02 -0700 Subject: [PATCH 08/10] missed two string conversion functions. Moved them to StringUtil --- common/MiscFunctions.cpp | 12 ------------ common/MiscFunctions.h | 3 +-- common/StringUtil.cpp | 12 ++++++++++++ common/StringUtil.h | 3 +++ zone/exp.cpp | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/common/MiscFunctions.cpp b/common/MiscFunctions.cpp index 734a48fd5..d768da017 100644 --- a/common/MiscFunctions.cpp +++ b/common/MiscFunctions.cpp @@ -353,18 +353,6 @@ static unsigned int case_6 (void){ // end WELL RNG code -const char *ConvertArray(int input, char *returnchar) -{ - sprintf(returnchar, "%i" ,input); - return returnchar; -} - -const char *ConvertArrayF(float input, char *returnchar) -{ - sprintf(returnchar, "%0.2f", input); - return returnchar; -} - float EQ13toFloat(int d) { return ( float(d)/float(1<<2)); diff --git a/common/MiscFunctions.h b/common/MiscFunctions.h index cebc04d32..35207b95c 100644 --- a/common/MiscFunctions.h +++ b/common/MiscFunctions.h @@ -96,8 +96,7 @@ void CoutTimestamp(bool ms = true); int MakeRandomInt(int low, int high); double MakeRandomFloat(double low, double high); -const char *ConvertArray(int input, char *returnchar); -const char *ConvertArrayF(float input, char *returnchar); + float EQ13toFloat(int d); float NewEQ13toFloat(int d); float EQ19toFloat(int d); diff --git a/common/StringUtil.cpp b/common/StringUtil.cpp index bfe923487..530bf2f1d 100644 --- a/common/StringUtil.cpp +++ b/common/StringUtil.cpp @@ -320,3 +320,15 @@ char *RemoveApostrophes(const char *s) return NewString; } + +const char *ConvertArray(int input, char *returnchar) +{ + sprintf(returnchar, "%i" ,input); + return returnchar; +} + +const char *ConvertArrayF(float input, char *returnchar) +{ + sprintf(returnchar, "%0.2f", input); + return returnchar; +} diff --git a/common/StringUtil.h b/common/StringUtil.h index ef757e24f..b7e389e65 100644 --- a/common/StringUtil.h +++ b/common/StringUtil.h @@ -49,6 +49,9 @@ bool strn0cpyt(char* dest, const char* source, uint32 size); char *CleanMobName(const char *in, char *out); +const char *ConvertArray(int input, char *returnchar); +const char *ConvertArrayF(float input, char *returnchar); + void RemoveApostrophes(std::string &s); char *RemoveApostrophes(const char *s); diff --git a/zone/exp.cpp b/zone/exp.cpp index 2a9cdc6a0..97c19363e 100644 --- a/zone/exp.cpp +++ b/zone/exp.cpp @@ -19,7 +19,7 @@ #include "../common/features.h" #include "masterentity.h" #include "StringIDs.h" -#include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/rulesys.h" #include "QuestParserCollection.h" From b19755a31357719eeadd88e191ed3bd68e90234e Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sat, 11 May 2013 00:46:46 -0700 Subject: [PATCH 09/10] For windows compile, moved definve of va_copy --- common/MiscFunctions.cpp | 104 +++++++++++++++++++-------------------- common/StringUtil.cpp | 63 +++++++++++++----------- 2 files changed, 83 insertions(+), 84 deletions(-) diff --git a/common/MiscFunctions.cpp b/common/MiscFunctions.cpp index d768da017..eb1a3c7d0 100644 --- a/common/MiscFunctions.cpp +++ b/common/MiscFunctions.cpp @@ -1,19 +1,19 @@ /* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) + Copyright (C) 2001-2002 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 - the Free Software Foundation; version 2 of the License. + 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; version 2 of the License. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which are required to give you total support for your newly bought product; 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, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "../common/debug.h" #include "MiscFunctions.h" @@ -47,8 +47,8 @@ using namespace std; #include #include #ifdef FREEBSD //Timothy Whitman - January 7, 2003 - #include - #include + #include + #include #endif #include #include @@ -56,10 +56,6 @@ using namespace std; #include #endif -#ifndef va_copy - #define va_copy(d,s) ((d) = (s)) -#endif - static bool WELLRNG_init = false; static int state_i = 0; static unsigned int STATE[R]; @@ -80,8 +76,8 @@ void CoutTimestamp(bool ms) { time(&rawtime); gmt_t = gmtime(&rawtime); - struct timeval read_time; - gettimeofday(&read_time,0); + struct timeval read_time; + gettimeofday(&read_time,0); cout << (gmt_t->tm_year + 1900) << "/" << setw(2) << setfill('0') << (gmt_t->tm_mon + 1) << "/" << setw(2) << setfill('0') << gmt_t->tm_mday << " " << setw(2) << setfill('0') << gmt_t->tm_hour << ":" << setw(2) << setfill('0') << gmt_t->tm_min << ":" << setw(2) << setfill('0') << gmt_t->tm_sec; if (ms) @@ -117,7 +113,7 @@ uint32 ResolveIP(const char* hostname, char* errbuf) { snprintf(errbuf, ERRBUF_SIZE, "ResolveIP(): hostname == 0"); return 0; } - struct sockaddr_in server_sin; + struct sockaddr_in server_sin; #ifdef _WINDOWS PHOSTENT phostent = nullptr; #else @@ -197,7 +193,7 @@ int MakeRandomInt(int low, int high) return(low); //return (rand()%(high-low+1) + (low)); - if(!WELLRNG_init) { + if(!WELLRNG_init) { WELLRNG_init = true; oneseed( rnd_hash( time(nullptr), clock() ) ); WELLRNG19937 = case_1; @@ -215,7 +211,7 @@ double MakeRandomFloat(double low, double high) return(low); //return (rand() / (double)RAND_MAX * (high - low) + low); - if(!WELLRNG_init) { + if(!WELLRNG_init) { WELLRNG_init = true; oneseed( rnd_hash( time(nullptr), clock() ) ); WELLRNG19937 = case_1; @@ -225,41 +221,41 @@ double MakeRandomFloat(double low, double high) uint32 rnd_hash( time_t t, clock_t c ) { - // Get a uint32 from t and c - // Better than uint32(x) in case x is floating point in [0,1] - // Based on code by Lawrence Kirby (fred@genesis.demon.co.uk) - - static uint32 differ = 0; // guarantee time-based seeds will change - - uint32 h1 = 0; - unsigned char *p = (unsigned char *) &t; - for( size_t i = 0; i < sizeof(t); ++i ) - { - h1 *= 255 + 2U; - h1 += p[i]; - } - uint32 h2 = 0; - p = (unsigned char *) &c; - for( size_t j = 0; j < sizeof(c); ++j ) - { - h2 *= 255 + 2U; - h2 += p[j]; - } - return ( h1 + differ++ ) ^ h2; + // Get a uint32 from t and c + // Better than uint32(x) in case x is floating point in [0,1] + // Based on code by Lawrence Kirby (fred@genesis.demon.co.uk) + + static uint32 differ = 0; // guarantee time-based seeds will change + + uint32 h1 = 0; + unsigned char *p = (unsigned char *) &t; + for( size_t i = 0; i < sizeof(t); ++i ) + { + h1 *= 255 + 2U; + h1 += p[i]; + } + uint32 h2 = 0; + p = (unsigned char *) &c; + for( size_t j = 0; j < sizeof(c); ++j ) + { + h2 *= 255 + 2U; + h2 += p[j]; + } + return ( h1 + differ++ ) ^ h2; } void oneseed( const uint32 seed ) { - // Initialize generator state with seed - // See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier. - // In previous versions, most significant bits (MSBs) of the seed affect - // only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. - register int j = 0; - STATE[j] = seed & 0xffffffffUL; + // Initialize generator state with seed + // See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier. + // In previous versions, most significant bits (MSBs) of the seed affect + // only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. + register int j = 0; + STATE[j] = seed & 0xffffffffUL; for (j = 1; j < R; j++) - { - STATE[j] = ( 1812433253UL * ( STATE[j-1] ^ (STATE[j-1] >> 30) ) + j ) & 0xffffffffUL; - } + { + STATE[j] = ( 1812433253UL * ( STATE[j-1] ^ (STATE[j-1] >> 30) ) + j ) & 0xffffffffUL; + } } // WELL RNG code @@ -307,7 +303,7 @@ static unsigned int case_3 (void){ newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1); state_i--; if (state_i + M1 < R) - WELLRNG19937 = case_5; + WELLRNG19937 = case_5; return (STATE[state_i] ^ (newVM2Over & BITMASK)); } @@ -320,7 +316,7 @@ static unsigned int case_4 (void){ newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1); state_i--; if (state_i + M3 < R) - WELLRNG19937 = case_6; + WELLRNG19937 = case_6; return (STATE[state_i] ^ (newVM2 & BITMASK)); } @@ -333,7 +329,7 @@ static unsigned int case_5 (void){ newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1); state_i--; if (state_i + M2 < R) - WELLRNG19937 = case_4; + WELLRNG19937 = case_4; return (STATE[state_i] ^ (newVM2Over & BITMASK)); } @@ -346,7 +342,7 @@ static unsigned int case_6 (void){ newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1); state_i--; if (state_i == 1) - WELLRNG19937 = case_2; + WELLRNG19937 = case_2; return (STATE[state_i] ^ (newVM2 & BITMASK)); } diff --git a/common/StringUtil.cpp b/common/StringUtil.cpp index 530bf2f1d..bf4965965 100644 --- a/common/StringUtil.cpp +++ b/common/StringUtil.cpp @@ -30,6 +30,9 @@ #include #endif +#ifndef va_copy + #define va_copy(d,s) ((d) = (s)) +#endif // original source: // https://github.com/facebook/folly/blob/master/folly/String.cpp @@ -110,50 +113,50 @@ bool strn0cpyt(char* dest, const char* source, uint32 size) { } const char *MakeUpperString(const char *source) { - static char str[128]; - if (!source) - return nullptr; - MakeUpperString(source, str); - return str; + static char str[128]; + if (!source) + return nullptr; + MakeUpperString(source, str); + return str; } void MakeUpperString(const char *source, char *target) { - if (!source || !target) { + if (!source || !target) { *target=0; - return; - } - while (*source) - { - *target = toupper(*source); - target++;source++; - } - *target = 0; + return; + } + while (*source) + { + *target = toupper(*source); + target++;source++; + } + *target = 0; } const char *MakeLowerString(const char *source) { - static char str[128]; - if (!source) - return nullptr; - MakeLowerString(source, str); - return str; + static char str[128]; + if (!source) + return nullptr; + MakeLowerString(source, str); + return str; } void MakeLowerString(const char *source, char *target) { - if (!source || !target) { + if (!source || !target) { *target=0; - return; - } - while (*source) - { - *target = tolower(*source); - target++;source++; - } - *target = 0; + return; + } + while (*source) + { + *target = tolower(*source); + target++;source++; + } + *target = 0; } int MakeAnyLenString(char** ret, const char* format, ...) { int buf_len = 128; - int chars = -1; + int chars = -1; va_list argptr, tmpargptr; va_start(argptr, format); while (chars == -1 || chars >= buf_len) { @@ -175,7 +178,7 @@ uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const cha *bufsize = 256; if (*ret == 0) *strlen = 0; - int chars = -1; + int chars = -1; char* oldret = 0; va_list argptr, tmpargptr; va_start(argptr, format); From d41331d948e2ac512720b288482fd076be05feef Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 20 May 2013 17:51:08 -0700 Subject: [PATCH 10/10] Apparently the original implementation from facebook was incorrect. Fixed it, sadly this does mean we need to call vsnprintf twice. Once to find out the size involved, a second time to apply. --- common/StringUtil.cpp | 74 +++++++++++++++++++++++++------------------ common/StringUtil.h | 3 ++ common/debug.cpp | 29 +++++++++++------ 3 files changed, 66 insertions(+), 40 deletions(-) diff --git a/common/StringUtil.cpp b/common/StringUtil.cpp index bf4965965..b1269bf46 100644 --- a/common/StringUtil.cpp +++ b/common/StringUtil.cpp @@ -15,9 +15,10 @@ */ #include "StringUtil.h" + #include -#include // for strncpy #include +#include // for strncpy #include #ifdef _WINDOWS @@ -26,8 +27,10 @@ #define snprintf _snprintf #define strncasecmp _strnicmp #define strcasecmp _stricmp + #else #include + #include #endif #ifndef va_copy @@ -37,53 +40,64 @@ // original source: // https://github.com/facebook/folly/blob/master/folly/String.cpp // -void StringFormat(std::string& output, const char* format, ...) +void vStringFormat(std::string& output, const char* format, va_list args) { - va_list args; - // Tru to the space at the end of output for our output buffer. - // Find out write point then inflate its size temporarily to its - // capacity; we will later shrink it to the size needed to represent - // the formatted string. If this buffer isn't large enough, we do a - // resize and try again. + va_list tmpargs; - const auto write_point = output.size(); - auto remaining = output.capacity() - write_point; - output.resize(output.capacity()); + va_copy(tmpargs,args); + int characters_used = vsnprintf(nullptr, 0, format, tmpargs); + va_end(tmpargs); - va_start(args, format); - int bytes_used = vsnprintf(&output[write_point], remaining, format,args); - va_end(args); - if (bytes_used < 0) { - + if (characters_used < 0) { + // Looks like we have an invalid format string. + // error out. std::string errorMessage("Invalid format string; snprintf returned negative with format string: "); errorMessage.append(format); throw std::runtime_error(errorMessage); - } - else if ((unsigned int)bytes_used < remaining) { - // There was enough room, just shrink and return. - output.resize(write_point + bytes_used); + } + else if ((unsigned int)characters_used > output.capacity()) { + output.resize(characters_used+1); + va_copy(tmpargs,args); + characters_used = vsnprintf(&output[0], output.capacity(), format, tmpargs); + va_end(tmpargs); + + if (characters_used < 0) { + // We shouldn't have a format error by this point, but I can't imagine what error we + // could have by this point. Still, error out and report it. + std::string errorMessage("Invalid format string or unknown vsnprintf error; vsnprintf returned negative with format string: "); + errorMessage.append(format); + + throw std::runtime_error(errorMessage); + } } else { - output.resize(write_point + bytes_used + 1); - remaining = bytes_used + 1; + output.resize(characters_used + 1); - va_start(args, format); - bytes_used = vsnprintf(&output[write_point], remaining, format, args); - va_end(args); - - if ((unsigned int)(bytes_used + 1) != remaining) { - - std::string errorMessage("vsnprint retry did not manage to work with format string: "); + va_copy(tmpargs,args); + characters_used = vsnprintf(&output[0], output.capacity(), format, tmpargs); + va_end(tmpargs); + + if (characters_used < 0) { + // We shouldn't have a format error by this point, but I can't imagine what error we + // could have by this point. still error out and report it. + std::string errorMessage("Invalid format string or unknown vsnprintf error; vsnprintf returned negative with format string: "); errorMessage.append(format); throw std::runtime_error(errorMessage); } - output.resize(write_point + bytes_used); } } +void StringFormat(std::string& output, const char* format, ...) +{ + va_list args; + va_start(args, format); + vStringFormat(output,format,args); + va_end(args); +} + // normal strncpy doesnt put a null term on copied strings, this one does // ref: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecrt/htm/_wcecrt_strncpy_wcsncpy.asp char* strn0cpy(char* dest, const char* source, uint32 size) { diff --git a/common/StringUtil.h b/common/StringUtil.h index b7e389e65..423201247 100644 --- a/common/StringUtil.h +++ b/common/StringUtil.h @@ -17,8 +17,11 @@ #define _STRINGUTIL_H_ #include +#include #include "types.h" + +void vStringFormat(std::string& output, const char* format, va_list args); void StringFormat(std::string& output, const char* format, ...); ////////////////////////////////////////////////////////////////////// // diff --git a/common/debug.cpp b/common/debug.cpp index e164acbd6..b59882d46 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -12,10 +13,11 @@ #define vsnprintf _vsnprintf #define strncasecmp _strnicmp #define strcasecmp _stricmp + #else + #include #include - #include #endif #include "../common/StringUtil.h" @@ -150,28 +152,36 @@ bool EQEMuLog::write(LogIDs id, const char *fmt, ...) { time( &aclock ); /* Get time in seconds */ newtime = localtime( &aclock ); /* Convert time to struct */ - if (dofile) + if (dofile) { #ifndef NO_PIDLOG fprintf(fp[id], "[%02d.%02d. - %02d:%02d:%02d] ", newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec); #else fprintf(fp[id], "%04i [%02d.%02d. - %02d:%02d:%02d] ", getpid(), newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec); #endif + } - va_list argptr, tmpargptr; - va_start(argptr, fmt); + va_list argptr,tmpargptr; + if (dofile) { - va_copy(tmpargptr, argptr); + va_start(argptr, fmt); + va_copy(tmpargptr,argptr); vfprintf( fp[id], fmt, tmpargptr ); + va_end(tmpargptr); } if(logCallbackFmt[id]) { msgCallbackFmt p = logCallbackFmt[id]; - va_copy(tmpargptr, argptr); + va_start(argptr, fmt); + va_copy(tmpargptr,argptr); p(id, fmt, tmpargptr ); + va_end(tmpargptr); } - + std::string outputMessage; - StringFormat(outputMessage, fmt, argptr); - + va_start(argptr, fmt); + va_copy(tmpargptr,argptr); + vStringFormat(outputMessage, fmt, tmpargptr); + va_end(tmpargptr); + if (pLogStatus[id] & 2) { if (pLogStatus[id] & 8) { @@ -183,7 +193,6 @@ bool EQEMuLog::write(LogIDs id, const char *fmt, ...) { std::cout << outputMessage; } } - va_end(argptr); if (dofile) fprintf(fp[id], "\n"); if (pLogStatus[id] & 2) {