Merge branch 'master' of https://github.com/EQEmu/Server into EQEmu-master

Conflicts:
	zone/client.h
	zone/mod_functions.cpp
	zone/mod_functions_base.cpp
This commit is contained in:
root 2013-06-01 19:17:23 -05:00
commit 7fca5a7a89
231 changed files with 2955 additions and 3061 deletions

View File

@ -79,6 +79,8 @@ IF(MSVC)
STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
ENDIF(${flag_var} MATCHES "/MD") ENDIF(${flag_var} MATCHES "/MD")
ENDFOREACH(flag_var) ENDFOREACH(flag_var)
ADD_DEFINITIONS(-DNOMINMAX)
ELSE(MSVC) ELSE(MSVC)
#Normally set by perl but we don't use the perl flags anymore so we set it. #Normally set by perl but we don't use the perl flags anymore so we set it.
ADD_DEFINITIONS(-DHAS_UNION_SEMUN) ADD_DEFINITIONS(-DHAS_UNION_SEMUN)
@ -125,17 +127,8 @@ OPTION(EQEMU_BUILD_PERL "Build Perl parser." ON)
#C++11 stuff #C++11 stuff
IF(NOT MSVC) IF(NOT MSVC)
ADD_DEFINITIONS(-std=c++0x) ADD_DEFINITIONS(-std=c++0x)
#Rvalue-Move - todo: auto set this based on gcc version
OPTION(EQEMU_ENABLE_RVALUE_MOVE "Enable EQEmu RValue References (Enable if GCC 4.3 or higher)" OFF)
ELSE(NOT MSVC)
#Rvalue-Move - todo: auto set this based on msvc version
OPTION(EQEMU_ENABLE_RVALUE_MOVE "Enable EQEmu RValue References (Enable if Visual Studio 2010 or higher)" OFF)
ENDIF(NOT MSVC) ENDIF(NOT MSVC)
IF(EQEMU_ENABLE_RVALUE_MOVE)
ADD_DEFINITIONS(-DEQEMU_RVALUE_MOVE)
ENDIF(EQEMU_ENABLE_RVALUE_MOVE)
#Various definitions #Various definitions
IF(EQEMU_BUILD_PERL) IF(EQEMU_BUILD_PERL)
ADD_DEFINITIONS(-DEMBPERL) ADD_DEFINITIONS(-DEMBPERL)

View File

@ -1,4 +1,4 @@
The server code and utilities are released under GPL. The server code and utilities are released under GPLv3.
We also include some small libraries for convienence that may be under different licensing: We also include some small libraries for convienence that may be under different licensing:
@ -9,3 +9,4 @@ ZLib - ZLib License
MySQL - GPL MySQL - GPL
Perl - GPL / ActiveState (under the assumption that this is a free project). Perl - GPL / ActiveState (under the assumption that this is a free project).
CPPUnit - GLP CPPUnit - GLP
StringUtilities - Apache

View File

@ -56,7 +56,7 @@ void BasePacket::build_raw_header_dump(char *buffer, uint16 seq) const
buffer += sprintf(buffer, "%s.%06lu ",temp,timestamp.tv_usec); buffer += sprintf(buffer, "%s.%06lu ",temp,timestamp.tv_usec);
} }
if (src_ip) { if (src_ip) {
string sIP,dIP;; std::string sIP,dIP;;
sIP=long2ip(src_ip); sIP=long2ip(src_ip);
dIP=long2ip(dst_ip); dIP=long2ip(dst_ip);
buffer += sprintf(buffer, "[%s:%d->%s:%d]\n",sIP.c_str(),src_port,dIP.c_str(),dst_port); buffer += sprintf(buffer, "[%s:%d->%s:%d]\n",sIP.c_str(),src_port,dIP.c_str(),dst_port);
@ -80,7 +80,7 @@ void BasePacket::build_header_dump(char *buffer) const
void BasePacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const void BasePacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
{ {
if (src_ip) { if (src_ip) {
string sIP,dIP;; std::string sIP,dIP;;
sIP=long2ip(src_ip); sIP=long2ip(src_ip);
dIP=long2ip(dst_ip); dIP=long2ip(dst_ip);
fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port); fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port);

View File

@ -10,7 +10,6 @@ SET(common_sources
database.cpp database.cpp
dbasync.cpp dbasync.cpp
dbcore.cpp dbcore.cpp
DBMemLeak.cpp
debug.cpp debug.cpp
emu_opcodes.cpp emu_opcodes.cpp
EmuTCPConnection.cpp EmuTCPConnection.cpp
@ -55,6 +54,7 @@ SET(common_sources
serverinfo.cpp serverinfo.cpp
shareddb.cpp shareddb.cpp
spdat.cpp spdat.cpp
StringUtil.cpp
StructStrategy.cpp StructStrategy.cpp
TCPConnection.cpp TCPConnection.cpp
TCPServer.cpp TCPServer.cpp
@ -102,7 +102,6 @@ SET(common_headers
database.h database.h
dbasync.h dbasync.h
dbcore.h dbcore.h
DBMemLeak.h
debug.h debug.h
deity.h deity.h
emu_opcodes.h emu_opcodes.h
@ -170,6 +169,7 @@ SET(common_headers
shareddb.h shareddb.h
skills.h skills.h
spdat.h spdat.h
StringUtil.h
StructStrategy.h StructStrategy.h
TCPBasicServer.h TCPBasicServer.h
TCPConnection.h TCPConnection.h
@ -313,7 +313,6 @@ INCLUDE_DIRECTORIES(Patches SocketLib StackWalker TinyXML)
ADD_LIBRARY(Common ${common_sources} ${common_headers}) ADD_LIBRARY(Common ${common_sources} ${common_headers})
IF(UNIX) IF(UNIX)
ADD_DEFINITIONS(-fPIC) ADD_DEFINITIONS(-fPIC)
SET_SOURCE_FILES_PROPERTIES("patches/SoD.cpp" "patches/SoF.cpp" "patches/RoF.cpp" "patches/Underfoot.cpp" PROPERTIES COMPILE_FLAGS -O0) SET_SOURCE_FILES_PROPERTIES("patches/SoD.cpp" "patches/SoF.cpp" "patches/RoF.cpp" "patches/Underfoot.cpp" PROPERTIES COMPILE_FLAGS -O0)

View File

@ -20,134 +20,129 @@
#include "Condition.h" #include "Condition.h"
#ifdef _WINDOWS #ifdef _WINDOWS
Condition::Condition()
{
m_events[SignalEvent] = CreateEvent (nullptr, // security
FALSE, // is auto-reset event?
FALSE, // is signaled initially?
nullptr); // name
m_events[BroadcastEvent] = CreateEvent (nullptr, // security
TRUE, // is auto-reset event?
FALSE, // is signaled initially?
nullptr); // name
m_waiters = 0;
InitializeCriticalSection(&CSMutex);
}
Condition::~Condition()
{
DeleteCriticalSection(&CSMutex);
CloseHandle(m_events[SignalEvent]);
CloseHandle(m_events[BroadcastEvent]);
}
void Condition::Signal()
{
EnterCriticalSection(&CSMutex);
if(m_waiters > 0)
SetEvent(m_events[SignalEvent]);
LeaveCriticalSection(&CSMutex);
}
void Condition::SignalAll()
{
EnterCriticalSection(&CSMutex);
if(m_waiters > 0)
SetEvent(m_events[BroadcastEvent]);
LeaveCriticalSection(&CSMutex);
}
void Condition::Wait()
{
EnterCriticalSection(&CSMutex);
m_waiters++;
LeaveCriticalSection(&CSMutex);
int result = WaitForMultipleObjects (_eventCount, m_events, FALSE, INFINITE);
EnterCriticalSection(&CSMutex);
m_waiters--;
//see if we are the last person waiting on the condition, and there was a broadcast
//if so, we need to reset the broadcast event.
if(m_waiters == 0 && result == (WAIT_OBJECT_0+BroadcastEvent))
ResetEvent(m_events[BroadcastEvent]);
LeaveCriticalSection(&CSMutex);
}
#else #else
#include <pthread.h> #include <pthread.h>
#include <sys/time.h> #include <sys/time.h>
#include <errno.h> #include <errno.h>
Condition::Condition()
{
pthread_cond_init(&cond,nullptr);
pthread_mutex_init(&mutex,nullptr);
}
void Condition::Signal()
{
pthread_mutex_lock(&mutex);
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}
void Condition::SignalAll()
{
pthread_mutex_lock(&mutex);
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
}
void Condition::Wait()
{
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond,&mutex);
pthread_mutex_unlock(&mutex);
}
/*
I commented this specifically because I think it might be very
difficult to write a windows counterpart to it, so I would like
to discourage its use until we can confirm that it can be reasonably
implemented on windows.
bool Condition::TimedWait(unsigned long usec)
{
struct timeval now;
struct timespec timeout;
int retcode=0;
pthread_mutex_lock(&mutex);
gettimeofday(&now,nullptr);
now.tv_usec+=usec;
timeout.tv_sec = now.tv_sec + (now.tv_usec/1000000);
timeout.tv_nsec = (now.tv_usec%1000000) *1000;
//cout << "now=" << now.tv_sec << "."<<now.tv_usec << endl;
//cout << "timeout=" << timeout.tv_sec << "."<<timeout.tv_nsec << endl;
retcode=pthread_cond_timedwait(&cond,&mutex,&timeout);
pthread_mutex_unlock(&mutex);
return retcode!=ETIMEDOUT;
}
*/
Condition::~Condition()
{
pthread_mutex_lock(&mutex);
pthread_cond_destroy(&cond);
pthread_mutex_unlock(&mutex);
pthread_mutex_destroy(&mutex);
}
#endif #endif
#ifdef _WINDOWS
Condition::Condition()
{
m_events[SignalEvent] = CreateEvent (nullptr, // security
FALSE, // is auto-reset event?
FALSE, // is signaled initially?
nullptr); // name
m_events[BroadcastEvent] = CreateEvent (nullptr, // security
TRUE, // is auto-reset event?
FALSE, // is signaled initially?
nullptr); // name
m_waiters = 0;
InitializeCriticalSection(&CSMutex);
}
Condition::~Condition()
{
DeleteCriticalSection(&CSMutex);
CloseHandle(m_events[SignalEvent]);
CloseHandle(m_events[BroadcastEvent]);
}
void Condition::Signal()
{
EnterCriticalSection(&CSMutex);
if(m_waiters > 0)
SetEvent(m_events[SignalEvent]);
LeaveCriticalSection(&CSMutex);
}
void Condition::SignalAll()
{
EnterCriticalSection(&CSMutex);
if(m_waiters > 0)
SetEvent(m_events[BroadcastEvent]);
LeaveCriticalSection(&CSMutex);
}
void Condition::Wait()
{
EnterCriticalSection(&CSMutex);
m_waiters++;
LeaveCriticalSection(&CSMutex);
int result = WaitForMultipleObjects (_eventCount, m_events, FALSE, INFINITE);
EnterCriticalSection(&CSMutex);
m_waiters--;
//see if we are the last person waiting on the condition, and there was a broadcast
//if so, we need to reset the broadcast event.
if(m_waiters == 0 && result == (WAIT_OBJECT_0+BroadcastEvent))
ResetEvent(m_events[BroadcastEvent]);
LeaveCriticalSection(&CSMutex);
}
#else //!WIN32
Condition::Condition()
{
pthread_cond_init(&cond,nullptr);
pthread_mutex_init(&mutex,nullptr);
}
void Condition::Signal()
{
pthread_mutex_lock(&mutex);
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}
void Condition::SignalAll()
{
pthread_mutex_lock(&mutex);
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
}
void Condition::Wait()
{
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond,&mutex);
pthread_mutex_unlock(&mutex);
}
/*
I commented this specifically because I think it might be very
difficult to write a windows counterpart to it, so I would like
to discourage its use until we can confirm that it can be reasonably
implemented on windows.
bool Condition::TimedWait(unsigned long usec)
{
struct timeval now;
struct timespec timeout;
int retcode=0;
pthread_mutex_lock(&mutex);
gettimeofday(&now,nullptr);
now.tv_usec+=usec;
timeout.tv_sec = now.tv_sec + (now.tv_usec/1000000);
timeout.tv_nsec = (now.tv_usec%1000000) *1000;
//cout << "now=" << now.tv_sec << "."<<now.tv_usec << endl;
//cout << "timeout=" << timeout.tv_sec << "."<<timeout.tv_nsec << endl;
retcode=pthread_cond_timedwait(&cond,&mutex,&timeout);
pthread_mutex_unlock(&mutex);
return retcode!=ETIMEDOUT;
}
*/
Condition::~Condition()
{
pthread_mutex_lock(&mutex);
pthread_cond_destroy(&cond);
pthread_mutex_unlock(&mutex);
pthread_mutex_destroy(&mutex);
}
#endif

View File

@ -1,62 +0,0 @@
#ifdef _EQDEBUG
#include "../common/debug.h"
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "../common/Mutex.h"
#include "DBMemLeak.h"
#include <crtdbg.h>
#ifdef _WINDOWS
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#endif
DBMemLeak dbmemleak;
LinkedList<DBMemLeakStruct*>* list = 0;
Mutex MDBMemLeak;
DBMemLeak::DBMemLeak() {
list = new LinkedList<DBMemLeakStruct*>;
}
DBMemLeak::~DBMemLeak() {
LinkedListIterator<DBMemLeakStruct*> iterator(*list);
iterator.Reset();
while (iterator.MoreElements()) {
char tmp[200];
snprintf(tmp, sizeof(tmp) - 3, "DB Mem Leak: Block=%6d, Query=%s", iterator.GetData()->memblock, iterator.GetData()->query);
snprintf(tmp, sizeof(tmp), "%s\n", tmp);
OutputDebugString(tmp);
iterator.Advance();
}
safe_delete(list);
}
void DBMemLeak::Alloc(const void* result, const char* query) {
LockMutex lock(&MDBMemLeak);
long requestNumber;
uint8* tmp2 = new uint8;
_CrtIsMemoryBlock( tmp2, 1, &requestNumber, 0, 0 );
safe_delete(tmp2);
DBMemLeakStruct* tmp = (DBMemLeakStruct*) new uchar[sizeof(DBMemLeakStruct) + strlen(query) + 1];
tmp->result = result;
tmp->memblock = requestNumber;
strcpy(tmp->query, query);
list->Append(tmp);
}
void DBMemLeak::Free(const void* result) {
LockMutex lock(&MDBMemLeak);
LinkedListIterator<DBMemLeakStruct*> iterator(*list);
iterator.Reset();
while (iterator.MoreElements()) {
if (result == iterator.GetData()->result)
iterator.RemoveCurrent();
else
iterator.Advance();
}
}
#endif

View File

@ -1,25 +0,0 @@
#ifdef _EQDEBUG
#ifndef DBMemLeak_H
#define DBMemLeak_H
#include "../common/types.h"
#include "../common/linked_list.h"
#define mysql_free_result(r) { DBMemLeak::Free(r); mysql_free_result(r); }
struct DBMemLeakStruct {
const void* result;
uint32 memblock;
char query[0];
};
class DBMemLeak {
public:
DBMemLeak();
~DBMemLeak();
static void Alloc(const void* result, const char* query);
static void Free(const void* result);
};
#endif
#endif

View File

@ -46,7 +46,7 @@ public:
//END PERL EXPORT //END PERL EXPORT
private: private:
string m_escapeBuffer; std::string m_escapeBuffer;
static EQDB s_EQDB; static EQDB s_EQDB;
MYSQL *mysql_ref; MYSQL *mysql_ref;
}; };

View File

@ -19,8 +19,8 @@
#include "EQDBRes.h" #include "EQDBRes.h"
#include <mysql.h> #include <mysql.h>
vector<string> EQDBRes::fetch_row_array() { std::vector<std::string> EQDBRes::fetch_row_array() {
vector<string> array; std::vector<std::string> array;
if(res == nullptr) if(res == nullptr)
return(array); return(array);
@ -32,8 +32,8 @@ vector<string> EQDBRes::fetch_row_array() {
return array; return array;
} }
map<string,string> EQDBRes::fetch_row_hash() { std::map<std::string,std::string> EQDBRes::fetch_row_hash() {
map<string,string> rowhash; std::map<std::string,std::string> rowhash;
if(res == nullptr) if(res == nullptr)
return(rowhash); return(rowhash);

View File

@ -36,8 +36,8 @@ public:
unsigned long num_fields() { return (res) ? mysql_num_fields(res) : 0; } unsigned long num_fields() { return (res) ? mysql_num_fields(res) : 0; }
void DESTROY() { } void DESTROY() { }
void finish() { if (res) mysql_free_result(res); res=nullptr; }; void finish() { if (res) mysql_free_result(res); res=nullptr; };
vector<string> fetch_row_array(); std::vector<std::string> fetch_row_array();
map<string,string> fetch_row_hash(); std::map<std::string,std::string> fetch_row_hash();
unsigned long * fetch_lengths() { return (res) ? mysql_fetch_lengths(res) : 0; } unsigned long * fetch_lengths() { return (res) ? mysql_fetch_lengths(res) : 0; }
//END PERL EXPORT //END PERL EXPORT

View File

@ -21,7 +21,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
string EQEmuConfig::ConfigFile = "eqemu_config.xml"; std::string EQEmuConfig::ConfigFile = "eqemu_config.xml";
EQEmuConfig *EQEmuConfig::_config = nullptr; EQEmuConfig *EQEmuConfig::_config = nullptr;
void EQEmuConfig::do_world(TiXmlElement *ele) { void EQEmuConfig::do_world(TiXmlElement *ele) {
@ -315,7 +315,7 @@ void EQEmuConfig::do_launcher(TiXmlElement *ele) {
} }
} }
string EQEmuConfig::GetByName(const string &var_name) const { std::string EQEmuConfig::GetByName(const std::string &var_name) const {
if(var_name == "ShortName") if(var_name == "ShortName")
return(ShortName); return(ShortName);
if(var_name == "LongName") if(var_name == "LongName")
@ -405,44 +405,44 @@ string EQEmuConfig::GetByName(const string &var_name) const {
void EQEmuConfig::Dump() const void EQEmuConfig::Dump() const
{ {
cout << "ShortName = " << ShortName << endl; std::cout << "ShortName = " << ShortName << std::endl;
cout << "LongName = " << LongName << endl; std::cout << "LongName = " << LongName << std::endl;
cout << "WorldAddress = " << WorldAddress << endl; std::cout << "WorldAddress = " << WorldAddress << std::endl;
cout << "LoginHost = " << LoginHost << endl; std::cout << "LoginHost = " << LoginHost << std::endl;
cout << "LoginAccount = " << LoginAccount << endl; std::cout << "LoginAccount = " << LoginAccount << std::endl;
cout << "LoginPassword = " << LoginPassword << endl; std::cout << "LoginPassword = " << LoginPassword << std::endl;
cout << "LoginPort = " << LoginPort << endl; std::cout << "LoginPort = " << LoginPort << std::endl;
cout << "Locked = " << Locked << endl; std::cout << "Locked = " << Locked << std::endl;
cout << "WorldTCPPort = " << WorldTCPPort << endl; std::cout << "WorldTCPPort = " << WorldTCPPort << std::endl;
cout << "WorldIP = " << WorldIP << endl; std::cout << "WorldIP = " << WorldIP << std::endl;
cout << "TelnetEnabled = " << TelnetEnabled << endl; std::cout << "TelnetEnabled = " << TelnetEnabled << std::endl;
cout << "WorldHTTPPort = " << WorldHTTPPort << endl; std::cout << "WorldHTTPPort = " << WorldHTTPPort << std::endl;
cout << "WorldHTTPMimeFile = " << WorldHTTPMimeFile << endl; std::cout << "WorldHTTPMimeFile = " << WorldHTTPMimeFile << std::endl;
cout << "WorldHTTPEnabled = " << WorldHTTPEnabled << endl; std::cout << "WorldHTTPEnabled = " << WorldHTTPEnabled << std::endl;
cout << "ChatHost = " << ChatHost << endl; std::cout << "ChatHost = " << ChatHost << std::endl;
cout << "ChatPort = " << ChatPort << endl; std::cout << "ChatPort = " << ChatPort << std::endl;
cout << "MailHost = " << MailHost << endl; std::cout << "MailHost = " << MailHost << std::endl;
cout << "MailPort = " << MailPort << endl; std::cout << "MailPort = " << MailPort << std::endl;
cout << "DatabaseHost = " << DatabaseHost << endl; std::cout << "DatabaseHost = " << DatabaseHost << std::endl;
cout << "DatabaseUsername = " << DatabaseUsername << endl; std::cout << "DatabaseUsername = " << DatabaseUsername << std::endl;
cout << "DatabasePassword = " << DatabasePassword << endl; std::cout << "DatabasePassword = " << DatabasePassword << std::endl;
cout << "DatabaseDB = " << DatabaseDB << endl; std::cout << "DatabaseDB = " << DatabaseDB << std::endl;
cout << "DatabasePort = " << DatabasePort << endl; std::cout << "DatabasePort = " << DatabasePort << std::endl;
cout << "QSDatabaseHost = " << QSDatabaseHost << endl; std::cout << "QSDatabaseHost = " << QSDatabaseHost << std::endl;
cout << "QSDatabaseUsername = " << QSDatabaseUsername << endl; std::cout << "QSDatabaseUsername = " << QSDatabaseUsername << std::endl;
cout << "QSDatabasePassword = " << QSDatabasePassword << endl; std::cout << "QSDatabasePassword = " << QSDatabasePassword << std::endl;
cout << "QSDatabaseDB = " << QSDatabaseDB << endl; std::cout << "QSDatabaseDB = " << QSDatabaseDB << std::endl;
cout << "QSDatabasePort = " << QSDatabasePort << endl; std::cout << "QSDatabasePort = " << QSDatabasePort << std::endl;
cout << "SpellsFile = " << SpellsFile << endl; std::cout << "SpellsFile = " << SpellsFile << std::endl;
cout << "OpCodesFile = " << OpCodesFile << endl; std::cout << "OpCodesFile = " << OpCodesFile << std::endl;
cout << "EQTimeFile = " << EQTimeFile << endl; std::cout << "EQTimeFile = " << EQTimeFile << std::endl;
cout << "LogSettingsFile = " << LogSettingsFile << endl; std::cout << "LogSettingsFile = " << LogSettingsFile << std::endl;
cout << "MapDir = " << MapDir << endl; std::cout << "MapDir = " << MapDir << std::endl;
cout << "QuestDir = " << QuestDir << endl; std::cout << "QuestDir = " << QuestDir << std::endl;
cout << "PluginDir = " << PluginDir << endl; std::cout << "PluginDir = " << PluginDir << std::endl;
cout << "ZonePortLow = " << ZonePortLow << endl; std::cout << "ZonePortLow = " << ZonePortLow << std::endl;
cout << "ZonePortHigh = " << ZonePortHigh << endl; std::cout << "ZonePortHigh = " << ZonePortHigh << std::endl;
cout << "DefaultStatus = " << (int)DefaultStatus << endl; std::cout << "DefaultStatus = " << (int)DefaultStatus << std::endl;
// cout << "DynamicCount = " << DynamicCount << endl; // std::cout << "DynamicCount = " << DynamicCount << std::endl;
} }

View File

@ -22,74 +22,74 @@
#include "linked_list.h" #include "linked_list.h"
struct LoginConfig { struct LoginConfig {
string LoginHost; std::string LoginHost;
string LoginAccount; std::string LoginAccount;
string LoginPassword; std::string LoginPassword;
uint16 LoginPort; uint16 LoginPort;
}; };
class EQEmuConfig : public XMLParser { class EQEmuConfig : public XMLParser {
public: public:
virtual string GetByName(const string &var_name) const; virtual std::string GetByName(const std::string &var_name) const;
// From <world/> // From <world/>
string ShortName; std::string ShortName;
string LongName; std::string LongName;
string WorldAddress; std::string WorldAddress;
string LocalAddress; std::string LocalAddress;
string LoginHost; std::string LoginHost;
string LoginAccount; std::string LoginAccount;
string LoginPassword; std::string LoginPassword;
uint16 LoginPort; uint16 LoginPort;
uint32 LoginCount; uint32 LoginCount;
LinkedList<LoginConfig*> loginlist; LinkedList<LoginConfig*> loginlist;
bool Locked; bool Locked;
uint16 WorldTCPPort; uint16 WorldTCPPort;
string WorldIP; std::string WorldIP;
bool TelnetEnabled; bool TelnetEnabled;
int32 MaxClients; int32 MaxClients;
bool WorldHTTPEnabled; bool WorldHTTPEnabled;
uint16 WorldHTTPPort; uint16 WorldHTTPPort;
string WorldHTTPMimeFile; std::string WorldHTTPMimeFile;
string SharedKey; std::string SharedKey;
// From <chatserver/> // From <chatserver/>
string ChatHost; std::string ChatHost;
uint16 ChatPort; uint16 ChatPort;
// From <mailserver/> // From <mailserver/>
string MailHost; std::string MailHost;
uint16 MailPort; uint16 MailPort;
// From <database/> // From <database/>
string DatabaseHost; std::string DatabaseHost;
string DatabaseUsername; std::string DatabaseUsername;
string DatabasePassword; std::string DatabasePassword;
string DatabaseDB; std::string DatabaseDB;
uint16 DatabasePort; uint16 DatabasePort;
// From <qsdatabase> // QueryServ // From <qsdatabase> // QueryServ
string QSDatabaseHost; std::string QSDatabaseHost;
string QSDatabaseUsername; std::string QSDatabaseUsername;
string QSDatabasePassword; std::string QSDatabasePassword;
string QSDatabaseDB; std::string QSDatabaseDB;
uint16 QSDatabasePort; uint16 QSDatabasePort;
// From <files/> // From <files/>
string SpellsFile; std::string SpellsFile;
string OpCodesFile; std::string OpCodesFile;
string EQTimeFile; std::string EQTimeFile;
string LogSettingsFile; std::string LogSettingsFile;
// From <directories/> // From <directories/>
string MapDir; std::string MapDir;
string QuestDir; std::string QuestDir;
string PluginDir; std::string PluginDir;
// From <launcher/> // From <launcher/>
string LogPrefix; std::string LogPrefix;
string LogSuffix; std::string LogSuffix;
string ZoneExe; std::string ZoneExe;
uint32 RestartWait; uint32 RestartWait;
uint32 TerminateWait; uint32 TerminateWait;
uint32 InitialBootWait; uint32 InitialBootWait;
@ -108,7 +108,7 @@ protected:
static EQEmuConfig *_config; static EQEmuConfig *_config;
static string ConfigFile; static std::string ConfigFile;
#define ELEMENT(name) \ #define ELEMENT(name) \
void do_##name(TiXmlElement *ele); void do_##name(TiXmlElement *ele);
@ -210,7 +210,7 @@ public:
} }
// Allow the use to set the conf file to be used. // Allow the use to set the conf file to be used.
static void SetConfigFile(string file) { EQEmuConfig::ConfigFile = file; } static void SetConfigFile(std::string file) { EQEmuConfig::ConfigFile = file; }
// Load the config // Load the config
static bool LoadConfig() { static bool LoadConfig() {

View File

@ -46,8 +46,6 @@
#include "../common/crc32.h" #include "../common/crc32.h"
#include "../common/eq_packet_structs.h" #include "../common/eq_packet_structs.h"
using namespace std;
#define EQN_DEBUG 0 #define EQN_DEBUG 0
#define EQN_DEBUG_Error 0 #define EQN_DEBUG_Error 0
#define EQN_DEBUG_Packet 0 #define EQN_DEBUG_Packet 0
@ -230,19 +228,19 @@ void EQStreamServer::Process() {
} }
} }
map <string, EQStream*>::iterator connection; std::map <std::string, EQStream*>::iterator connection;
for (connection = connection_list.begin( ); connection != connection_list.end( );) for (connection = connection_list.begin( ); connection != connection_list.end( );)
{ {
if(!connection->second) if(!connection->second)
{ {
map <string, EQStream*>::iterator tmp=connection; std::map <std::string, EQStream*>::iterator tmp=connection;
connection++; connection++;
connection_list.erase(tmp); connection_list.erase(tmp);
continue; continue;
} }
EQStream* eqs_data = connection->second; EQStream* eqs_data = connection->second;
if (eqs_data->IsFree() && (!eqs_data->CheckNetActive())) { if (eqs_data->IsFree() && (!eqs_data->CheckNetActive())) {
map <string, EQStream*>::iterator tmp=connection; std::map <std::string, EQStream*>::iterator tmp=connection;
connection++; connection++;
safe_delete(eqs_data); safe_delete(eqs_data);
connection_list.erase(tmp); connection_list.erase(tmp);
@ -277,7 +275,7 @@ void EQStreamServer::RecvData(uchar* data, uint32 size, uint32 irIP, uint16 irPo
sprintf(temp,"%lu:%u",(unsigned long)irIP,irPort); sprintf(temp,"%lu:%u",(unsigned long)irIP,irPort);
cout << "Data from " << temp << endl; cout << "Data from " << temp << endl;
EQStream* tmp = NULL; EQStream* tmp = NULL;
map <string, EQStream*>::iterator connection; std::map <std::string, EQStream*>::iterator connection;
if ((connection=connection_list.find(temp))!=connection_list.end()) if ((connection=connection_list.find(temp))!=connection_list.end())
tmp=connection->second; tmp=connection->second;
if(tmp != NULL && tmp->GetrPort() == irPort) if(tmp != NULL && tmp->GetrPort() == irPort)

View File

@ -30,7 +30,6 @@
#include <map> #include <map>
#include <list> #include <list>
#include <queue> #include <queue>
using namespace std;
#include "../common/types.h" #include "../common/types.h"
#include "../common/timer.h" #include "../common/timer.h"
@ -114,8 +113,8 @@ private:
Mutex MNewQueue; Mutex MNewQueue;
Mutex MOpen; Mutex MOpen;
map<string,EQStream*> connection_list; std::map<std::string,EQStream*> connection_list;
queue<EQStream *> NewQueue; std::queue<EQStream *> NewQueue;
}; };
#endif #endif

View File

@ -32,8 +32,6 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
using namespace std;
EQPacket::EQPacket(EmuOpcode op, const unsigned char *buf, uint32 len) EQPacket::EQPacket(EmuOpcode op, const unsigned char *buf, uint32 len)
: BasePacket(buf, len), : BasePacket(buf, len),
emu_opcode(op) emu_opcode(op)
@ -61,7 +59,7 @@ void EQPacket::build_header_dump(char *buffer) const {
void EQPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const void EQPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
{ {
if (src_ip) { if (src_ip) {
string sIP,dIP;; std::string sIP,dIP;;
sIP=long2ip(src_ip); sIP=long2ip(src_ip);
dIP=long2ip(dst_ip); dIP=long2ip(dst_ip);
fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port); fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port);
@ -95,7 +93,7 @@ void EQProtocolPacket::build_header_dump(char *buffer) const
void EQProtocolPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const void EQProtocolPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
{ {
if (src_ip) { if (src_ip) {
string sIP,dIP;; std::string sIP,dIP;;
sIP=long2ip(src_ip); sIP=long2ip(src_ip);
dIP=long2ip(dst_ip); dIP=long2ip(dst_ip);
fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port); fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port);
@ -137,7 +135,7 @@ void EQApplicationPacket::build_header_dump(char *buffer) const
void EQApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const void EQApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
{ {
if (src_ip) { if (src_ip) {
string sIP,dIP;; std::string sIP,dIP;;
sIP=long2ip(src_ip); sIP=long2ip(src_ip);
dIP=long2ip(dst_ip); dIP=long2ip(dst_ip);
fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port); fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port);
@ -183,7 +181,7 @@ void EQRawApplicationPacket::build_header_dump(char *buffer) const
void EQRawApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const void EQRawApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
{ {
if (src_ip) { if (src_ip) {
string sIP,dIP;; std::string sIP,dIP;;
sIP=long2ip(src_ip); sIP=long2ip(src_ip);
dIP=long2ip(dst_ip); dIP=long2ip(dst_ip);
fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port); fprintf(to, "[%s:%d->%s:%d] ",sIP.c_str(),src_port,dIP.c_str(),dst_port);
@ -502,8 +500,8 @@ EQRawApplicationPacket::EQRawApplicationPacket(const unsigned char *buf, const u
void DumpPacket(const EQApplicationPacket* app, bool iShowInfo) { void DumpPacket(const EQApplicationPacket* app, bool iShowInfo) {
if (iShowInfo) { if (iShowInfo) {
cout << "Dumping Applayer: 0x" << hex << setfill('0') << setw(4) << app->GetOpcode() << dec; std::cout << "Dumping Applayer: 0x" << std::hex << std::setfill('0') << std::setw(4) << app->GetOpcode() << std::dec;
cout << " size:" << app->size << endl; std::cout << " size:" << app->size << std::endl;
} }
DumpPacketHex(app->pBuffer, app->size); DumpPacketHex(app->pBuffer, app->size);
// DumpPacketAscii(app->pBuffer, app->size); // DumpPacketAscii(app->pBuffer, app->size);

View File

@ -30,8 +30,6 @@
#include "emu_opcodes.h" #include "emu_opcodes.h"
#endif #endif
using namespace std;
class EQStream; class EQStream;
class EQStreamPair; class EQStreamPair;

View File

@ -15,16 +15,32 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "debug.h" #include "debug.h"
#include "EQPacket.h"
#include "EQStream.h"
#include "misc.h"
#include "Mutex.h"
#include "op_codes.h"
#include "CRC16.h"
#include <string> #include <string>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <time.h> #include <algorithm>
#include <sys/types.h>
#if defined(ZONE) || defined(WORLD)
#define RETRANSMITS
#endif
#ifdef RETRANSMITS
#include "rulesys.h"
#endif
#ifdef _WINDOWS #ifdef _WINDOWS
#include <time.h> #include <time.h>
#else #else
#include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/time.h> #include <sys/time.h>
@ -33,20 +49,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
#include "EQPacket.h"
#include "EQStream.h"
//#include "EQStreamFactory.h"
#include "misc.h"
#include "Mutex.h"
#include "op_codes.h"
#include "CRC16.h"
#if defined(ZONE) || defined(WORLD)
#define RETRANSMITS
#endif
#ifdef RETRANSMITS
#include "rulesys.h"
#endif
//for logsys //for logsys
#define _L "%s:%d: " #define _L "%s:%d: "
@ -424,7 +426,7 @@ if(NextSequencedSend > SequencedQueue.size()) {
uint16 index = seq - SequencedBase; uint16 index = seq - SequencedBase;
_log(NET__NET_TRACE, _L " OP_OutOfOrderAck marking packet acked in queue (queue index = %d, queue size = %d)." __L, index, sqsize); _log(NET__NET_TRACE, _L " OP_OutOfOrderAck marking packet acked in queue (queue index = %d, queue size = %d)." __L, index, sqsize);
if (index < sqsize) { if (index < sqsize) {
deque<EQProtocolPacket *>::iterator sitr; std::deque<EQProtocolPacket *>::iterator sitr;
sitr = SequencedQueue.begin(); sitr = SequencedQueue.begin();
sitr += index; sitr += index;
(*sitr)->acked = true; (*sitr)->acked = true;
@ -567,7 +569,7 @@ uint32 length;
while (used<length) { while (used<length) {
out=new EQProtocolPacket(OP_Fragment,nullptr,MaxLen-4); out=new EQProtocolPacket(OP_Fragment,nullptr,MaxLen-4);
chunksize=min(length-used,MaxLen-6); chunksize=std::min(length-used,MaxLen-6);
memcpy(out->pBuffer+2,tmpbuff+used,chunksize); memcpy(out->pBuffer+2,tmpbuff+used,chunksize);
out->size=chunksize+2; out->size=chunksize+2;
SequencedPush(out); SequencedPush(out);
@ -646,9 +648,9 @@ uint16 Seq=htons(seq);
void EQStream::Write(int eq_fd) void EQStream::Write(int eq_fd)
{ {
queue<EQProtocolPacket *> ReadyToSend; std::queue<EQProtocolPacket *> ReadyToSend;
bool SeqEmpty=false,NonSeqEmpty=false; bool SeqEmpty=false,NonSeqEmpty=false;
deque<EQProtocolPacket *>::iterator sitr; std::deque<EQProtocolPacket *>::iterator sitr;
// Check our rate to make sure we can send more // Check our rate to make sure we can send more
MRate.lock(); MRate.lock();
@ -951,7 +953,7 @@ EQRawApplicationPacket *p=nullptr;
MInboundQueue.lock(); MInboundQueue.lock();
if (InboundQueue.size()) { if (InboundQueue.size()) {
vector<EQRawApplicationPacket *>::iterator itr=InboundQueue.begin(); std::vector<EQRawApplicationPacket *>::iterator itr=InboundQueue.begin();
p=*itr; p=*itr;
InboundQueue.erase(itr); InboundQueue.erase(itr);
} }
@ -979,7 +981,7 @@ EQRawApplicationPacket *p=nullptr;
MInboundQueue.lock(); MInboundQueue.lock();
if (InboundQueue.size()) { if (InboundQueue.size()) {
vector<EQRawApplicationPacket *>::iterator itr=InboundQueue.begin(); std::vector<EQRawApplicationPacket *>::iterator itr=InboundQueue.begin();
p=*itr; p=*itr;
InboundQueue.erase(itr); InboundQueue.erase(itr);
} }
@ -1007,7 +1009,7 @@ EQRawApplicationPacket *p=nullptr;
MInboundQueue.lock(); MInboundQueue.lock();
if (InboundQueue.size()) { if (InboundQueue.size()) {
vector<EQRawApplicationPacket *>::iterator itr=InboundQueue.begin(); std::vector<EQRawApplicationPacket *>::iterator itr=InboundQueue.begin();
p=*itr; p=*itr;
} }
MInboundQueue.unlock(); MInboundQueue.unlock();
@ -1023,7 +1025,7 @@ EQApplicationPacket *p=nullptr;
MInboundQueue.lock(); MInboundQueue.lock();
if (!InboundQueue.empty()) { if (!InboundQueue.empty()) {
vector<EQRawApplicationPacket *>::iterator itr; std::vector<EQRawApplicationPacket *>::iterator itr;
for(itr=InboundQueue.begin();itr!=InboundQueue.end();itr++) { for(itr=InboundQueue.begin();itr!=InboundQueue.end();itr++) {
p=*itr; p=*itr;
delete p; delete p;
@ -1070,7 +1072,7 @@ EQProtocolPacket *p=nullptr;
NonSequencedQueue.pop(); NonSequencedQueue.pop();
} }
if(!SequencedQueue.empty()) { if(!SequencedQueue.empty()) {
deque<EQProtocolPacket *>::iterator itr; std::deque<EQProtocolPacket *>::iterator itr;
for(itr=SequencedQueue.begin();itr!=SequencedQueue.end();itr++) { for(itr=SequencedQueue.begin();itr!=SequencedQueue.end();itr++) {
p=*itr; p=*itr;
delete p; delete p;
@ -1095,7 +1097,7 @@ EQProtocolPacket *p=nullptr;
_log(NET__APP_TRACE, _L "Clearing future packet queue" __L); _log(NET__APP_TRACE, _L "Clearing future packet queue" __L);
if(!PacketQueue.empty()) { if(!PacketQueue.empty()) {
map<unsigned short,EQProtocolPacket *>::iterator itr; std::map<unsigned short,EQProtocolPacket *>::iterator itr;
for(itr=PacketQueue.begin();itr!=PacketQueue.end();itr++) { for(itr=PacketQueue.begin();itr!=PacketQueue.end();itr++) {
p=itr->second; p=itr->second;
delete p; delete p;
@ -1149,7 +1151,7 @@ long EQStream::GetLastAckSent()
void EQStream::AckPackets(uint16 seq) void EQStream::AckPackets(uint16 seq)
{ {
deque<EQProtocolPacket *>::iterator itr, tmp; std::deque<EQProtocolPacket *>::iterator itr, tmp;
MOutboundQueue.lock(); MOutboundQueue.lock();
//do a bit of sanity checking. //do a bit of sanity checking.
@ -1234,7 +1236,7 @@ void EQStream::ProcessQueue()
EQProtocolPacket *EQStream::RemoveQueue(uint16 seq) EQProtocolPacket *EQStream::RemoveQueue(uint16 seq)
{ {
map<unsigned short,EQProtocolPacket *>::iterator itr; std::map<unsigned short,EQProtocolPacket *>::iterator itr;
EQProtocolPacket *qp=nullptr; EQProtocolPacket *qp=nullptr;
if ((itr=PacketQueue.find(seq))!=PacketQueue.end()) { if ((itr=PacketQueue.find(seq))!=PacketQueue.end()) {
qp=itr->second; qp=itr->second;
@ -1356,6 +1358,9 @@ void EQStream::CheckTimeout(uint32 now, uint32 timeout) {
_log(NET__DEBUG, _L "Timeout expired in established state. Closing connection." __L); _log(NET__DEBUG, _L "Timeout expired in established state. Closing connection." __L);
_SendDisconnect(); _SendDisconnect();
SetState(DISCONNECTING); SetState(DISCONNECTING);
break;
default:
break;
} }
} }
} }

View File

@ -18,8 +18,6 @@
#include "../common/Condition.h" #include "../common/Condition.h"
#include "../common/timer.h" #include "../common/timer.h"
using namespace std;
#define FLAG_COMPRESSED 0x01 #define FLAG_COMPRESSED 0x01
#define FLAG_ENCODED 0x04 #define FLAG_ENCODED 0x04
@ -113,8 +111,8 @@ class EQStream : public EQStreamInterface {
Mutex MAcks; Mutex MAcks;
// Packets waiting to be sent (all protected by MOutboundQueue) // Packets waiting to be sent (all protected by MOutboundQueue)
queue<EQProtocolPacket *> NonSequencedQueue; std::queue<EQProtocolPacket *> NonSequencedQueue;
deque<EQProtocolPacket *> SequencedQueue; std::deque<EQProtocolPacket *> SequencedQueue;
uint16 NextOutSeq; uint16 NextOutSeq;
uint16 SequencedBase; //the sequence number of SequencedQueue[0] uint16 SequencedBase; //the sequence number of SequencedQueue[0]
long NextSequencedSend; //index into SequencedQueue long NextSequencedSend; //index into SequencedQueue
@ -124,8 +122,8 @@ class EQStream : public EQStreamInterface {
unsigned char _tempBuffer[2048]; unsigned char _tempBuffer[2048];
// Packets waiting to be processed // Packets waiting to be processed
vector<EQRawApplicationPacket *> InboundQueue; std::vector<EQRawApplicationPacket *> InboundQueue;
map<unsigned short,EQProtocolPacket *> PacketQueue; //not mutex protected, only accessed by caller of Process() std::map<unsigned short,EQProtocolPacket *> PacketQueue; //not mutex protected, only accessed by caller of Process()
Mutex MInboundQueue; Mutex MInboundQueue;
static uint16 MaxWindowSize; static uint16 MaxWindowSize;

View File

@ -19,8 +19,6 @@
#include "EQStream.h" #include "EQStream.h"
#include "logsys.h" #include "logsys.h"
using namespace std;
ThreadReturnType EQStreamFactoryReaderLoop(void *eqfs) ThreadReturnType EQStreamFactoryReaderLoop(void *eqfs)
{ {
EQStreamFactory *fs=(EQStreamFactory *)eqfs; EQStreamFactory *fs=(EQStreamFactory *)eqfs;
@ -146,7 +144,7 @@ void EQStreamFactory::Push(EQStream *s)
void EQStreamFactory::ReaderLoop() void EQStreamFactory::ReaderLoop()
{ {
fd_set readset; fd_set readset;
map<string,EQStream *>::iterator stream_itr; std::map<std::string,EQStream *>::iterator stream_itr;
int num; int num;
int length; int length;
unsigned char buffer[2048]; unsigned char buffer[2048];
@ -227,7 +225,7 @@ void EQStreamFactory::CheckTimeout()
MStreams.lock(); MStreams.lock();
unsigned long now=Timer::GetCurrentTime(); unsigned long now=Timer::GetCurrentTime();
map<string,EQStream *>::iterator stream_itr; std::map<std::string,EQStream *>::iterator stream_itr;
for(stream_itr=Streams.begin();stream_itr!=Streams.end();) { for(stream_itr=Streams.begin();stream_itr!=Streams.end();) {
EQStream *s = stream_itr->second; EQStream *s = stream_itr->second;
@ -243,7 +241,7 @@ void EQStreamFactory::CheckTimeout()
} else { } else {
//everybody is done, we can delete it now //everybody is done, we can delete it now
//cout << "Removing connection" << endl; //cout << "Removing connection" << endl;
map<string,EQStream *>::iterator temp=stream_itr; std::map<std::string,EQStream *>::iterator temp=stream_itr;
stream_itr++; stream_itr++;
//let whoever has the stream outside delete it //let whoever has the stream outside delete it
delete temp->second; delete temp->second;
@ -259,10 +257,10 @@ void EQStreamFactory::CheckTimeout()
void EQStreamFactory::WriterLoop() void EQStreamFactory::WriterLoop()
{ {
map<string,EQStream *>::iterator stream_itr; std::map<std::string,EQStream *>::iterator stream_itr;
bool havework=true; bool havework=true;
vector<EQStream *> wants_write; std::vector<EQStream *> wants_write;
vector<EQStream *>::iterator cur,end; std::vector<EQStream *>::iterator cur,end;
bool decay=false; bool decay=false;
uint32 stream_count; uint32 stream_count;

View File

@ -24,10 +24,10 @@ class EQStreamFactory : private Timeoutable {
EQStreamType StreamType; EQStreamType StreamType;
queue<EQStream *> NewStreams; std::queue<EQStream *> NewStreams;
Mutex MNewStreams; Mutex MNewStreams;
map<string,EQStream *> Streams; std::map<std::string,EQStream *> Streams;
Mutex MStreams; Mutex MStreams;
virtual void CheckTimeout(); virtual void CheckTimeout();

View File

@ -3,14 +3,12 @@
#include "EQStreamProxy.h" #include "EQStreamProxy.h"
#include "logsys.h" #include "logsys.h"
using namespace std;
EQStreamIdentifier::~EQStreamIdentifier() { EQStreamIdentifier::~EQStreamIdentifier() {
while(!m_identified.empty()) { while(!m_identified.empty()) {
m_identified.front()->ReleaseFromUse(); m_identified.front()->ReleaseFromUse();
m_identified.pop(); m_identified.pop();
} }
vector<Record *>::iterator cur, end; std::vector<Record *>::iterator cur, end;
cur = m_streams.begin(); cur = m_streams.begin();
end = m_streams.end(); end = m_streams.end();
for(; cur != end; cur++) { for(; cur != end; cur++) {
@ -18,7 +16,7 @@ EQStreamIdentifier::~EQStreamIdentifier() {
r->stream->ReleaseFromUse(); r->stream->ReleaseFromUse();
delete r; delete r;
} }
vector<Patch *>::iterator curp, endp; std::vector<Patch *>::iterator curp, endp;
curp = m_patches.begin(); curp = m_patches.begin();
endp = m_patches.end(); endp = m_patches.end();
for(; curp != endp; curp++) { for(; curp != endp; curp++) {
@ -36,8 +34,8 @@ void EQStreamIdentifier::RegisterPatch(const EQStream::Signature &sig, const cha
} }
void EQStreamIdentifier::Process() { void EQStreamIdentifier::Process() {
vector<Record *>::iterator cur; std::vector<Record *>::iterator cur;
vector<Patch *>::iterator curp, endp; std::vector<Patch *>::iterator curp, endp;
//foreach pending stream. //foreach pending stream.
cur = m_streams.begin(); cur = m_streams.begin();

View File

@ -24,7 +24,6 @@ This did not turn out nearly as nice as I hoped.
#include <map> #include <map>
#include <string> #include <string>
using namespace std;
class EQStreamInfo { class EQStreamInfo {
public: public:
@ -103,7 +102,7 @@ inline bool operator==(const EQStreamInfo &l, const EQStreamInfo &r) {
template <class T> template <class T>
class EQStreamLocator { class EQStreamLocator {
protected: protected:
typedef typename map<const EQStreamInfo, T *>::iterator iterator; typedef typename std::map<const EQStreamInfo, T *>::iterator iterator;
public: public:
void Clear() { void Clear() {
@ -167,7 +166,7 @@ public:
// inline iterator end() const { return(streams.end()); } // inline iterator end() const { return(streams.end()); }
protected: protected:
map<const EQStreamInfo, T *> streams; std::map<const EQStreamInfo, T *> streams;
}; };
#endif #endif

View File

@ -26,11 +26,9 @@ tremendously.
#include "../common/debug.h" #include "../common/debug.h"
#include <iostream> #include <iostream>
using namespace std;
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <iomanip> #include <iomanip>
using namespace std;
#include "EmuTCPConnection.h" #include "EmuTCPConnection.h"
#include "EmuTCPServer.h" #include "EmuTCPServer.h"
@ -93,7 +91,7 @@ EmuTCPConnection::EmuTCPConnection(bool iOldFormat, EmuTCPServer* iRelayServer,
TCPMode = iMode; TCPMode = iMode;
PacketMode = packetModeZone; PacketMode = packetModeZone;
#if TCPN_DEBUG_Memory >= 7 #if TCPN_DEBUG_Memory >= 7
cout << "Constructor #1 on outgoing TCP# " << GetID() << endl; std::cout << "Constructor #1 on outgoing TCP# " << GetID() << std::endl;
#endif #endif
} }
@ -113,7 +111,7 @@ EmuTCPConnection::EmuTCPConnection(uint32 ID, EmuTCPServer* iServer, EmuTCPConne
TCPMode = modePacket; TCPMode = modePacket;
PacketMode = packetModeZone; PacketMode = packetModeZone;
#if TCPN_DEBUG_Memory >= 7 #if TCPN_DEBUG_Memory >= 7
cout << "Constructor #3 on outgoing TCP# " << GetID() << endl; std::cout << "Constructor #3 on outgoing TCP# " << GetID() << std::endl;
#endif #endif
} }
@ -173,7 +171,7 @@ bool EmuTCPConnection::SendPacket(ServerPacket* pack, uint32 iDestination) {
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
CoutTimestamp(true); CoutTimestamp(true);
cout << ": Logging outgoing TCP OldPacket. OPCode: 0x" << hex << setw(4) << setfill('0') << pack->opcode << dec << ", size: " << setw(5) << setfill(' ') << pack->size << " " << inet_ntoa(in) << ":" << GetrPort() << endl; std::cout << ": Logging outgoing TCP OldPacket. OPCode: 0x" << hex << setw(4) << setfill('0') << pack->opcode << dec << ", size: " << setw(5) << setfill(' ') << pack->size << " " << inet_ntoa(in) << ":" << GetrPort() << std::endl;
#if TCPN_LOG_PACKETS == 2 #if TCPN_LOG_PACKETS == 2
if (pack->size >= 32) if (pack->size >= 32)
DumpPacket(pack->pBuffer, 32); DumpPacket(pack->pBuffer, 32);
@ -200,7 +198,7 @@ bool EmuTCPConnection::SendPacket(ServerPacket* pack, uint32 iDestination) {
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
CoutTimestamp(true); CoutTimestamp(true);
cout << ": Logging outgoing TCP packet. OPCode: 0x" << hex << setw(4) << setfill('0') << pack->opcode << dec << ", size: " << setw(5) << setfill(' ') << pack->size << " " << inet_ntoa(in) << ":" << GetrPort() << endl; std::cout << ": Logging outgoing TCP packet. OPCode: 0x" << hex << setw(4) << setfill('0') << pack->opcode << dec << ", size: " << setw(5) << setfill(' ') << pack->size << " " << inet_ntoa(in) << ":" << GetrPort() << std::endl;
#if TCPN_LOG_PACKETS == 2 #if TCPN_LOG_PACKETS == 2
if (pack->size >= 32) if (pack->size >= 32)
DumpPacket(pack->pBuffer, 32); DumpPacket(pack->pBuffer, 32);
@ -239,10 +237,10 @@ bool EmuTCPConnection::SendPacket(EmuTCPNetPacket_Struct* tnps) {
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
CoutTimestamp(true); CoutTimestamp(true);
cout << ": Logging outgoing TCP NetPacket. OPCode: 0x" << hex << setw(4) << setfill('0') << tnps->opcode << dec << ", size: " << setw(5) << setfill(' ') << tnps->size << " " << inet_ntoa(in) << ":" << GetrPort(); std::cout << ": Logging outgoing TCP NetPacket. OPCode: 0x" << hex << setw(4) << setfill('0') << tnps->opcode << dec << ", size: " << setw(5) << setfill(' ') << tnps->size << " " << inet_ntoa(in) << ":" << GetrPort();
if (pOldFormat) if (pOldFormat)
cout << " (OldFormat)"; std::cout << " (OldFormat)";
cout << endl; std::cout << std::endl;
#if TCPN_LOG_PACKETS == 2 #if TCPN_LOG_PACKETS == 2
if (tnps->size >= 32) if (tnps->size >= 32)
DumpPacket((uchar*) tnps, 32); DumpPacket((uchar*) tnps, 32);
@ -284,7 +282,7 @@ bool EmuTCPConnection::LineOutQueuePush(char* line) {
#if defined(GOTFRAGS) && 0 #if defined(GOTFRAGS) && 0
if (strcmp(line, "**CRASHME**") == 0) { if (strcmp(line, "**CRASHME**") == 0) {
int i = 0; int i = 0;
cout << (5 / i) << endl; std::cout << (5 / i) << std::endl;
} }
#endif #endif
if(line[0] == '*') { if(line[0] == '*') {
@ -456,10 +454,10 @@ void EmuTCPConnection::SendNetErrorPacket(const char* reason) {
#if TCPC_DEBUG >= 1 #if TCPC_DEBUG >= 1
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
cout "NetError: '"; std::cout "NetError: '";
if (reason) if (reason)
cout << reason; std::cout << reason;
cout << "': " << inet_ntoa(in) << ":" << GetPort() << endl; std::cout << "': " << inet_ntoa(in) << ":" << GetPort() << std::endl;
#endif #endif
ServerPacket* pack = new ServerPacket(0); ServerPacket* pack = new ServerPacket(0);
pack->size = 1; pack->size = 1;
@ -522,7 +520,7 @@ bool EmuTCPConnection::ProcessReceivedDataAsPackets(char* errbuf) {
size = tnps->size; size = tnps->size;
if (size >= MaxTCPReceiveBuffferSize) { if (size >= MaxTCPReceiveBuffferSize) {
#if TCPN_DEBUG_Memory >= 1 #if TCPN_DEBUG_Memory >= 1
cout << "TCPConnection[" << GetID() << "]::ProcessReceivedDataAsPackets(): size[" << size << "] >= MaxTCPReceiveBuffferSize" << endl; std::cout << "TCPConnection[" << GetID() << "]::ProcessReceivedDataAsPackets(): size[" << size << "] >= MaxTCPReceiveBuffferSize" << std::endl;
DumpPacket(&recvbuf[base], 16); DumpPacket(&recvbuf[base], 16);
#endif #endif
if (errbuf) if (errbuf)
@ -562,13 +560,13 @@ bool EmuTCPConnection::ProcessReceivedDataAsPackets(char* errbuf) {
if (pack->opcode == 0) { if (pack->opcode == 0) {
if (pack->size) { if (pack->size) {
#if TCPN_DEBUG >= 2 #if TCPN_DEBUG >= 2
cout << "Received TCP Network layer packet" << endl; std::cout << "Received TCP Network layer packet" << std::endl;
#endif #endif
ProcessNetworkLayerPacket(pack); ProcessNetworkLayerPacket(pack);
} }
#if TCPN_DEBUG >= 5 #if TCPN_DEBUG >= 5
else { else {
cout << "Received TCP keepalive packet. (opcode=0)" << endl; std::cout << "Received TCP keepalive packet. (opcode=0)" << std::endl;
} }
#endif #endif
// keepalive, no need to process // keepalive, no need to process
@ -580,7 +578,7 @@ bool EmuTCPConnection::ProcessReceivedDataAsPackets(char* errbuf) {
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
CoutTimestamp(true); CoutTimestamp(true);
cout << ": Logging incoming TCP packet. OPCode: 0x" << hex << setw(4) << setfill('0') << pack->opcode << dec << ", size: " << setw(5) << setfill(' ') << pack->size << " " << inet_ntoa(in) << ":" << GetrPort() << endl; std::cout << ": Logging incoming TCP packet. OPCode: 0x" << hex << setw(4) << setfill('0') << pack->opcode << dec << ", size: " << setw(5) << setfill(' ') << pack->size << " " << inet_ntoa(in) << ":" << GetrPort() << std::endl;
#if TCPN_LOG_PACKETS == 2 #if TCPN_LOG_PACKETS == 2
if (pack->size >= 32) if (pack->size >= 32)
DumpPacket(pack->pBuffer, 32); DumpPacket(pack->pBuffer, 32);
@ -596,7 +594,7 @@ bool EmuTCPConnection::ProcessReceivedDataAsPackets(char* errbuf) {
EmuTCPConnection* con = Server->FindConnection(pack->destination); EmuTCPConnection* con = Server->FindConnection(pack->destination);
if (!con) { if (!con) {
#if TCPN_DEBUG >= 1 #if TCPN_DEBUG >= 1
cout << "Error relaying packet: con = 0" << endl; std::cout << "Error relaying packet: con = 0" << std::endl;
#endif #endif
safe_delete(pack); safe_delete(pack);
} }
@ -635,7 +633,7 @@ bool EmuTCPConnection::ProcessReceivedDataAsOldPackets(char* errbuf) {
memcpy(&size, &buffer[2], 2); memcpy(&size, &buffer[2], 2);
if (size >= MaxTCPReceiveBuffferSize) { if (size >= MaxTCPReceiveBuffferSize) {
#if TCPN_DEBUG_Memory >= 1 #if TCPN_DEBUG_Memory >= 1
cout << "TCPConnection[" << GetID() << "]::ProcessReceivedDataAsPackets(): size[" << size << "] >= MaxTCPReceiveBuffferSize" << endl; std::cout << "TCPConnection[" << GetID() << "]::ProcessReceivedDataAsPackets(): size[" << size << "] >= MaxTCPReceiveBuffferSize" << std::endl;
#endif #endif
if (errbuf) if (errbuf)
snprintf(errbuf, TCPConnection_ErrorBufferSize, "EmuTCPConnection::ProcessReceivedDataAsPackets(): size >= MaxTCPReceiveBuffferSize"); snprintf(errbuf, TCPConnection_ErrorBufferSize, "EmuTCPConnection::ProcessReceivedDataAsPackets(): size >= MaxTCPReceiveBuffferSize");
@ -665,7 +663,7 @@ bool EmuTCPConnection::ProcessReceivedDataAsOldPackets(char* errbuf) {
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
CoutTimestamp(true); CoutTimestamp(true);
cout << ": Logging incoming TCP OldPacket. OPCode: 0x" << hex << setw(4) << setfill('0') << pack->opcode << dec << ", size: " << setw(5) << setfill(' ') << pack->size << " " << inet_ntoa(in) << ":" << GetrPort() << endl; std::cout << ": Logging incoming TCP OldPacket. OPCode: 0x" << hex << setw(4) << setfill('0') << pack->opcode << dec << ", size: " << setw(5) << setfill(' ') << pack->size << " " << inet_ntoa(in) << ":" << GetrPort() << std::endl;
#if TCPN_LOG_PACKETS == 2 #if TCPN_LOG_PACKETS == 2
if (pack->size >= 32) if (pack->size >= 32)
DumpPacket(pack->pBuffer, 32); DumpPacket(pack->pBuffer, 32);
@ -726,7 +724,7 @@ void EmuTCPConnection::ProcessNetworkLayerPacket(ServerPacket* pack) {
#if TCPC_DEBUG >= 3 #if TCPC_DEBUG >= 3
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
cout << "Switching to RelayServer mode: " << inet_ntoa(in) << ":" << GetPort() << endl; std::cout << "Switching to RelayServer mode: " << inet_ntoa(in) << ":" << GetPort() << std::endl;
#endif #endif
RelayServer = true; RelayServer = true;
break; break;
@ -774,10 +772,10 @@ void EmuTCPConnection::ProcessNetworkLayerPacket(ServerPacket* pack) {
#if TCPC_DEBUG >= 1 #if TCPC_DEBUG >= 1
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
cout "Received NetError: '"; std::cout "Received NetError: '";
if (pack->size > 1) if (pack->size > 1)
cout << (char*) data; std::cout << (char*) data;
cout << "': " << inet_ntoa(in) << ":" << GetPort() << endl; std::cout << "': " << inet_ntoa(in) << ":" << GetPort() << std::endl;
#endif #endif
break; break;
} }
@ -796,7 +794,7 @@ bool EmuTCPConnection::SendData(bool &sent_something, char* errbuf) {
SendPacket(pack); SendPacket(pack);
safe_delete(pack); safe_delete(pack);
#if TCPN_DEBUG >= 5 #if TCPN_DEBUG >= 5
cout << "Sending TCP keepalive packet. (timeout=" << timeout_timer.GetRemainingTime() << " remaining)" << endl; std::cout << "Sending TCP keepalive packet. (timeout=" << timeout_timer.GetRemainingTime() << " remaining)" << std::endl;
#endif #endif
} }

View File

@ -16,27 +16,19 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifdef _WINDOWS #include "debug.h"
// VS6 doesn't like the length of STL generated names: disabling #include "StringUtil.h"
#pragma warning(disable:4786)
// Quagmire: Dont know why the one in debug.h doesnt work, but it doesnt.
#endif
#include "../common/debug.h"
/*#ifdef _CRTDBG_MAP_ALLOC
#undef new
#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
#endif
*/
#include <sstream>
#include <iostream>
#include <limits.h>
#include "Item.h" #include "Item.h"
#include "database.h" #include "database.h"
#include "misc.h" #include "misc.h"
#include "races.h" #include "races.h"
#include "shareddb.h" #include "shareddb.h"
#include "classes.h" #include "classes.h"
using namespace std;
#include <limits.h>
#include <sstream>
#include <iostream>
int32 NextItemInstSerialNumber = 1; int32 NextItemInstSerialNumber = 1;
@ -102,7 +94,7 @@ ItemInstQueue::~ItemInstQueue() {
} }
Inventory::~Inventory() { Inventory::~Inventory() {
map<int16, ItemInst*>::iterator cur,end; std::map<int16, ItemInst*>::iterator cur,end;
cur = m_worn.begin(); cur = m_worn.begin();
@ -580,7 +572,7 @@ ItemInst* Inventory::GetItem(int16 slot_id) const
std::string ItemInst::GetCustomDataString() const { std::string ItemInst::GetCustomDataString() const {
std::string ret_val; std::string ret_val;
map<std::string, std::string>::const_iterator iter = m_custom_data.begin(); std::map<std::string, std::string>::const_iterator iter = m_custom_data.begin();
while(iter != m_custom_data.end()) { while(iter != m_custom_data.end()) {
if(ret_val.length() > 0) { if(ret_val.length() > 0) {
ret_val += "^"; ret_val += "^";
@ -624,14 +616,14 @@ void ItemInst::SetCustomData(std::string identifier, bool value) {
} }
void ItemInst::DeleteCustomData(std::string identifier) { void ItemInst::DeleteCustomData(std::string identifier) {
map<std::string, std::string>::iterator iter = m_custom_data.find(identifier); std::map<std::string, std::string>::iterator iter = m_custom_data.find(identifier);
if(iter != m_custom_data.end()) { if(iter != m_custom_data.end()) {
m_custom_data.erase(iter); m_custom_data.erase(iter);
} }
} }
std::string ItemInst::GetCustomData(std::string identifier) { std::string ItemInst::GetCustomData(std::string identifier) {
map<std::string, std::string>::const_iterator iter = m_custom_data.find(identifier); std::map<std::string, std::string>::const_iterator iter = m_custom_data.find(identifier);
if(iter != m_custom_data.end()) { if(iter != m_custom_data.end()) {
return iter->second; return iter->second;
} }
@ -1060,107 +1052,79 @@ int16 Inventory::FindFreeSlot(bool for_bag, bool try_cursor, uint8 min_size, boo
return SLOT_INVALID; return SLOT_INVALID;
} }
void Inventory::dumpInventory() { void Inventory::dumpBagContents(ItemInst *inst, iter_inst *it) {
iter_contents itb;
if (!inst || !inst->IsType(ItemClassContainer))
return;
// Go through bag, if bag
for (itb=inst->_begin(); itb!=inst->_end(); itb++) {
ItemInst* baginst = itb->second;
if(!baginst || !baginst->GetItem())
continue;
std::string subSlot;
StringFormat(subSlot," Slot %d: %s (%d)", Inventory::CalcSlotId((*it)->first, itb->first),
baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges());
std::cout << subSlot << std::endl;
}
}
void Inventory::dumpItemCollection(const std::map<int16, ItemInst*> &collection) {
iter_inst it; iter_inst it;
iter_contents itb; iter_contents itb;
ItemInst* inst = nullptr; ItemInst* inst = nullptr;
// Check item: After failed checks, check bag contents (if bag) for (it=collection.begin(); it!=collection.end(); it++) {
printf("Worn items:\n");
for (it=m_worn.begin(); it!=m_worn.end(); it++) {
inst = it->second; inst = it->second;
it->first; it->first;
if(!inst || !inst->GetItem()) if(!inst || !inst->GetItem())
continue; continue;
std::string slot;
StringFormat(slot, "Slot %d: %s (%d)",it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges());
std::cout << slot << std::endl;
printf("Slot %d: %s (%d)\n", it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges()); dumpBagContents(inst, &it);
// Go through bag, if bag
if (inst && inst->IsType(ItemClassContainer)) {
for (itb=inst->_begin(); itb!=inst->_end(); itb++) {
ItemInst* baginst = itb->second;
if(!baginst || !baginst->GetItem())
continue;
printf(" Slot %d: %s (%d)\n", Inventory::CalcSlotId(it->first, itb->first),
baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges());
}
}
} }
}
printf("Inventory items:\n"); void Inventory::dumpWornItems() {
for (it=m_inv.begin(); it!=m_inv.end(); it++) { std::cout << "Worn items:" << std::endl;
inst = it->second; dumpItemCollection(m_worn);
it->first; }
if(!inst || !inst->GetItem())
continue;
printf("Slot %d: %s (%d)\n", it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges()); void Inventory::dumpInventory() {
std::cout << "Inventory items:" << std::endl;
dumpItemCollection(m_inv);
}
// Go through bag, if bag void Inventory::dumpBankItems() {
if (inst && inst->IsType(ItemClassContainer)) {
for (itb=inst->_begin(); itb!=inst->_end(); itb++) { std::cout << "Bank items:" << std::endl;
ItemInst* baginst = itb->second; dumpItemCollection(m_bank);
if(!baginst || !baginst->GetItem()) }
continue;
printf(" Slot %d: %s (%d)\n", Inventory::CalcSlotId(it->first, itb->first),
baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges());
} void Inventory::dumpSharedBankItems() {
}
} std::cout << "Shared Bank items:" << std::endl;
dumpItemCollection(m_shbank);
}
printf("Bank items:\n"); void Inventory::dumpEntireInventory() {
for (it=m_bank.begin(); it!=m_bank.end(); it++) {
inst = it->second;
it->first;
if(!inst || !inst->GetItem())
continue;
printf("Slot %d: %s (%d)\n", it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges()); dumpWornItems();
dumpInventory();
// Go through bag, if bag dumpBankItems();
if (inst && inst->IsType(ItemClassContainer)) { dumpSharedBankItems();
for (itb=inst->_begin(); itb!=inst->_end(); itb++) { std::cout << std::endl;
ItemInst* baginst = itb->second;
if(!baginst || !baginst->GetItem())
continue;
printf(" Slot %d: %s (%d)\n", Inventory::CalcSlotId(it->first, itb->first),
baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges());
}
}
}
printf("Shared Bank items:\n");
for (it=m_shbank.begin(); it!=m_shbank.end(); it++) {
inst = it->second;
it->first;
if(!inst || !inst->GetItem())
continue;
printf("Slot %d: %s (%d)\n", it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges());
// Go through bag, if bag
if (inst && inst->IsType(ItemClassContainer)) {
for (itb=inst->_begin(); itb!=inst->_end(); itb++) {
ItemInst* baginst = itb->second;
if(!baginst || !baginst->GetItem())
continue;
printf(" Slot %d: %s (%d)\n", Inventory::CalcSlotId(it->first, itb->first),
baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges());
}
}
}
printf("\n");
fflush(stdout);
} }
// Internal Method: Retrieves item within an inventory bucket // Internal Method: Retrieves item within an inventory bucket
ItemInst* Inventory::_GetItem(const map<int16, ItemInst*>& bucket, int16 slot_id) const ItemInst* Inventory::_GetItem(const std::map<int16, ItemInst*>& bucket, int16 slot_id) const
{ {
iter_inst it = bucket.find(slot_id); iter_inst it = bucket.find(slot_id);
if (it != bucket.end()) { if (it != bucket.end()) {
@ -1228,7 +1192,7 @@ int16 Inventory::_PutItem(int16 slot_id, ItemInst* inst)
} }
// Internal Method: Checks an inventory bucket for a particular item // Internal Method: Checks an inventory bucket for a particular item
int16 Inventory::_HasItem(map<int16, ItemInst*>& bucket, uint32 item_id, uint8 quantity) int16 Inventory::_HasItem(std::map<int16, ItemInst*>& bucket, uint32 item_id, uint8 quantity)
{ {
iter_inst it; iter_inst it;
iter_contents itb; iter_contents itb;
@ -1318,7 +1282,7 @@ int16 Inventory::_HasItem(ItemInstQueue& iqueue, uint32 item_id, uint8 quantity)
} }
// Internal Method: Checks an inventory bucket for a particular item // Internal Method: Checks an inventory bucket for a particular item
int16 Inventory::_HasItemByUse(map<int16, ItemInst*>& bucket, uint8 use, uint8 quantity) int16 Inventory::_HasItemByUse(std::map<int16, ItemInst*>& bucket, uint8 use, uint8 quantity)
{ {
iter_inst it; iter_inst it;
iter_contents itb; iter_contents itb;
@ -1386,7 +1350,7 @@ int16 Inventory::_HasItemByUse(ItemInstQueue& iqueue, uint8 use, uint8 quantity)
return SLOT_INVALID; return SLOT_INVALID;
} }
int16 Inventory::_HasItemByLoreGroup(map<int16, ItemInst*>& bucket, uint32 loregroup) int16 Inventory::_HasItemByLoreGroup(std::map<int16, ItemInst*>& bucket, uint32 loregroup)
{ {
iter_inst it; iter_inst it;
iter_contents itb; iter_contents itb;

View File

@ -34,15 +34,14 @@ class EvolveInfo; // Stores information about an evolving item family
#include <vector> #include <vector>
#include <map> #include <map>
#include <list> #include <list>
using namespace std;
#include "../common/eq_packet_structs.h" #include "../common/eq_packet_structs.h"
#include "../common/eq_constants.h" #include "../common/eq_constants.h"
#include "../common/item_struct.h" #include "../common/item_struct.h"
// Helper typedefs // Helper typedefs
typedef list<ItemInst*>::const_iterator iter_queue; typedef std::list<ItemInst*>::const_iterator iter_queue;
typedef map<int16, ItemInst*>::const_iterator iter_inst; typedef std::map<int16, ItemInst*>::const_iterator iter_inst;
typedef map<uint8, ItemInst*>::const_iterator iter_contents; typedef std::map<uint8, ItemInst*>::const_iterator iter_contents;
namespace ItemField { namespace ItemField {
enum { enum {
@ -120,7 +119,7 @@ protected:
// Protected Members // Protected Members
///////////////////////// /////////////////////////
list<ItemInst*> m_list; std::list<ItemInst*> m_list;
}; };
@ -196,7 +195,11 @@ public:
// Test whether a given slot can support a container item // Test whether a given slot can support a container item
static bool SupportsContainers(int16 slot_id); static bool SupportsContainers(int16 slot_id);
void dumpEntireInventory();
void dumpWornItems();
void dumpInventory(); void dumpInventory();
void dumpBankItems();
void dumpSharedBankItems();
void SetCustomItemData(uint32 character_id, int16 slot_id, std::string identifier, std::string value); void SetCustomItemData(uint32 character_id, int16 slot_id, std::string identifier, std::string value);
void SetCustomItemData(uint32 character_id, int16 slot_id, std::string identifier, int value); void SetCustomItemData(uint32 character_id, int16 slot_id, std::string identifier, int value);
@ -208,27 +211,30 @@ protected:
// Protected Methods // Protected Methods
/////////////////////////////// ///////////////////////////////
void dumpItemCollection(const std::map<int16, ItemInst*> &collection);
void dumpBagContents(ItemInst *inst, iter_inst *it);
// Retrieves item within an inventory bucket // Retrieves item within an inventory bucket
ItemInst* _GetItem(const map<int16, ItemInst*>& bucket, int16 slot_id) const; ItemInst* _GetItem(const std::map<int16, ItemInst*>& bucket, int16 slot_id) const;
// Private "put" item into bucket, without regard for what is currently in bucket // Private "put" item into bucket, without regard for what is currently in bucket
int16 _PutItem(int16 slot_id, ItemInst* inst); int16 _PutItem(int16 slot_id, ItemInst* inst);
// Checks an inventory bucket for a particular item // Checks an inventory bucket for a particular item
int16 _HasItem(map<int16, ItemInst*>& bucket, uint32 item_id, uint8 quantity); int16 _HasItem(std::map<int16, ItemInst*>& bucket, uint32 item_id, uint8 quantity);
int16 _HasItem(ItemInstQueue& iqueue, uint32 item_id, uint8 quantity); int16 _HasItem(ItemInstQueue& iqueue, uint32 item_id, uint8 quantity);
int16 _HasItemByUse(map<int16, ItemInst*>& bucket, uint8 use, uint8 quantity); int16 _HasItemByUse(std::map<int16, ItemInst*>& bucket, uint8 use, uint8 quantity);
int16 _HasItemByUse(ItemInstQueue& iqueue, uint8 use, uint8 quantity); int16 _HasItemByUse(ItemInstQueue& iqueue, uint8 use, uint8 quantity);
int16 _HasItemByLoreGroup(map<int16, ItemInst*>& bucket, uint32 loregroup); int16 _HasItemByLoreGroup(std::map<int16, ItemInst*>& bucket, uint32 loregroup);
int16 _HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 loregroup); int16 _HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 loregroup);
// Player inventory // Player inventory
map<int16, ItemInst*> m_worn; // Items worn by character std::map<int16, ItemInst*> m_worn; // Items worn by character
map<int16, ItemInst*> m_inv; // Items in character personal inventory std::map<int16, ItemInst*> m_inv; // Items in character personal inventory
map<int16, ItemInst*> m_bank; // Items in character bank std::map<int16, ItemInst*> m_bank; // Items in character bank
map<int16, ItemInst*> m_shbank; // Items in character shared bank std::map<int16, ItemInst*> m_shbank; // Items in character shared bank
map<int16, ItemInst*> m_trade; // Items in a trade session std::map<int16, ItemInst*> m_trade; // Items in a trade session
ItemInstQueue m_cursor; // Items on cursor: FIFO ItemInstQueue m_cursor; // Items on cursor: FIFO
}; };
@ -300,7 +306,7 @@ public:
uint8 FirstOpenSlot() const; uint8 FirstOpenSlot() const;
uint8 GetTotalItemCount() const; uint8 GetTotalItemCount() const;
bool IsNoneEmptyContainer(); bool IsNoneEmptyContainer();
map<uint8, ItemInst*>* GetContents() { return &m_contents; } std::map<uint8, ItemInst*>* GetContents() { return &m_contents; }
// //
// Augments // Augments
@ -371,7 +377,7 @@ public:
virtual bool IsScaling() const { return false; } virtual bool IsScaling() const { return false; }
virtual bool IsEvolving() const { return false; } virtual bool IsEvolving() const { return false; }
string Serialize(int16 slot_id) const { InternalSerializedItem_Struct s; s.slot_id=slot_id; s.inst=(const void *)this; string ser; ser.assign((char *)&s,sizeof(InternalSerializedItem_Struct)); return ser; } std::string Serialize(int16 slot_id) const { InternalSerializedItem_Struct s; s.slot_id=slot_id; s.inst=(const void *)this; std::string ser; ser.assign((char *)&s,sizeof(InternalSerializedItem_Struct)); return ser; }
inline int32 GetSerialNumber() const { return m_SerialNumber; } inline int32 GetSerialNumber() const { return m_SerialNumber; }
inline void SetSerialNumber(int32 id) { m_SerialNumber = id; } inline void SetSerialNumber(int32 id) { m_SerialNumber = id; }
@ -399,8 +405,8 @@ protected:
int32 m_SerialNumber; // Unique identifier for this instance of an item. Needed for Bazaar. int32 m_SerialNumber; // Unique identifier for this instance of an item. Needed for Bazaar.
// //
// Items inside of this item (augs or contents); // Items inside of this item (augs or contents);
map<uint8, ItemInst*> m_contents; // Zero-based index: min=0, max=9 std::map<uint8, ItemInst*> m_contents; // Zero-based index: min=0, max=9
map<std::string, std::string> m_custom_data; std::map<std::string, std::string> m_custom_data;
}; };
class EvoItemInst: public ItemInst { class EvoItemInst: public ItemInst {

View File

@ -32,15 +32,10 @@
#include "../common/timer.h" #include "../common/timer.h"
#include "../common/seperator.h" #include "../common/seperator.h"
using namespace std;
#ifdef _WINDOWS #ifdef _WINDOWS
#include <windows.h> #include <windows.h>
#define snprintf _snprintf #define snprintf _snprintf
#if (_MSC_VER < 1500)
#define vsnprintf _vsnprintf
#endif
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#define strcasecmp _stricmp #define strcasecmp _stricmp
#else #else
@ -59,10 +54,6 @@ using namespace std;
#include <errno.h> #include <errno.h>
#endif #endif
#ifndef va_copy
#define va_copy(d,s) ((d) = (s))
#endif
static bool WELLRNG_init = false; static bool WELLRNG_init = false;
static int state_i = 0; static int state_i = 0;
static unsigned int STATE[R]; static unsigned int STATE[R];
@ -86,207 +77,12 @@ void CoutTimestamp(bool ms) {
struct timeval read_time; struct timeval read_time;
gettimeofday(&read_time,0); 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; std::cout << (gmt_t->tm_year + 1900) << "/" << std::setw(2) << std::setfill('0') << (gmt_t->tm_mon + 1) << "/" << std::setw(2) << std::setfill('0') << gmt_t->tm_mday << " " << std::setw(2) << std::setfill('0') << gmt_t->tm_hour << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_min << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_sec;
if (ms) if (ms)
cout << "." << setw(3) << setfill('0') << (read_time.tv_usec / 1000); std::cout << "." << std::setw(3) << std::setfill('0') << (read_time.tv_usec / 1000);
cout << " GMT"; std::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) { int32 filesize(FILE* fp) {
#ifdef _WINDOWS #ifdef _WINDOWS
@ -549,40 +345,6 @@ static unsigned int case_6 (void){
// end WELL RNG code // 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)
{
sprintf(returnchar, "%i" ,input);
return returnchar;
}
const char *ConvertArrayF(float input, char *returnchar)
{
sprintf(returnchar, "%0.2f", input);
return returnchar;
}
float EQ13toFloat(int d) float EQ13toFloat(int d)
{ {
@ -627,24 +389,3 @@ float EQHtoFloat(int d)
{ {
return(360.0f - float((d * 360) >> 11)); 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;
}

View File

@ -34,7 +34,7 @@
// //
#define VARSTRUCT_DECODE_TYPE(Type, Buffer) *(Type *)Buffer; Buffer += sizeof(Type); #define VARSTRUCT_DECODE_TYPE(Type, Buffer) *(Type *)Buffer; Buffer += sizeof(Type);
#define VARSTRUCT_DECODE_STRING(String, Buffer) strcpy(String, Buffer); Buffer += strlen(String)+1; #define VARSTRUCT_DECODE_STRING(String, Buffer) strcpy(String, Buffer); Buffer += strlen(String)+1;
#define VARSTRUCT_ENCODE_STRING(Buffer, String) { sprintf(Buffer, String); Buffer += strlen(String) + 1; } #define VARSTRUCT_ENCODE_STRING(Buffer, String) { sprintf(Buffer, "%s", String); Buffer += strlen(String) + 1; }
#define VARSTRUCT_ENCODE_INTSTRING(Buffer, Number) { sprintf(Buffer, "%i", Number); Buffer += strlen(Buffer) + 1; } #define VARSTRUCT_ENCODE_INTSTRING(Buffer, Number) { sprintf(Buffer, "%i", Number); Buffer += strlen(Buffer) + 1; }
#define VARSTRUCT_ENCODE_TYPE(Type, Buffer, Value) { *(Type *)Buffer = Value; Buffer += sizeof(Type); } #define VARSTRUCT_ENCODE_TYPE(Type, Buffer, Value) { *(Type *)Buffer = Value; Buffer += sizeof(Type); }
#define VARSTRUCT_SKIP_TYPE(Type, Buffer) Buffer += sizeof(Type); #define VARSTRUCT_SKIP_TYPE(Type, Buffer) Buffer += sizeof(Type);
@ -86,39 +86,14 @@
#define BITMASK 0x41180000 #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); int32 filesize(FILE* fp);
uint32 ResolveIP(const char* hostname, char* errbuf = 0); uint32 ResolveIP(const char* hostname, char* errbuf = 0);
bool ParseAddress(const char* iAddress, uint32* oIP, uint16* oPort, char* errbuf = 0); bool ParseAddress(const char* iAddress, uint32* oIP, uint16* oPort, char* errbuf = 0);
void CoutTimestamp(bool ms = true); 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); int MakeRandomInt(int low, int high);
double MakeRandomFloat(double low, double 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); float EQ13toFloat(int d);
float NewEQ13toFloat(int d); float NewEQ13toFloat(int d);
float EQ19toFloat(int d); float EQ19toFloat(int d);
@ -127,8 +102,6 @@ int FloatToEQ13(float d);
int NewFloatToEQ13(float d); int NewFloatToEQ13(float d);
int FloatToEQ19(float d); int FloatToEQ19(float d);
int FloatToEQH(float d); int FloatToEQH(float d);
void RemoveApostrophes(std::string &s);
char *RemoveApostrophes(const char *s);

View File

@ -19,7 +19,6 @@
#include "../common/Mutex.h" #include "../common/Mutex.h"
#include <iostream> #include <iostream>
using namespace std;
#define DEBUG_MUTEX_CLASS 0 #define DEBUG_MUTEX_CLASS 0
#if DEBUG_MUTEX_CLASS >= 1 #if DEBUG_MUTEX_CLASS >= 1
@ -43,7 +42,7 @@ bool IsTryLockSupported() {
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) { if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) {
#if DEBUG_MUTEX_CLASS >= 1 #if DEBUG_MUTEX_CLASS >= 1
cout << "Mutex::trylock() NOT supported" << endl; std::cout << "Mutex::trylock() NOT supported" << std::endl;
#endif #endif
return false; return false;
} }
@ -52,13 +51,13 @@ bool IsTryLockSupported() {
// Tests for Windows NT product family. // Tests for Windows NT product family.
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion >= 4) { if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion >= 4) {
#if DEBUG_MUTEX_CLASS >= 1 #if DEBUG_MUTEX_CLASS >= 1
cout << "Mutex::trylock() SUPPORTED" << endl; std::cout << "Mutex::trylock() SUPPORTED" << std::endl;
#endif #endif
return true; return true;
} }
else { else {
#if DEBUG_MUTEX_CLASS >= 1 #if DEBUG_MUTEX_CLASS >= 1
cout << "Mutex::trylock() NOT supported" << endl; std::cout << "Mutex::trylock() NOT supported" << std::endl;
#endif #endif
return false; return false;
} }
@ -66,27 +65,28 @@ bool IsTryLockSupported() {
#endif #endif
Mutex::Mutex() { Mutex::Mutex() {
#if DEBUG_MUTEX_CLASS >= 7 #if DEBUG_MUTEX_CLASS >= 7
cout << "Constructing Mutex" << endl; std::cout << "Constructing Mutex" << std::endl;
#endif #endif
#ifdef _WINDOWS #ifdef _WINDOWS
InitializeCriticalSection(&CSMutex); InitializeCriticalSection(&CSMutex);
#else #else
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr); pthread_mutexattr_init(&attr);
#if defined(__CYGWIN__) || defined(__APPLE__) || defined(FREEBSD) #if defined(__CYGWIN__) || defined(__APPLE__) || defined(FREEBSD)
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
#else #else
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
#endif #endif
pthread_mutex_init(&CSMutex, &attr); pthread_mutex_init(&CSMutex, &attr);
pthread_mutexattr_destroy(&attr); pthread_mutexattr_destroy(&attr);
#endif #endif
} }
Mutex::~Mutex() { Mutex::~Mutex() {
#if DEBUG_MUTEX_CLASS >= 7 #if DEBUG_MUTEX_CLASS >= 7
cout << "Deconstructing Mutex" << endl; std::cout << "Deconstructing Mutex" << std::endl;
#endif #endif
#ifdef _WINDOWS #ifdef _WINDOWS
DeleteCriticalSection(&CSMutex); DeleteCriticalSection(&CSMutex);
@ -98,11 +98,11 @@ Mutex::~Mutex() {
void Mutex::lock() { void Mutex::lock() {
_CP(Mutex_lock); _CP(Mutex_lock);
#if DEBUG_MUTEX_CLASS >= 9 #if DEBUG_MUTEX_CLASS >= 9
cout << "Locking Mutex" << endl; std::cout << "Locking Mutex" << std::endl;
#endif #endif
#if DEBUG_MUTEX_CLASS >= 5 #if DEBUG_MUTEX_CLASS >= 5
if (!trylock()) { if (!trylock()) {
cout << "Locking Mutex: Having to wait" << endl; std::cout << "Locking Mutex: Having to wait" << std::endl;
#ifdef _WINDOWS #ifdef _WINDOWS
EnterCriticalSection(&CSMutex); EnterCriticalSection(&CSMutex);
#else #else
@ -120,7 +120,7 @@ void Mutex::lock() {
bool Mutex::trylock() { bool Mutex::trylock() {
#if DEBUG_MUTEX_CLASS >= 9 #if DEBUG_MUTEX_CLASS >= 9
cout << "TryLocking Mutex" << endl; std::cout << "TryLocking Mutex" << std::endl;
#endif #endif
#ifdef _WINDOWS #ifdef _WINDOWS
#if(_WIN32_WINNT >= 0x0400) #if(_WIN32_WINNT >= 0x0400)
@ -141,7 +141,7 @@ bool Mutex::trylock() {
void Mutex::unlock() { void Mutex::unlock() {
#if DEBUG_MUTEX_CLASS >= 9 #if DEBUG_MUTEX_CLASS >= 9
cout << "Unlocking Mutex" << endl; std::cout << "Unlocking Mutex" << std::endl;
#endif #endif
#ifdef _WINDOWS #ifdef _WINDOWS
LeaveCriticalSection(&CSMutex); LeaveCriticalSection(&CSMutex);
@ -187,7 +187,7 @@ MRMutex::MRMutex() {
MRMutex::~MRMutex() { MRMutex::~MRMutex() {
#ifdef _EQDEBUG #ifdef _EQDEBUG
if (wl || rl) { if (wl || rl) {
cout << "MRMutex::~MRMutex: poor cleanup detected: rl=" << rl << ", wl=" << wl << endl; std::cout << "MRMutex::~MRMutex: poor cleanup detected: rl=" << rl << ", wl=" << wl << std::endl;
} }
#endif #endif
} }

View File

@ -15,25 +15,27 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <string>
#include <vector>
#include "debug.h" #include "debug.h"
#include "ProcLauncher.h" #include "ProcLauncher.h"
#ifdef _WINDOWS #ifdef _WINDOWS
#include <windows.h> #include <windows.h>
#else #else
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#endif #endif
using namespace std;
ProcLauncher ProcLauncher::s_launcher; ProcLauncher ProcLauncher::s_launcher;
#ifdef _WINDOWS #ifdef _WINDOWS
@ -51,10 +53,9 @@ ProcLauncher::ProcLauncher()
#endif #endif
} }
void ProcLauncher::Process() { void ProcLauncher::Process() {
#ifdef _WINDOWS #ifdef _WINDOWS
map<ProcRef, Spec *>::iterator cur, end, tmp; std::map<ProcRef, Spec *>::iterator cur, end, tmp;
cur = m_running.begin(); cur = m_running.begin();
end = m_running.end(); end = m_running.end();
while(cur != end) { while(cur != end) {
@ -91,7 +92,7 @@ void ProcLauncher::Process() {
break; break;
} else { } else {
//one died... //one died...
map<ProcRef, Spec *>::iterator ref; std::map<ProcRef, Spec *>::iterator ref;
ref = m_running.find(died); ref = m_running.find(died);
if(ref == m_running.end()) { if(ref == m_running.end()) {
//unable to find this process in our list... //unable to find this process in our list...
@ -168,8 +169,8 @@ ProcLauncher::ProcRef ProcLauncher::Launch(Spec *&to_launch) {
// Create the child process. // Create the child process.
//glue together all the nice command line arguments //glue together all the nice command line arguments
string args(it->program); std::string args(it->program);
vector<string>::iterator cur, end; std::vector<std::string>::iterator cur, end;
cur = it->args.begin(); cur = it->args.begin();
end = it->args.end(); end = it->args.end();
for(; cur != end; cur++) { for(; cur != end; cur++) {

330
common/StringUtil.cpp Normal file
View File

@ -0,0 +1,330 @@
/*
* 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 <string>
#include <cstdarg>
#include <cstring> // for strncpy
#include <stdexcept>
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <stdlib.h>
#include <stdio.h>
#endif
#ifndef va_copy
#define va_copy(d,s) ((d) = (s))
#endif
// original source:
// https://github.com/facebook/folly/blob/master/folly/String.cpp
//
void vStringFormat(std::string& output, const char* format, va_list args)
{
va_list tmpargs;
va_copy(tmpargs,args);
int characters_used = vsnprintf(nullptr, 0, format, tmpargs);
va_end(tmpargs);
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)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(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);
}
}
}
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) {
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 *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;
}
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;
}

51
common/StringUtil.h Normal file
View File

@ -0,0 +1,51 @@
/*
* 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 <string>
#include <cstdarg>
#include "types.h"
void vStringFormat(std::string& output, const char* format, va_list args);
void StringFormat(std::string& output, const char* format, ...);
const char *MakeLowerString(const char *source);
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);
const char *ConvertArray(int input, char *returnchar);
const char *ConvertArrayF(float input, char *returnchar);
void RemoveApostrophes(std::string &s);
char *RemoveApostrophes(const char *s);
#endif

View File

@ -57,14 +57,14 @@ void StructStrategy::PassDecoder(EQApplicationPacket *p) {
//effectively a singleton, but I decided to do it this way for no apparent reason. //effectively a singleton, but I decided to do it this way for no apparent reason.
namespace StructStrategyFactory { namespace StructStrategyFactory {
static map<EmuOpcode, const StructStrategy *> strategies; static std::map<EmuOpcode, const StructStrategy *> strategies;
void RegisterPatch(EmuOpcode first_opcode, const StructStrategy *structs) { void RegisterPatch(EmuOpcode first_opcode, const StructStrategy *structs) {
strategies[first_opcode] = structs; strategies[first_opcode] = structs;
} }
const StructStrategy *FindPatch(EmuOpcode first_opcode) { const StructStrategy *FindPatch(EmuOpcode first_opcode) {
map<EmuOpcode, const StructStrategy *>::const_iterator res; std::map<EmuOpcode, const StructStrategy *>::const_iterator res;
res = strategies.find(first_opcode); res = strategies.find(first_opcode);
if(res == strategies.end()) if(res == strategies.end())
return(nullptr); return(nullptr);

View File

@ -18,11 +18,9 @@
#include "../common/debug.h" #include "../common/debug.h"
#include <iostream> #include <iostream>
using namespace std;
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <iomanip> #include <iomanip>
using namespace std;
#include "TCPConnection.h" #include "TCPConnection.h"
#include "../common/servertalk.h" #include "../common/servertalk.h"
@ -63,7 +61,7 @@ TCPConnection::TCPConnection()
pAsyncConnect = false; pAsyncConnect = false;
m_previousLineEnd = false; m_previousLineEnd = false;
#if TCPN_DEBUG_Memory >= 7 #if TCPN_DEBUG_Memory >= 7
cout << "Constructor #2 on outgoing TCP# " << GetID() << endl; std::cout << "Constructor #2 on outgoing TCP# " << GetID() << std::endl;
#endif #endif
} }
@ -85,7 +83,7 @@ TCPConnection::TCPConnection(uint32 ID, SOCKET in_socket, uint32 irIP, uint16 ir
pAsyncConnect = false; pAsyncConnect = false;
m_previousLineEnd = false; m_previousLineEnd = false;
#if TCPN_DEBUG_Memory >= 7 #if TCPN_DEBUG_Memory >= 7
cout << "Constructor #2 on incoming TCP# " << GetID() << endl; std::cout << "Constructor #2 on incoming TCP# " << GetID() << std::endl;
#endif #endif
} }
@ -99,12 +97,12 @@ TCPConnection::~TCPConnection() {
MLoopRunning.lock(); MLoopRunning.lock();
MLoopRunning.unlock(); MLoopRunning.unlock();
#if TCPN_DEBUG_Memory >= 6 #if TCPN_DEBUG_Memory >= 6
cout << "Deconstructor on outgoing TCP# " << GetID() << endl; std::cout << "Deconstructor on outgoing TCP# " << GetID() << std::endl;
#endif #endif
} }
#if TCPN_DEBUG_Memory >= 5 #if TCPN_DEBUG_Memory >= 5
else { else {
cout << "Deconstructor on incomming TCP# " << GetID() << endl; std::cout << "Deconstructor on incomming TCP# " << GetID() << std::endl;
} }
#endif #endif
safe_delete_array(recvbuf); safe_delete_array(recvbuf);
@ -587,7 +585,7 @@ bool TCPConnection::Process() {
if (!SendData(sent_something, errbuf)) { if (!SendData(sent_something, errbuf)) {
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
cout << inet_ntoa(in) << ":" << GetrPort() << ": " << errbuf << endl; std::cout << inet_ntoa(in) << ":" << GetrPort() << ": " << errbuf << std::endl;
return false; return false;
} }
@ -628,8 +626,8 @@ bool TCPConnection::RecvData(char* errbuf) {
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
CoutTimestamp(true); CoutTimestamp(true);
cout << ": Read " << status << " bytes from network. (recvbuf_used = " << recvbuf_used << ") " << inet_ntoa(in) << ":" << GetrPort(); std::cout << ": Read " << status << " bytes from network. (recvbuf_used = " << recvbuf_used << ") " << inet_ntoa(in) << ":" << GetrPort();
cout << endl; std::cout << std::endl;
#if TCPN_LOG_RAW_DATA_IN == 2 #if TCPN_LOG_RAW_DATA_IN == 2
int32 tmp = status; int32 tmp = status;
if (tmp > 32) if (tmp > 32)
@ -683,7 +681,7 @@ bool TCPConnection::ProcessReceivedData(char* errbuf) {
return true; return true;
#if TCPN_DEBUG_Console >= 4 #if TCPN_DEBUG_Console >= 4
if (recvbuf_used) { if (recvbuf_used) {
cout << "Starting Processing: recvbuf=" << recvbuf_used << endl; std::cout << "Starting Processing: recvbuf=" << recvbuf_used << std::endl;
DumpPacket(recvbuf, recvbuf_used); DumpPacket(recvbuf, recvbuf_used);
} }
#endif #endif
@ -715,13 +713,13 @@ bool TCPConnection::ProcessReceivedData(char* errbuf) {
} }
} }
#if TCPN_DEBUG_Console >= 5 #if TCPN_DEBUG_Console >= 5
cout << "Removed 0x00" << endl; std::cout << "Removed 0x00" << std::endl;
if (recvbuf_used) { if (recvbuf_used) {
cout << "recvbuf left: " << recvbuf_used << endl; std::cout << "recvbuf left: " << recvbuf_used << std::endl;
DumpPacket(recvbuf, recvbuf_used); DumpPacket(recvbuf, recvbuf_used);
} }
else else
cout << "recbuf left: None" << endl; std::cout << "recbuf left: None" << std::endl;
#endif #endif
m_previousLineEnd = false; m_previousLineEnd = false;
break; break;
@ -748,7 +746,7 @@ bool TCPConnection::ProcessReceivedData(char* errbuf) {
memset(line, 0, i+1); memset(line, 0, i+1);
memcpy(line, recvbuf, i); memcpy(line, recvbuf, i);
#if TCPN_DEBUG_Console >= 3 #if TCPN_DEBUG_Console >= 3
cout << "Line Out: " << endl; std::cout << "Line Out: " << std::endl;
DumpPacket((uchar*) line, i); DumpPacket((uchar*) line, i);
#endif #endif
//line[i] = 0; //line[i] = 0;
@ -758,13 +756,13 @@ bool TCPConnection::ProcessReceivedData(char* errbuf) {
recvbuf_echo -= i+1; recvbuf_echo -= i+1;
memcpy(recvbuf, &tmpdel[i+1], recvbuf_used); memcpy(recvbuf, &tmpdel[i+1], recvbuf_used);
#if TCPN_DEBUG_Console >= 5 #if TCPN_DEBUG_Console >= 5
cout << "i+1=" << i+1 << endl; std::cout << "i+1=" << i+1 << std::endl;
if (recvbuf_used) { if (recvbuf_used) {
cout << "recvbuf left: " << recvbuf_used << endl; std::cout << "recvbuf left: " << recvbuf_used << std::endl;
DumpPacket(recvbuf, recvbuf_used); DumpPacket(recvbuf, recvbuf_used);
} }
else else
cout << "recbuf left: None" << endl; std::cout << "recbuf left: None" << std::endl;
#endif #endif
safe_delete_array(tmpdel); safe_delete_array(tmpdel);
i = -1; i = -1;
@ -829,8 +827,8 @@ bool TCPConnection::SendData(bool &sent_something, char* errbuf) {
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
CoutTimestamp(true); CoutTimestamp(true);
cout << ": Wrote " << status << " bytes to network. " << inet_ntoa(in) << ":" << GetrPort(); std::cout << ": Wrote " << status << " bytes to network. " << inet_ntoa(in) << ":" << GetrPort();
cout << endl; std::cout << std::endl;
#if TCPN_LOG_RAW_DATA_OUT == 2 #if TCPN_LOG_RAW_DATA_OUT == 2
int32 tmp = status; int32 tmp = status;
if (tmp > 32) if (tmp > 32)
@ -846,8 +844,8 @@ bool TCPConnection::SendData(bool &sent_something, char* errbuf) {
struct in_addr in; struct in_addr in;
in.s_addr = GetrIP(); in.s_addr = GetrIP();
CoutTimestamp(true); CoutTimestamp(true);
cout << ": Pushed " << (size - status) << " bytes back onto the send queue. " << inet_ntoa(in) << ":" << GetrPort(); std::cout << ": Pushed " << (size - status) << " bytes back onto the send queue. " << inet_ntoa(in) << ":" << GetrPort();
cout << endl; std::cout << std::endl;
#endif #endif
// If there's network congestion, the number of bytes sent can be less than // If there's network congestion, the number of bytes sent can be less than
// what we tried to give it... Push the extra back on the queue for later // what we tried to give it... Push the extra back on the queue for later

View File

@ -24,9 +24,6 @@
#ifdef _WINDOWS #ifdef _WINDOWS
#define snprintf _snprintf #define snprintf _snprintf
#if (_MSC_VER < 1500)
#define vsnprintf _vsnprintf
#endif
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#define strcasecmp _stricmp #define strcasecmp _stricmp

View File

@ -23,7 +23,7 @@ XMLParser::XMLParser() {
} }
bool XMLParser::ParseFile(const char *file, const char *root_ele) { bool XMLParser::ParseFile(const char *file, const char *root_ele) {
map<string,ElementHandler>::iterator handler; std::map<std::string,ElementHandler>::iterator handler;
TiXmlDocument doc( file ); TiXmlDocument doc( file );
if(!doc.LoadFile()) { if(!doc.LoadFile()) {
printf("Unable to load '%s': %s\n", file, doc.ErrorDesc()); printf("Unable to load '%s': %s\n", file, doc.ErrorDesc());

View File

@ -24,9 +24,6 @@
#include <string> #include <string>
#include <map> #include <map>
using namespace std;
/* /*
* See note in XMLParser::ParseFile() before inheriting this class. * See note in XMLParser::ParseFile() before inheriting this class.
@ -45,12 +42,11 @@ protected:
const char *ParseTextBlock(TiXmlNode *within, const char *name, bool optional = false); const char *ParseTextBlock(TiXmlNode *within, const char *name, bool optional = false);
const char *GetText(TiXmlNode *within, bool optional = false); const char *GetText(TiXmlNode *within, bool optional = false);
map<string,ElementHandler> Handlers; std::map<std::string,ElementHandler> Handlers;
bool ParseOkay; bool ParseOkay;
}; };
#endif #endif

View File

@ -18,7 +18,6 @@
#include "../common/debug.h" #include "../common/debug.h"
#include "../common/rulesys.h" #include "../common/rulesys.h"
#include <iostream> #include <iostream>
using namespace std;
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -44,7 +43,8 @@ using namespace std;
#include "database.h" #include "database.h"
#include "eq_packet_structs.h" #include "eq_packet_structs.h"
#include "guilds.h" #include "guilds.h"
#include "MiscFunctions.h" //#include "MiscFunctions.h"
#include "StringUtil.h"
#include "extprofile.h" #include "extprofile.h"
extern Client client; extern Client client;
@ -193,7 +193,7 @@ uint32 Database::CheckLogin(const char* name, const char* password, int16* oStat
} }
else else
{ {
cerr << "Error in CheckLogin query '" << query << "' " << errbuf << endl; std::cerr << "Error in CheckLogin query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -227,7 +227,7 @@ bool Database::CheckBannedIPs(const char* loginIP)
} }
else else
{ {
cerr << "Error in CheckBannedIPs query '" << query << "' " << errbuf << endl; std::cerr << "Error in CheckBannedIPs query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return true; return true;
} }
@ -240,7 +240,7 @@ bool Database::AddBannedIP(char* bannedIP, const char* notes)
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT into Banned_IPs SET ip_address='%s', notes='%s'", bannedIP, notes), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "INSERT into Banned_IPs SET ip_address='%s', notes='%s'", bannedIP, notes), errbuf)) {
cerr << "Error in ReserveName query '" << query << "' " << errbuf << endl; std::cerr << "Error in ReserveName query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -290,7 +290,7 @@ void Database::LoginIP(uint32 AccountID, const char* LoginIP)
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO account_ip SET accid=%i, ip='%s' ON DUPLICATE KEY UPDATE count=count+1, lastused=now()", AccountID, LoginIP), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO account_ip SET accid=%i, ip='%s' ON DUPLICATE KEY UPDATE count=count+1, lastused=now()", AccountID, LoginIP), errbuf)) {
cerr << "Error in Log IP query '" << query << "' " << errbuf << endl; std::cerr << "Error in Log IP query '" << query << "' " << errbuf << std::endl;
} }
safe_delete_array(query); safe_delete_array(query);
} }
@ -333,7 +333,7 @@ int16 Database::CheckStatus(uint32 account_id)
} }
else else
{ {
cerr << "Error in CheckStatus query '" << query << "' " << errbuf << endl; std::cerr << "Error in CheckStatus query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -352,16 +352,16 @@ uint32 Database::CreateAccount(const char* name, const char* password, int16 sta
else else
querylen = MakeAnyLenString(&query, "INSERT INTO account SET name='%s', status=%i, lsaccount_id=%i, time_creation=UNIX_TIMESTAMP();",name, status, lsaccount_id); querylen = MakeAnyLenString(&query, "INSERT INTO account SET name='%s', status=%i, lsaccount_id=%i, time_creation=UNIX_TIMESTAMP();",name, status, lsaccount_id);
cerr << "Account Attempting to be created:" << name << " " << (int16) status << endl; std::cerr << "Account Attempting to be created:" << name << " " << (int16) status << std::endl;
if (!RunQuery(query, querylen, errbuf, 0, 0, &last_insert_id)) { if (!RunQuery(query, querylen, errbuf, 0, 0, &last_insert_id)) {
cerr << "Error in CreateAccount query '" << query << "' " << errbuf << endl; std::cerr << "Error in CreateAccount query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return 0; return 0;
} }
safe_delete_array(query); safe_delete_array(query);
if (last_insert_id == 0) { if (last_insert_id == 0) {
cerr << "Error in CreateAccount query '" << query << "' " << errbuf << endl; std::cerr << "Error in CreateAccount query '" << query << "' " << errbuf << std::endl;
return 0; return 0;
} }
@ -373,7 +373,7 @@ bool Database::DeleteAccount(const char* name) {
char *query = 0; char *query = 0;
uint32 affected_rows = 0; uint32 affected_rows = 0;
cerr << "Account Attempting to be deleted:" << name << endl; std::cerr << "Account Attempting to be deleted:" << name << std::endl;
if (RunQuery(query, MakeAnyLenString(&query, "DELETE FROM account WHERE name='%s';",name), errbuf, 0, &affected_rows)) { if (RunQuery(query, MakeAnyLenString(&query, "DELETE FROM account WHERE name='%s';",name), errbuf, 0, &affected_rows)) {
safe_delete_array(query); safe_delete_array(query);
if (affected_rows == 1) { if (affected_rows == 1) {
@ -382,7 +382,7 @@ bool Database::DeleteAccount(const char* name) {
} }
else { else {
cerr << "Error in DeleteAccount query '" << query << "' " << errbuf << endl; std::cerr << "Error in DeleteAccount query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
@ -394,7 +394,7 @@ bool Database::SetLocalPassword(uint32 accid, const char* password) {
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET password=MD5('%s') where id=%i;", password, accid), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET password=MD5('%s') where id=%i;", password, accid), errbuf)) {
cerr << "Error in SetLocalPassword query '" << query << "' " << errbuf << endl; std::cerr << "Error in SetLocalPassword query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -408,7 +408,7 @@ bool Database::SetAccountStatus(const char* name, int16 status) {
char *query = 0; char *query = 0;
uint32 affected_rows = 0; uint32 affected_rows = 0;
cout << "Account being GM Flagged:" << name << ", Level: " << (int16) status << endl; std::cout << "Account being GM Flagged:" << name << ", Level: " << (int16) status << std::endl;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET status=%i WHERE name='%s';", status, name), errbuf, 0, &affected_rows)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET status=%i WHERE name='%s';", status, name), errbuf, 0, &affected_rows)) {
safe_delete_array(query); safe_delete_array(query);
return false; return false;
@ -416,7 +416,7 @@ bool Database::SetAccountStatus(const char* name, int16 status) {
safe_delete_array(query); safe_delete_array(query);
if (affected_rows == 0) { if (affected_rows == 0) {
cout << "Account: " << name << " does not exist, therefore it cannot be flagged\n"; std::cout << "Account: " << name << " does not exist, therefore it cannot be flagged\n";
return false; return false;
} }
@ -429,7 +429,7 @@ bool Database::ReserveName(uint32 account_id, char* name)
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT into character_ SET account_id=%i, name='%s', profile=NULL", account_id, name), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "INSERT into character_ SET account_id=%i, name='%s', profile=NULL", account_id, name), errbuf)) {
cerr << "Error in ReserveName query '" << query << "' " << errbuf << endl; std::cerr << "Error in ReserveName query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -877,7 +877,7 @@ uint32 Database::GetAccountIDByChar(const char* charname, uint32* oCharID) {
mysql_free_result(result); mysql_free_result(result);
} }
else { else {
cerr << "Error in GetAccountIDByChar query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetAccountIDByChar query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
@ -940,7 +940,7 @@ uint32 Database::GetAccountIDByName(const char* accname, int16* status, uint32*
mysql_free_result(result); mysql_free_result(result);
} }
else { else {
cerr << "Error in GetAccountIDByAcc query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetAccountIDByAcc query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
@ -968,7 +968,7 @@ void Database::GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID
} }
else { else {
safe_delete_array(query); safe_delete_array(query);
cerr << "Error in GetAccountName query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetAccountName query '" << query << "' " << errbuf << std::endl;
} }
} }
@ -990,7 +990,7 @@ void Database::GetCharName(uint32 char_id, char* name) {
} }
else { else {
safe_delete_array(query); safe_delete_array(query);
cerr << "Error in GetCharName query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetCharName query '" << query << "' " << errbuf << std::endl;
} }
} }
@ -1007,7 +1007,7 @@ bool Database::LoadVariables() {
return ret; return ret;
} }
else { else {
cerr << "Error in LoadVariables query '" << query << "' " << errbuf << endl; std::cerr << "Error in LoadVariables query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
return false; return false;
@ -1130,7 +1130,7 @@ bool Database::SetVariable(const char* varname_in, const char* varvalue_in) {
} }
} }
else { else {
cerr << "Error in SetVariable query '" << query << "' " << errbuf << endl; std::cerr << "Error in SetVariable query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
free(varname); free(varname);
@ -1152,7 +1152,7 @@ uint32 Database::GetMiniLoginAccount(char* ip){
} }
else else
{ {
cerr << "Error in GetMiniLoginAccount query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetMiniLoginAccount query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
return retid; return retid;
@ -1194,11 +1194,11 @@ bool Database::GetSafePoints(const char* short_name, uint32 version, float* safe
} }
else else
{ {
cerr << "Error in GetSafePoint query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetSafePoint query '" << query << "' " << errbuf << std::endl;
cerr << "If it errors, run the following querys:\n"; std::cerr << "If it errors, run the following querys:\n";
cerr << "ALTER TABLE `zone` CHANGE `minium_level` `min_level` TINYINT(3) UNSIGNED DEFAULT \"0\" NOT NULL;\n"; std::cerr << "ALTER TABLE `zone` CHANGE `minium_level` `min_level` TINYINT(3) UNSIGNED DEFAULT \"0\" NOT NULL;\n";
cerr << "ALTER TABLE `zone` CHANGE `minium_status` `min_status` TINYINT(3) UNSIGNED DEFAULT \"0\" NOT NULL;\n"; std::cerr << "ALTER TABLE `zone` CHANGE `minium_status` `min_status` TINYINT(3) UNSIGNED DEFAULT \"0\" NOT NULL;\n";
cerr << "ALTER TABLE `zone` ADD flag_needed VARCHAR(128) NOT NULL DEFAULT '';\n"; std::cerr << "ALTER TABLE `zone` ADD flag_needed VARCHAR(128) NOT NULL DEFAULT '';\n";
safe_delete_array(query); safe_delete_array(query);
} }
@ -1243,7 +1243,7 @@ bool Database::GetZoneLongName(const char* short_name, char** long_name, char* f
} }
else else
{ {
cerr << "Error in GetZoneLongName query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetZoneLongName query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -1269,7 +1269,7 @@ uint32 Database::GetZoneGraveyardID(uint32 zone_id, uint32 version) {
} }
else else
{ {
cerr << "Error in GetZoneGraveyardID query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetZoneGraveyardID query '" << query << "' " << errbuf << std::endl;
} }
safe_delete_array(query); safe_delete_array(query);
return GraveyardID; return GraveyardID;
@ -1303,7 +1303,7 @@ bool Database::GetZoneGraveyard(const uint32 graveyard_id, uint32* graveyard_zon
} }
else else
{ {
cerr << "Error in GetZoneGraveyard query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetZoneGraveyard query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -1342,7 +1342,7 @@ bool Database::LoadZoneNames() {
mysql_free_result(result); mysql_free_result(result);
} }
else { else {
cerr << "Error in LoadZoneNames query '" << query << "' " << errbuf << endl; std::cerr << "Error in LoadZoneNames query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -1352,7 +1352,7 @@ bool Database::LoadZoneNames() {
} }
} }
else { else {
cerr << "Error in LoadZoneNames query '" << query << "' " << errbuf << endl; std::cerr << "Error in LoadZoneNames query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -1419,7 +1419,7 @@ uint8 Database::GetPEQZone(uint32 zoneID, uint32 version){
} }
else else
{ {
cerr << "Error in GetPEQZone query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetPEQZone query '" << query << "' " << errbuf << std::endl;
} }
safe_delete_array(query); safe_delete_array(query);
return peqzone; return peqzone;
@ -1503,7 +1503,7 @@ bool Database::CheckNameFilter(const char* name, bool surname)
} }
else else
{ {
cerr << "Error in CheckNameFilter query '" << query << "' " << errbuf << endl; std::cerr << "Error in CheckNameFilter query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
@ -1516,7 +1516,7 @@ bool Database::AddToNameFilter(const char* name) {
uint32 affected_rows = 0; uint32 affected_rows = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO name_filter (name) values ('%s')", name), errbuf, 0, &affected_rows)) { if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO name_filter (name) values ('%s')", name), errbuf, 0, &affected_rows)) {
cerr << "Error in AddToNameFilter query '" << query << "' " << errbuf << endl; std::cerr << "Error in AddToNameFilter query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -1557,7 +1557,7 @@ uint32 Database::GetAccountIDFromLSID(uint32 iLSID, char* oAccountName, int16* o
mysql_free_result(result); mysql_free_result(result);
} }
else { else {
cerr << "Error in GetAccountIDFromLSID query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetAccountIDFromLSID query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return 0; return 0;
} }
@ -1583,7 +1583,7 @@ void Database::GetAccountFromID(uint32 id, char* oAccountName, int16* oStatus) {
mysql_free_result(result); mysql_free_result(result);
} }
else else
cerr << "Error in GetAccountFromID query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetAccountFromID query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
@ -1592,7 +1592,7 @@ void Database::ClearMerchantTemp(){
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "delete from merchantlist_temp"), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "delete from merchantlist_temp"), errbuf)) {
cerr << "Error in ClearMerchantTemp query '" << query << "' " << errbuf << endl; std::cerr << "Error in ClearMerchantTemp query '" << query << "' " << errbuf << std::endl;
} }
safe_delete_array(query); safe_delete_array(query);
} }
@ -1602,7 +1602,7 @@ bool Database::UpdateName(const char* oldname, const char* newname) {
char *query = 0; char *query = 0;
uint32 affected_rows = 0; uint32 affected_rows = 0;
cout << "Renaming " << oldname << " to " << newname << "..." << endl; std::cout << "Renaming " << oldname << " to " << newname << "..." << std::endl;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET name='%s' WHERE name='%s';", newname, oldname), errbuf, 0, &affected_rows)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET name='%s' WHERE name='%s';", newname, oldname), errbuf, 0, &affected_rows)) {
safe_delete_array(query); safe_delete_array(query);
return false; return false;
@ -1626,7 +1626,7 @@ bool Database::CheckUsedName(const char* name)
//if (strlen(name) > 15) //if (strlen(name) > 15)
// return false; // return false;
if (!RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM character_ where name='%s'", name), errbuf, &result)) { if (!RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM character_ where name='%s'", name), errbuf, &result)) {
cerr << "Error in CheckUsedName query '" << query << "' " << errbuf << endl; std::cerr << "Error in CheckUsedName query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -1664,15 +1664,11 @@ uint8 Database::GetServerType()
mysql_free_result(result); mysql_free_result(result);
} }
else else
{ {
std::cerr << "Error in GetServerType query '" << query << "' " << errbuf << std::endl;
cerr << "Error in GetServerType query '" << query << "' " << errbuf << endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
return 0; return 0;
} }
@ -1686,7 +1682,7 @@ bool Database::MoveCharacterToZone(const char* charname, const char* zonename,ui
return(false); return(false);
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET zonename = '%s',zoneid=%i,x=-1, y=-1, z=-1 WHERE name='%s'", zonename,zoneid, charname), errbuf, 0,&affected_rows)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET zonename = '%s',zoneid=%i,x=-1, y=-1, z=-1 WHERE name='%s'", zonename,zoneid, charname), errbuf, 0,&affected_rows)) {
cerr << "Error in MoveCharacterToZone(name) query '" << query << "' " << errbuf << endl; std::cerr << "Error in MoveCharacterToZone(name) query '" << query << "' " << errbuf << std::endl;
return false; return false;
} }
safe_delete_array(query); safe_delete_array(query);
@ -1706,7 +1702,7 @@ bool Database::MoveCharacterToZone(uint32 iCharID, const char* iZonename) {
char *query = 0; char *query = 0;
uint32 affected_rows = 0; uint32 affected_rows = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET zonename = '%s', zoneid=%i, x=-1, y=-1, z=-1 WHERE id=%i", iZonename, GetZoneID(iZonename), iCharID), errbuf, 0,&affected_rows)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET zonename = '%s', zoneid=%i, x=-1, y=-1, z=-1 WHERE id=%i", iZonename, GetZoneID(iZonename), iCharID), errbuf, 0,&affected_rows)) {
cerr << "Error in MoveCharacterToZone(id) query '" << query << "' " << errbuf << endl; std::cerr << "Error in MoveCharacterToZone(id) query '" << query << "' " << errbuf << std::endl;
return false; return false;
} }
safe_delete_array(query); safe_delete_array(query);
@ -1739,7 +1735,7 @@ uint8 Database::CopyCharacter(const char* oldname, const char* newname, uint32 a
} }
else { else {
cerr << "Error in CopyCharacter read query '" << query << "' " << errbuf << endl; std::cerr << "Error in CopyCharacter read query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return 0; return 0;
} }
@ -1755,7 +1751,7 @@ uint8 Database::CopyCharacter(const char* oldname, const char* newname, uint32 a
end += sprintf(end, "\', account_id=%d, name='%s'", acctid, newname); end += sprintf(end, "\', account_id=%d, name='%s'", acctid, newname);
if (!RunQuery(query2, (uint32) (end - query2), errbuf, 0, &affected_rows)) { if (!RunQuery(query2, (uint32) (end - query2), errbuf, 0, &affected_rows)) {
cerr << "Error in CopyCharacter query '" << query << "' " << errbuf << endl; std::cerr << "Error in CopyCharacter query '" << query << "' " << errbuf << std::endl;
return 0; return 0;
} }
@ -1772,7 +1768,7 @@ bool Database::SetHackerFlag(const char* accountname, const char* charactername,
char *query = 0; char *query = 0;
uint32 affected_rows = 0; uint32 affected_rows = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO hackers(account,name,hacked) values('%s','%s','%s')", accountname, charactername, hacked), errbuf, 0,&affected_rows)) { if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO hackers(account,name,hacked) values('%s','%s','%s')", accountname, charactername, hacked), errbuf, 0,&affected_rows)) {
cerr << "Error in SetHackerFlag query '" << query << "' " << errbuf << endl; std::cerr << "Error in SetHackerFlag query '" << query << "' " << errbuf << std::endl;
return false; return false;
} }
safe_delete_array(query); safe_delete_array(query);
@ -1792,7 +1788,7 @@ bool Database::SetMQDetectionFlag(const char* accountname, const char* character
uint32 affected_rows = 0; uint32 affected_rows = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO hackers(account,name,hacked,zone) values('%s','%s','%s','%s')", accountname, charactername, hacked, zone), errbuf, 0,&affected_rows)) { if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO hackers(account,name,hacked,zone) values('%s','%s','%s','%s')", accountname, charactername, hacked, zone), errbuf, 0,&affected_rows)) {
cerr << "Error in SetMQDetectionFlag query '" << query << "' " << errbuf << endl; std::cerr << "Error in SetMQDetectionFlag query '" << query << "' " << errbuf << std::endl;
return false; return false;
} }
@ -1911,7 +1907,7 @@ uint32 Database::GetCharacterInfo(const char* iName, uint32* oAccID, uint32* oZo
mysql_free_result(result); mysql_free_result(result);
} }
else { else {
cerr << "Error in GetCharacterInfo query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetCharacterInfo query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
return 0; return 0;
@ -1921,7 +1917,7 @@ bool Database::UpdateLiveChar(char* charname,uint32 lsaccount_id) {
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET charname='%s' WHERE id=%i;",charname, lsaccount_id), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET charname='%s' WHERE id=%i;",charname, lsaccount_id), errbuf)) {
cerr << "Error in UpdateLiveChar query '" << query << "' " << errbuf << endl; std::cerr << "Error in UpdateLiveChar query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -1946,7 +1942,7 @@ bool Database::GetLiveChar(uint32 account_id, char* cname) {
mysql_free_result(result); mysql_free_result(result);
} }
else { else {
cerr << "Error in GetLiveChar query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetLiveChar query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
@ -2171,7 +2167,7 @@ void Database::ClearGroupLeader(uint32 gid){
safe_delete_array(query); safe_delete_array(query);
} }
bool FetchRowMap(MYSQL_RES *result, map<string,string> &rowmap) bool FetchRowMap(MYSQL_RES *result, std::map<std::string,std::string> &rowmap)
{ {
MYSQL_FIELD *fields; MYSQL_FIELD *fields;
MYSQL_ROW row; MYSQL_ROW row;
@ -3175,7 +3171,7 @@ uint32 Database::GetGuildDBIDByCharID(uint32 char_id) {
mysql_free_result(result); mysql_free_result(result);
} }
else { else {
cerr << "Error in GetAccountIDByChar query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetAccountIDByChar query '" << query << "' " << errbuf << std::endl;
} }
safe_delete_array(query); safe_delete_array(query);
return retVal; return retVal;

View File

@ -35,7 +35,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
using namespace std;
//atoi is not uint32 or uint32 safe!!!! //atoi is not uint32 or uint32 safe!!!!
#define atoul(str) strtoul(str, nullptr, 10) #define atoul(str) strtoul(str, nullptr, 10)
@ -217,7 +216,7 @@ public:
const char *GetRaidLeaderName(uint32 rid); const char *GetRaidLeaderName(uint32 rid);
/* /*
* Database Varaibles * Database Variables
*/ */
bool GetVariable(const char* varname, char* varvalue, uint16 varvalue_len); bool GetVariable(const char* varname, char* varvalue, uint16 varvalue_len);
bool SetVariable(const char* varname, const char* varvalue); bool SetVariable(const char* varname, const char* varvalue);
@ -265,5 +264,5 @@ private:
uint32 varcache_lastupdate; uint32 varcache_lastupdate;
}; };
bool FetchRowMap(MYSQL_RES *result, map<string,string> &rowmap); bool FetchRowMap(MYSQL_RES *result, std::map<std::string,std::string> &rowmap);
#endif #endif

View File

@ -5,7 +5,6 @@
#include <winsock2.h> #include <winsock2.h>
#endif #endif
#include <iostream> #include <iostream>
using namespace std;
#include "dbasync.h" #include "dbasync.h"
#include "database.h" #include "database.h"
#include <errmsg.h> #include <errmsg.h>
@ -14,7 +13,8 @@ using namespace std;
#include "dbcore.h" #include "dbcore.h"
#include "common_profile.h" #include "common_profile.h"
#include <string.h> #include <string.h>
#include "../common/MiscFunctions.h" //#include "../common/MiscFunctions.h"
#include "StringUtil.h"
#define ASYNC_LOOP_GRANULARITY 4 //# of ms between checking our work #define ASYNC_LOOP_GRANULARITY 4 //# of ms between checking our work
bool DBAsyncCB_LoadVariables(DBAsyncWork* iWork) { bool DBAsyncCB_LoadVariables(DBAsyncWork* iWork) {
@ -24,7 +24,7 @@ bool DBAsyncCB_LoadVariables(DBAsyncWork* iWork) {
if (dbaq->GetAnswer(errbuf, &result)) if (dbaq->GetAnswer(errbuf, &result))
iWork->GetDB()->LoadVariables_result(result); iWork->GetDB()->LoadVariables_result(result);
else else
cout << "Error: DBAsyncCB_LoadVariables failed: !GetAnswer: '" << errbuf << "'" << endl; std::cout << "Error: DBAsyncCB_LoadVariables failed: !GetAnswer: '" << errbuf << "'" << std::endl;
return true; return true;
} }
@ -115,8 +115,8 @@ uint32 DBAsync::AddWork(DBAsyncWork** iWork, uint32 iDelay) {
if (iDelay) if (iDelay)
(*iWork)->pExecuteAfter = Timer::GetCurrentTime() + iDelay; (*iWork)->pExecuteAfter = Timer::GetCurrentTime() + iDelay;
#if DEBUG_MYSQL_QUERIES >= 2 #if DEBUG_MYSQL_QUERIES >= 2
cout << "Adding AsyncWork #" << (*iWork)->GetWorkID() << endl; std::cout << "Adding AsyncWork #" << (*iWork)->GetWorkID() << std::endl;
cout << "ExecuteAfter = " << (*iWork)->pExecuteAfter << " (" << Timer::GetCurrentTime() << " + " << iDelay << ")" << endl; std::cout << "ExecuteAfter = " << (*iWork)->pExecuteAfter << " (" << Timer::GetCurrentTime() << " + " << iDelay << ")" << std::endl;
#endif #endif
*iWork = 0; *iWork = 0;
MInList.unlock(); MInList.unlock();
@ -131,7 +131,7 @@ bool DBAsync::CancelWork(uint32 iWorkID) {
if (iWorkID == 0) if (iWorkID == 0)
return false; return false;
#if DEBUG_MYSQL_QUERIES >= 2 #if DEBUG_MYSQL_QUERIES >= 2
cout << "DBAsync::CancelWork: " << iWorkID << endl; std::cout << "DBAsync::CancelWork: " << iWorkID << std::endl;
#endif #endif
MCurrentWork.lock(); MCurrentWork.lock();
if (CurrentWork && CurrentWork->GetWorkID() == iWorkID) { if (CurrentWork && CurrentWork->GetWorkID() == iWorkID) {
@ -174,8 +174,8 @@ DBAsyncWork* DBAsync::InListPop() {
if (iterator.GetData()->pExecuteAfter <= Timer::GetCurrentTime()) { if (iterator.GetData()->pExecuteAfter <= Timer::GetCurrentTime()) {
ret = iterator.GetData(); ret = iterator.GetData();
#if DEBUG_MYSQL_QUERIES >= 2 #if DEBUG_MYSQL_QUERIES >= 2
cout << "Poping AsyncWork #" << ret->GetWorkID() << endl; std::cout << "Poping AsyncWork #" << ret->GetWorkID() << std::endl;
cout << ret->pExecuteAfter << " <= " << Timer::GetCurrentTime() << endl; std::cout << ret->pExecuteAfter << " <= " << Timer::GetCurrentTime() << std::endl;
#endif #endif
iterator.RemoveCurrent(false); iterator.RemoveCurrent(false);
break; break;
@ -232,7 +232,7 @@ void DBAsync::Process() {
tmpStatus = tmpWork->SetStatus(DBAsync::Finished); tmpStatus = tmpWork->SetStatus(DBAsync::Finished);
if (tmpStatus != Executing) { if (tmpStatus != Executing) {
if (tmpStatus != Canceled) { if (tmpStatus != Canceled) {
cout << "Error: Unexpected DBAsyncWork->Status in DBAsync::Process #1" << endl; std::cout << "Error: Unexpected DBAsyncWork->Status in DBAsync::Process #1" << std::endl;
} }
MCurrentWork.lock(); MCurrentWork.lock();
safe_delete(tmpWork); safe_delete(tmpWork);
@ -246,7 +246,7 @@ void DBAsync::Process() {
} }
else { else {
if (tmpStatus != Canceled) { if (tmpStatus != Canceled) {
cout << "Error: Unexpected DBAsyncWork->Status in DBAsync::Process #2" << endl; std::cout << "Error: Unexpected DBAsyncWork->Status in DBAsync::Process #2" << std::endl;
} }
MCurrentWork.lock(); MCurrentWork.lock();
safe_delete(CurrentWork); safe_delete(CurrentWork);
@ -274,7 +274,7 @@ void DBAsync::CheckTimeout() {
void DBAsync::CommitWrites() { void DBAsync::CommitWrites() {
#if DEBUG_MYSQL_QUERIES >= 2 #if DEBUG_MYSQL_QUERIES >= 2
cout << "DBAsync::CommitWrites() called." << endl; std::cout << "DBAsync::CommitWrites() called." << std::endl;
#endif #endif
DBAsyncWork* tmpWork; DBAsyncWork* tmpWork;
while ((tmpWork = InListPopWrite())) { while ((tmpWork = InListPopWrite())) {
@ -284,7 +284,7 @@ void DBAsync::CommitWrites() {
tmpStatus = tmpWork->SetStatus(DBAsync::Finished); tmpStatus = tmpWork->SetStatus(DBAsync::Finished);
if (tmpStatus != Executing) { if (tmpStatus != Executing) {
if (tmpStatus != Canceled) { if (tmpStatus != Canceled) {
cout << "Error: Unexpected DBAsyncWork->Status in DBAsync::CommitWrites #1" << endl; std::cout << "Error: Unexpected DBAsyncWork->Status in DBAsync::CommitWrites #1" << std::endl;
} }
safe_delete(tmpWork); safe_delete(tmpWork);
} }
@ -294,7 +294,7 @@ void DBAsync::CommitWrites() {
} }
else { else {
if (tmpStatus != Canceled) { if (tmpStatus != Canceled) {
cout << "Error: Unexpected DBAsyncWork->Status in DBAsync::CommitWrites #2" << endl; std::cout << "Error: Unexpected DBAsyncWork->Status in DBAsync::CommitWrites #2" << std::endl;
} }
safe_delete(tmpWork); safe_delete(tmpWork);
} }
@ -305,7 +305,7 @@ void DBAsync::ProcessWork(DBAsyncWork* iWork, bool iSleep) {
_CP(DBAsync_ProcessWork); _CP(DBAsync_ProcessWork);
DBAsyncQuery* CurrentQuery; DBAsyncQuery* CurrentQuery;
#if DEBUG_MYSQL_QUERIES >= 2 #if DEBUG_MYSQL_QUERIES >= 2
cout << "Processing AsyncWork #" << iWork->GetWorkID() << endl; std::cout << "Processing AsyncWork #" << iWork->GetWorkID() << std::endl;
#endif #endif
while ((CurrentQuery = iWork->PopQuery())) { while ((CurrentQuery = iWork->PopQuery())) {
CurrentQuery->Process(pDBC); CurrentQuery->Process(pDBC);

View File

@ -5,7 +5,6 @@
#endif #endif
#include <iostream> #include <iostream>
using namespace std;
#include <errmsg.h> #include <errmsg.h>
#include <mysqld_error.h> #include <mysqld_error.h>
#include <limits.h> #include <limits.h>
@ -72,17 +71,17 @@ bool DBcore::RunQuery(const char* query, uint32 querylen, char* errbuf, MYSQL_RE
#if DEBUG_MYSQL_QUERIES >= 1 #if DEBUG_MYSQL_QUERIES >= 1
char tmp[120]; char tmp[120];
strn0cpy(tmp, query, sizeof(tmp)); strn0cpy(tmp, query, sizeof(tmp));
cout << "QUERY: " << tmp << endl; std::cout << "QUERY: " << tmp << std::endl;
#endif #endif
if (mysql_real_query(&mysql, query, querylen)) { if (mysql_real_query(&mysql, query, querylen)) {
if (mysql_errno(&mysql) == CR_SERVER_GONE_ERROR) if (mysql_errno(&mysql) == CR_SERVER_GONE_ERROR)
pStatus = Error; pStatus = Error;
if (mysql_errno(&mysql) == CR_SERVER_LOST || mysql_errno(&mysql) == CR_SERVER_GONE_ERROR) { if (mysql_errno(&mysql) == CR_SERVER_LOST || mysql_errno(&mysql) == CR_SERVER_GONE_ERROR) {
if (retry) { if (retry) {
cout << "Database Error: Lost connection, attempting to recover...." << endl; std::cout << "Database Error: Lost connection, attempting to recover...." << std::endl;
ret = RunQuery(query, querylen, errbuf, result, affected_rows, last_insert_id, errnum, false); ret = RunQuery(query, querylen, errbuf, result, affected_rows, last_insert_id, errnum, false);
if (ret) if (ret)
cout << "Reconnection to database successful." << endl; std::cout << "Reconnection to database successful." << std::endl;
} }
else { else {
pStatus = Error; pStatus = Error;
@ -90,7 +89,7 @@ bool DBcore::RunQuery(const char* query, uint32 querylen, char* errbuf, MYSQL_RE
*errnum = mysql_errno(&mysql); *errnum = mysql_errno(&mysql);
if (errbuf) if (errbuf)
snprintf(errbuf, MYSQL_ERRMSG_SIZE, "#%i: %s", mysql_errno(&mysql), mysql_error(&mysql)); snprintf(errbuf, MYSQL_ERRMSG_SIZE, "#%i: %s", mysql_errno(&mysql), mysql_error(&mysql));
cout << "DB Query Error #" << mysql_errno(&mysql) << ": " << mysql_error(&mysql) << endl; std::cout << "DB Query Error #" << mysql_errno(&mysql) << ": " << mysql_error(&mysql) << std::endl;
ret = false; ret = false;
} }
} }
@ -100,7 +99,7 @@ bool DBcore::RunQuery(const char* query, uint32 querylen, char* errbuf, MYSQL_RE
if (errbuf) if (errbuf)
snprintf(errbuf, MYSQL_ERRMSG_SIZE, "#%i: %s", mysql_errno(&mysql), mysql_error(&mysql)); snprintf(errbuf, MYSQL_ERRMSG_SIZE, "#%i: %s", mysql_errno(&mysql), mysql_error(&mysql));
#ifdef _EQDEBUG #ifdef _EQDEBUG
cout << "DB Query Error #" << mysql_errno(&mysql) << ": " << mysql_error(&mysql) << endl; std::cout << "DB Query Error #" << mysql_errno(&mysql) << ": " << mysql_error(&mysql) << std::endl;
#endif #endif
ret = false; ret = false;
} }
@ -124,7 +123,7 @@ bool DBcore::RunQuery(const char* query, uint32 querylen, char* errbuf, MYSQL_RE
} }
else { else {
#ifdef _EQDEBUG #ifdef _EQDEBUG
cout << "DB Query Error: No Result" << endl; std::cout << "DB Query Error: No Result" << std::endl;
#endif #endif
if (errnum) if (errnum)
*errnum = UINT_MAX; *errnum = UINT_MAX;
@ -139,15 +138,15 @@ bool DBcore::RunQuery(const char* query, uint32 querylen, char* errbuf, MYSQL_RE
} }
#if DEBUG_MYSQL_QUERIES >= 1 #if DEBUG_MYSQL_QUERIES >= 1
if (ret) { if (ret) {
cout << "query successful"; std::cout << "query successful";
if (result && (*result)) if (result && (*result))
cout << ", " << (int) mysql_num_rows(*result) << " rows returned"; std::cout << ", " << (int) mysql_num_rows(*result) << " rows returned";
if (affected_rows) if (affected_rows)
cout << ", " << (*affected_rows) << " rows affected"; std::cout << ", " << (*affected_rows) << " rows affected";
cout<< endl; std::cout<< std::endl;
} }
else { else {
cout << "QUERY: query FAILED" << endl; std::cout << "QUERY: query FAILED" << std::endl;
} }
#endif #endif
return ret; return ret;

View File

@ -7,7 +7,6 @@
//#include <winsock.h> //#include <winsock.h>
#endif #endif
#include <mysql.h> #include <mysql.h>
#include "../common/DBMemLeak.h"
#include "../common/types.h" #include "../common/types.h"
#include "../common/Mutex.h" #include "../common/Mutex.h"
#include "../common/linked_list.h" #include "../common/linked_list.h"

View File

@ -1,25 +1,27 @@
#include "debug.h"
#include <iostream> #include <iostream>
using namespace std; #include <string>
#include <cstdarg>
#include <time.h> #include <time.h>
#include <string.h>
#ifdef _WINDOWS #ifdef _WINDOWS
#include <process.h> #include <process.h>
#define snprintf _snprintf #define snprintf _snprintf
#if (_MSC_VER < 1500)
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#endif
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#define strcasecmp _stricmp #define strcasecmp _stricmp
#else #else
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <stdarg.h>
#endif #endif
#include "../common/MiscFunctions.h"
#include "../common/platform.h" #include "debug.h"
#include "StringUtil.h"
#include "MiscFunctions.h"
#include "platform.h"
#ifndef va_copy #ifndef va_copy
#define va_copy(d,s) ((d) = (s)) #define va_copy(d,s) ((d) = (s))
@ -112,7 +114,7 @@ bool EQEMuLog::open(LogIDs id) {
#endif #endif
fp[id] = fopen(filename, "a"); fp[id] = fopen(filename, "a");
if (!fp[id]) { 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 pLogStatus[id] |= 4; // set file state to error
return false; return false;
} }
@ -328,7 +330,7 @@ bool EQEMuLog::writeNTS(LogIDs id, bool dofile, const char *fmt, ...) {
bool EQEMuLog::Dump(LogIDs id, uint8* data, uint32 size, uint32 cols, uint32 skip) { bool EQEMuLog::Dump(LogIDs id, uint8* data, uint32 size, uint32 cols, uint32 skip) {
if (!logFileValid) { if (!logFileValid) {
#if EQDEBUG >= 10 #if EQDEBUG >= 10
cerr << "Error: Dump() from null pointer"<<endl; std::cerr << "Error: Dump() from null pointer" << std::endl;
#endif #endif
return false; return false;
} }
@ -350,36 +352,45 @@ bool EQEMuLog::Dump(LogIDs id, uint8* data, uint32 size, uint32 cols, uint32 ski
write(id, "Dumping Packet: %i", size); write(id, "Dumping Packet: %i", size);
// Output as HEX // Output as HEX
int j = 0; char* ascii = new char[cols+1]; memset(ascii, 0, cols+1);
uint32 i; int beginningOfLineOffset = 0;
for(i=skip; i<size; i++) { uint32 indexInData;
if ((i-skip)%cols==0) { std::string asciiOutput;
if (i != skip)
writeNTS(id, dofile, " | %s\n", ascii); for(indexInData=skip; indexInData<size; indexInData++) {
writeNTS(id, dofile, "%4i: ", i-skip); if ((indexInData-skip)%cols==0) {
memset(ascii, 0, cols+1); if (indexInData != skip)
j = 0; writeNTS(id, dofile, " | %s\n", asciiOutput.c_str());
writeNTS(id, dofile, "%4i: ", indexInData-skip);
asciiOutput.clear();
beginningOfLineOffset = 0;
} }
else if ((i-skip)%(cols/2) == 0) { else if ((indexInData-skip)%(cols/2) == 0) {
writeNTS(id, dofile, "- "); writeNTS(id, dofile, "- ");
} }
writeNTS(id, dofile, "%02X ", (unsigned char)data[i]); writeNTS(id, dofile, "%02X ", (unsigned char)data[indexInData]);
if (data[i] >= 32 && data[i] < 127) if (data[indexInData] >= 32 && data[indexInData] < 127)
ascii[j++] = data[i]; {
// 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(std::to_string((long long)data[indexInData]));
}
else else
ascii[j++] = '.'; {
asciiOutput.append(".");
}
} }
uint32 k = ((i-skip)-1)%cols; uint32 k = ((indexInData-skip)-1)%cols;
if (k < 8) if (k < 8)
writeNTS(id, dofile, " "); writeNTS(id, dofile, " ");
for (uint32 h = k+1; h < cols; h++) { for (uint32 h = k+1; h < cols; h++) {
writeNTS(id, dofile, " "); writeNTS(id, dofile, " ");
} }
writeNTS(id, dofile, " | %s\n", ascii); writeNTS(id, dofile, " | %s\n", asciiOutput.c_str());
if (dofile) if (dofile)
fflush(fp[id]); fflush(fp[id]);
safe_delete_array(ascii);
return true; return true;
} }

View File

@ -45,22 +45,9 @@
#ifndef _CRTDBG_MAP_ALLOC #ifndef _CRTDBG_MAP_ALLOC
#include <stdlib.h> #include <stdlib.h>
#include <crtdbg.h> #include <crtdbg.h>
#if (_MSC_VER < 1300)
#include <new>
#include <memory>
#define _CRTDBG_MAP_ALLOC
#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
#endif
#endif #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 #ifndef EQDEBUG_H
#define EQDEBUG_H #define EQDEBUG_H

View File

@ -95,11 +95,11 @@ namespace EQEmu
*/ */
const char* what() const throw() { return full_description().c_str(); } const char* what() const throw() { return full_description().c_str(); }
protected: protected:
std::string name_; //!< Exception name
std::string desc_; //!< Exception Description
mutable std::string full_desc_; //!< Full Exception Description mutable std::string full_desc_; //!< Full Exception Description
std::string file_; //!< File Name
long line_; //<! File Line long line_; //<! File Line
std::string file_; //!< File Name
std::string desc_; //!< Exception Description
std::string name_; //!< Exception name
}; };
} // EQEmu } // EQEmu

View File

@ -22,7 +22,6 @@
#include "../common/eq_packet_structs.h" #include "../common/eq_packet_structs.h"
#include <memory.h> #include <memory.h>
#include <iostream> #include <iostream>
using namespace std;
/*#ifdef _CRTDBG_MAP_ALLOC /*#ifdef _CRTDBG_MAP_ALLOC
#undef new #undef new
#endif*/ #endif*/
@ -137,7 +136,7 @@ int EQTime::setEQTimeOfDay(TimeOfDay_Struct start_eq, time_t start_real)
//For some reason, ifstream/ofstream have problems with EQEmu datatypes in files. //For some reason, ifstream/ofstream have problems with EQEmu datatypes in files.
bool EQTime::saveFile(const char *filename) bool EQTime::saveFile(const char *filename)
{ {
ofstream of; std::ofstream of;
of.open(filename); of.open(filename);
if(!of) if(!of)
{ {
@ -146,13 +145,13 @@ bool EQTime::saveFile(const char *filename)
} }
//Enable for debugging //Enable for debugging
//cout << "SAVE: day=" << (long)eqTime.start_eqtime.day << ";hour=" << (long)eqTime.start_eqtime.hour << ";min=" << (long)eqTime.start_eqtime.minute << ";mon=" << (long)eqTime.start_eqtime.month << ";yr=" << eqTime.start_eqtime.year << ";timet=" << eqTime.start_realtime << endl; //cout << "SAVE: day=" << (long)eqTime.start_eqtime.day << ";hour=" << (long)eqTime.start_eqtime.hour << ";min=" << (long)eqTime.start_eqtime.minute << ";mon=" << (long)eqTime.start_eqtime.month << ";yr=" << eqTime.start_eqtime.year << ";timet=" << eqTime.start_realtime << endl;
of << EQT_VERSION << endl; of << EQT_VERSION << std::endl;
of << (long)eqTime.start_eqtime.day << endl; of << (long)eqTime.start_eqtime.day << std::endl;
of << (long)eqTime.start_eqtime.hour << endl; of << (long)eqTime.start_eqtime.hour << std::endl;
of << (long)eqTime.start_eqtime.minute << endl; of << (long)eqTime.start_eqtime.minute << std::endl;
of << (long)eqTime.start_eqtime.month << endl; of << (long)eqTime.start_eqtime.month << std::endl;
of << eqTime.start_eqtime.year << endl; of << eqTime.start_eqtime.year << std::endl;
of << eqTime.start_realtime << endl; of << eqTime.start_realtime << std::endl;
of.close(); of.close();
return true; return true;
} }
@ -161,7 +160,7 @@ bool EQTime::loadFile(const char *filename)
{ {
int version=0; int version=0;
long in_data=0; long in_data=0;
ifstream in; std::ifstream in;
in.open(filename); in.open(filename);
if(!in) if(!in)
{ {
@ -265,7 +264,7 @@ void EQTime::AddMinutes(uint32 minutes, TimeOfDay_Struct *to) {
to->year += (cur-1) / 12; to->year += (cur-1) / 12;
} }
void EQTime::ToString(TimeOfDay_Struct *t, string &str) { void EQTime::ToString(TimeOfDay_Struct *t, std::string &str) {
char buf[128]; char buf[128];
snprintf(buf, 128, "%.2d/%.2d/%.4d %.2d:%.2d", snprintf(buf, 128, "%.2d/%.2d/%.4d %.2d:%.2d",
t->month, t->day, t->year, t->hour, t->minute); t->month, t->day, t->year, t->hour, t->minute);

View File

@ -4,8 +4,6 @@
#include "../common/eq_packet_structs.h" #include "../common/eq_packet_structs.h"
#include <string> #include <string>
using namespace std;
//Struct //Struct
struct eqTimeOfDay struct eqTimeOfDay
{ {
@ -39,7 +37,7 @@ public:
static bool IsTimeBefore(TimeOfDay_Struct *base, TimeOfDay_Struct *test); //is test before base static bool IsTimeBefore(TimeOfDay_Struct *base, TimeOfDay_Struct *test); //is test before base
static void AddMinutes(uint32 minutes, TimeOfDay_Struct *to); static void AddMinutes(uint32 minutes, TimeOfDay_Struct *to);
static void ToString(TimeOfDay_Struct *t, string &str); static void ToString(TimeOfDay_Struct *t, std::string &str);
//Database functions //Database functions
//bool loadDB(Database q); //bool loadDB(Database q);

View File

@ -20,7 +20,8 @@
#include "guild_base.h" #include "guild_base.h"
#include "database.h" #include "database.h"
#include "logsys.h" #include "logsys.h"
#include "MiscFunctions.h" //#include "MiscFunctions.h"
#include "StringUtil.h"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@ -52,7 +53,7 @@ bool BaseGuildManager::LoadGuilds() {
char *query = 0; char *query = 0;
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
map<uint32, GuildInfo *>::iterator res; std::map<uint32, GuildInfo *>::iterator res;
// load up all the guilds // load up all the guilds
if (!m_db->RunQuery(query, MakeAnyLenString(&query, if (!m_db->RunQuery(query, MakeAnyLenString(&query,
@ -116,7 +117,7 @@ bool BaseGuildManager::RefreshGuild(uint32 guild_id) {
char *query = 0; char *query = 0;
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
map<uint32, GuildInfo *>::iterator res; std::map<uint32, GuildInfo *>::iterator res;
GuildInfo *info; GuildInfo *info;
// load up all the guilds // load up all the guilds
@ -173,7 +174,7 @@ bool BaseGuildManager::RefreshGuild(uint32 guild_id) {
BaseGuildManager::GuildInfo *BaseGuildManager::_CreateGuild(uint32 guild_id, const char *guild_name, uint32 leader_char_id, uint8 minstatus, const char *guild_motd, const char *motd_setter, const char *Channel, const char *URL) BaseGuildManager::GuildInfo *BaseGuildManager::_CreateGuild(uint32 guild_id, const char *guild_name, uint32 leader_char_id, uint8 minstatus, const char *guild_motd, const char *motd_setter, const char *Channel, const char *URL)
{ {
map<uint32, GuildInfo *>::iterator res; std::map<uint32, GuildInfo *>::iterator res;
//remove any old entry. //remove any old entry.
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
@ -222,7 +223,7 @@ bool BaseGuildManager::_StoreGuildDB(uint32 guild_id) {
return(false); return(false);
} }
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) { if(res == m_guilds.end()) {
_log(GUILDS__DB, "Requested to store non-existent guild %d", guild_id); _log(GUILDS__DB, "Requested to store non-existent guild %d", guild_id);
@ -376,7 +377,7 @@ bool BaseGuildManager::RenameGuild(uint32 guild_id, const char* name) {
bool BaseGuildManager::SetGuildLeader(uint32 guild_id, uint32 leader_char_id) { bool BaseGuildManager::SetGuildLeader(uint32 guild_id, uint32 leader_char_id) {
//get old leader first. //get old leader first.
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(false); return(false);
@ -516,7 +517,7 @@ uint32 BaseGuildManager::DBCreateGuild(const char* name, uint32 leader) {
bool BaseGuildManager::DBDeleteGuild(uint32 guild_id) { bool BaseGuildManager::DBDeleteGuild(uint32 guild_id) {
//remove the local entry //remove the local entry
map<uint32, GuildInfo *>::iterator res; std::map<uint32, GuildInfo *>::iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res != m_guilds.end()) { if(res != m_guilds.end()) {
delete res->second; delete res->second;
@ -557,7 +558,7 @@ bool BaseGuildManager::DBRenameGuild(uint32 guild_id, const char* name) {
return(false); return(false);
} }
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(false); return(false);
@ -597,7 +598,7 @@ bool BaseGuildManager::DBSetGuildLeader(uint32 guild_id, uint32 leader) {
return(false); return(false);
} }
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(false); return(false);
@ -637,7 +638,7 @@ bool BaseGuildManager::DBSetGuildMOTD(uint32 guild_id, const char* motd, const c
return(false); return(false);
} }
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(false); return(false);
@ -682,7 +683,7 @@ bool BaseGuildManager::DBSetGuildURL(uint32 GuildID, const char* URL)
if(m_db == nullptr) if(m_db == nullptr)
return(false); return(false);
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(GuildID); res = m_guilds.find(GuildID);
@ -723,7 +724,7 @@ bool BaseGuildManager::DBSetGuildChannel(uint32 GuildID, const char* Channel)
if(m_db == nullptr) if(m_db == nullptr)
return(false); return(false);
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(GuildID); res = m_guilds.find(GuildID);
@ -978,7 +979,7 @@ static void ProcessGuildMember(MYSQL_ROW &row, CharGuildInfo &into) {
} }
bool BaseGuildManager::GetEntireGuild(uint32 guild_id, vector<CharGuildInfo *> &members) { bool BaseGuildManager::GetEntireGuild(uint32 guild_id, std::vector<CharGuildInfo *> &members) {
members.clear(); members.clear();
if(m_db == nullptr) if(m_db == nullptr)
@ -1109,7 +1110,7 @@ uint8 *BaseGuildManager::MakeGuildList(const char *head_name, uint32 &length) co
strn0cpy((char *) buffer, head_name, 64); strn0cpy((char *) buffer, head_name, 64);
map<uint32, GuildInfo *>::const_iterator cur, end; std::map<uint32, GuildInfo *>::const_iterator cur, end;
cur = m_guilds.begin(); cur = m_guilds.begin();
end = m_guilds.end(); end = m_guilds.end();
for(; cur != end; cur++) { for(; cur != end; cur++) {
@ -1122,7 +1123,7 @@ uint8 *BaseGuildManager::MakeGuildList(const char *head_name, uint32 &length) co
const char *BaseGuildManager::GetRankName(uint32 guild_id, uint8 rank) const { const char *BaseGuildManager::GetRankName(uint32 guild_id, uint8 rank) const {
if(rank > GUILD_MAX_RANK) if(rank > GUILD_MAX_RANK)
return("Invalid Rank"); return("Invalid Rank");
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return("Invalid Guild Rank"); return("Invalid Guild Rank");
@ -1132,7 +1133,7 @@ const char *BaseGuildManager::GetRankName(uint32 guild_id, uint8 rank) const {
const char *BaseGuildManager::GetGuildName(uint32 guild_id) const { const char *BaseGuildManager::GetGuildName(uint32 guild_id) const {
if(guild_id == GUILD_NONE) if(guild_id == GUILD_NONE)
return(""); return("");
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return("Invalid Guild"); return("Invalid Guild");
@ -1140,7 +1141,7 @@ const char *BaseGuildManager::GetGuildName(uint32 guild_id) const {
} }
bool BaseGuildManager::GetGuildNameByID(uint32 guild_id, std::string &into) const { bool BaseGuildManager::GetGuildNameByID(uint32 guild_id, std::string &into) const {
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(false); return(false);
@ -1150,7 +1151,7 @@ bool BaseGuildManager::GetGuildNameByID(uint32 guild_id, std::string &into) cons
uint32 BaseGuildManager::GetGuildIDByName(const char *GuildName) uint32 BaseGuildManager::GetGuildIDByName(const char *GuildName)
{ {
map<uint32, GuildInfo *>::iterator Iterator; std::map<uint32, GuildInfo *>::iterator Iterator;
for(Iterator = m_guilds.begin(); Iterator != m_guilds.end(); ++Iterator) for(Iterator = m_guilds.begin(); Iterator != m_guilds.end(); ++Iterator)
{ {
@ -1162,7 +1163,7 @@ uint32 BaseGuildManager::GetGuildIDByName(const char *GuildName)
} }
bool BaseGuildManager::GetGuildMOTD(uint32 guild_id, char *motd_buffer, char *setter_buffer) const { bool BaseGuildManager::GetGuildMOTD(uint32 guild_id, char *motd_buffer, char *setter_buffer) const {
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(false); return(false);
@ -1173,7 +1174,7 @@ bool BaseGuildManager::GetGuildMOTD(uint32 guild_id, char *motd_buffer, char *se
bool BaseGuildManager::GetGuildURL(uint32 GuildID, char *URLBuffer) const bool BaseGuildManager::GetGuildURL(uint32 GuildID, char *URLBuffer) const
{ {
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(GuildID); res = m_guilds.find(GuildID);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(false); return(false);
@ -1184,7 +1185,7 @@ bool BaseGuildManager::GetGuildURL(uint32 GuildID, char *URLBuffer) const
bool BaseGuildManager::GetGuildChannel(uint32 GuildID, char *ChannelBuffer) const bool BaseGuildManager::GetGuildChannel(uint32 GuildID, char *ChannelBuffer) const
{ {
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(GuildID); res = m_guilds.find(GuildID);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(false); return(false);
@ -1203,7 +1204,7 @@ bool BaseGuildManager::IsGuildLeader(uint32 guild_id, uint32 char_id) const {
_log(GUILDS__PERMISSIONS, "Check leader for char %d: not a guild.", char_id); _log(GUILDS__PERMISSIONS, "Check leader for char %d: not a guild.", char_id);
return(false); return(false);
} }
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) { if(res == m_guilds.end()) {
_log(GUILDS__PERMISSIONS, "Check leader for char %d: invalid guild.", char_id); _log(GUILDS__PERMISSIONS, "Check leader for char %d: invalid guild.", char_id);
@ -1214,7 +1215,7 @@ bool BaseGuildManager::IsGuildLeader(uint32 guild_id, uint32 char_id) const {
} }
uint32 BaseGuildManager::FindGuildByLeader(uint32 leader) const { uint32 BaseGuildManager::FindGuildByLeader(uint32 leader) const {
map<uint32, GuildInfo *>::const_iterator cur, end; std::map<uint32, GuildInfo *>::const_iterator cur, end;
cur = m_guilds.begin(); cur = m_guilds.begin();
end = m_guilds.end(); end = m_guilds.end();
for(; cur != end; cur++) { for(; cur != end; cur++) {
@ -1226,7 +1227,7 @@ uint32 BaseGuildManager::FindGuildByLeader(uint32 leader) const {
//returns the rank to be sent to the client for display purposes, given their eqemu rank. //returns the rank to be sent to the client for display purposes, given their eqemu rank.
uint8 BaseGuildManager::GetDisplayedRank(uint32 guild_id, uint8 rank, uint32 char_id) const { uint8 BaseGuildManager::GetDisplayedRank(uint32 guild_id, uint8 rank, uint32 char_id) const {
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(3); //invalid guild rank return(3); //invalid guild rank
@ -1243,7 +1244,7 @@ bool BaseGuildManager::CheckGMStatus(uint32 guild_id, uint8 status) const {
return(true); //250+ as allowed anything return(true); //250+ as allowed anything
} }
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) { if(res == m_guilds.end()) {
_log(GUILDS__PERMISSIONS, "Check permission on guild %d with user status %d, no such guild, denied.", guild_id, status); _log(GUILDS__PERMISSIONS, "Check permission on guild %d with user status %d, no such guild, denied.", guild_id, status);
@ -1264,7 +1265,7 @@ bool BaseGuildManager::CheckPermission(uint32 guild_id, uint8 rank, GuildAction
guild_id, rank, GuildActionNames[act], act); guild_id, rank, GuildActionNames[act], act);
return(false); //invalid rank return(false); //invalid rank
} }
map<uint32, GuildInfo *>::const_iterator res; std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) { if(res == m_guilds.end()) {
_log(GUILDS__PERMISSIONS, "Check permission on guild %d and rank %d for action %s (%d): Invalid guild, denied.", _log(GUILDS__PERMISSIONS, "Check permission on guild %d and rank %d for action %s (%d): Invalid guild, denied.",
@ -1284,7 +1285,7 @@ bool BaseGuildManager::CheckPermission(uint32 guild_id, uint8 rank, GuildAction
} }
bool BaseGuildManager::LocalDeleteGuild(uint32 guild_id) { bool BaseGuildManager::LocalDeleteGuild(uint32 guild_id) {
map<uint32, GuildInfo *>::iterator res; std::map<uint32, GuildInfo *>::iterator res;
res = m_guilds.find(guild_id); res = m_guilds.find(guild_id);
if(res == m_guilds.end()) if(res == m_guilds.end())
return(false); //invalid guild return(false); //invalid guild
@ -1293,7 +1294,7 @@ bool BaseGuildManager::LocalDeleteGuild(uint32 guild_id) {
} }
void BaseGuildManager::ClearGuilds() { void BaseGuildManager::ClearGuilds() {
map<uint32, GuildInfo *>::iterator cur, end; std::map<uint32, GuildInfo *>::iterator cur, end;
cur = m_guilds.begin(); cur = m_guilds.begin();
end = m_guilds.end(); end = m_guilds.end();
for(; cur != end; cur++) { for(; cur != end; cur++) {

View File

@ -18,9 +18,12 @@
#include "debug.h" #include "debug.h"
#include "logsys.h" #include "logsys.h"
#include "StringUtil.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <string>
void log_message(LogType type, const char *fmt, ...) { void log_message(LogType type, const char *fmt, ...) {
va_list args; va_list args;
@ -30,10 +33,10 @@ void log_message(LogType type, const char *fmt, ...) {
} }
void log_messageVA(LogType type, const char *fmt, va_list args) { void log_messageVA(LogType type, const char *fmt, va_list args) {
char prefix_buffer[256]; std::string prefix_buffer;
snprintf(prefix_buffer, 255, "[%s] ", log_type_info[type].name);
prefix_buffer[255] = '\0'; StringFormat(prefix_buffer, "[%s] ", log_type_info[type].name);
LogFile->writePVA(EQEMuLog::Debug, prefix_buffer, fmt, args); LogFile->writePVA(EQEMuLog::Debug, prefix_buffer.c_str(), fmt, args);
} }

View File

@ -9,7 +9,7 @@
*/ */
#include <string.h> /* for memcpy() */ #include <string.h> /* for memcpy() */
#include "../common/md5.h" #include "../common/md5.h"
#include "../common/MiscFunctions.h" #include "../common/StringUtil.h"
#include "../common/seperator.h" #include "../common/seperator.h"
MD5::MD5() { MD5::MD5() {

View File

@ -18,12 +18,10 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
using namespace std;
#define ENC(c) (((c) & 0x3f) + ' ') #define ENC(c) (((c) & 0x3f) + ' ')
#define DEC(c) (((c) - ' ') & 0x3f) #define DEC(c) (((c) - ' ') & 0x3f)
map<int,string> DBFieldNames; std::map<int,std::string> DBFieldNames;
#ifndef WIN32 #ifndef WIN32
#if defined(FREEBSD) || defined(__CYGWIN__) #if defined(FREEBSD) || defined(__CYGWIN__)
@ -44,9 +42,9 @@ int print_stacktrace()
if (names != nullptr) if (names != nullptr)
{ {
int i; int i;
cerr << "called from " << (char*)names[0] << endl; std::cerr << "called from " << (char*)names[0] << std::endl;
for (i = 1; i < n; ++i) for (i = 1; i < n; ++i)
cerr << " " << (char*)names[i] << endl; std::cerr << " " << (char*)names[i] << std::endl;
free (names); free (names);
} }
} }
@ -55,19 +53,19 @@ int print_stacktrace()
#endif //!FREEBSD #endif //!FREEBSD
#endif //!WIN32 #endif //!WIN32
void Unprotect(string &s, char what) void Unprotect(std::string &s, char what)
{ {
if (s.length()) { if (s.length()) {
for(string::size_type i=0;i<s.length()-1;i++) { for(std::string::size_type i=0;i<s.length()-1;i++) {
if (s[i]=='\\' && s[i+1]==what) if (s[i]=='\\' && s[i+1]==what)
s.erase(i,1); s.erase(i,1);
} }
} }
} }
void Protect(string &s, char what) void Protect(std::string &s, char what)
{ {
for(string::size_type i=0;i<s.length();i++) { for(std::string::size_type i=0;i<s.length();i++) {
if (s[i]==what) if (s[i]==what)
s.insert(i++,"\\"); s.insert(i++,"\\");
} }
@ -77,11 +75,11 @@ void Protect(string &s, char what)
item id -> fields_list item id -> fields_list
each fields_list is a map of field index -> value each fields_list is a map of field index -> value
*/ */
bool ItemParse(const char *data, int length, map<int,map<int,string> > &items, int id_pos, int name_pos, int max_field, int level) bool ItemParse(const char *data, int length, std::map<int,std::map<int,std::string> > &items, int id_pos, int name_pos, int max_field, int level)
{ {
int i; int i;
char *end,*ptr; char *end,*ptr;
map<int,string> field; std::map<int,std::string> field;
static char *buffer=nullptr; static char *buffer=nullptr;
static int buffsize=0; static int buffsize=0;
static char *temp=nullptr; static char *temp=nullptr;
@ -102,7 +100,7 @@ static char *temp=nullptr;
break; break;
} }
if (!end) { if (!end) {
cerr << "ItemParse: Level " << level << ": (1) Expected '|' not found near '" << ptr << "'" << endl; std::cerr << "ItemParse: Level " << level << ": (1) Expected '|' not found near '" << ptr << "'" << std::endl;
return false; return false;
} else { } else {
*end=0; *end=0;
@ -114,7 +112,7 @@ static char *temp=nullptr;
} }
if (*ptr!='"') { if (*ptr!='"') {
cerr << "ItemParse: Level " << level << ": (2) Expected '\"' not found near '" << ptr << "'" << endl; std::cerr << "ItemParse: Level " << level << ": (2) Expected '\"' not found near '" << ptr << "'" << std::endl;
return false; return false;
} }
ptr++; ptr++;
@ -126,7 +124,7 @@ static char *temp=nullptr;
break; break;
} }
if (!end) { if (!end) {
cerr << "ItemParse: Level " << level << ": (1) Expected '|' not found near '" << ptr << "'" << endl; std::cerr << "ItemParse: Level " << level << ": (1) Expected '|' not found near '" << ptr << "'" << std::endl;
return false; return false;
} else { } else {
*end=0; *end=0;
@ -145,12 +143,12 @@ static char *temp=nullptr;
Unprotect(field[i],'|'); Unprotect(field[i],'|');
ptr+=length; ptr+=length;
} else { } else {
cerr << "ItemParse: Level " << level << ": (4) Expected '\"' not found near '" << ptr << "'" << endl; std::cerr << "ItemParse: Level " << level << ": (4) Expected '\"' not found near '" << ptr << "'" << std::endl;
return false; return false;
} }
if (*ptr!='|') { if (*ptr!='|') {
cerr << "ItemParse: Level " << level << ": (5) Expected '|' not found near '" << ptr << "'" << endl; std::cerr << "ItemParse: Level " << level << ": (5) Expected '|' not found near '" << ptr << "'" << std::endl;
return false; return false;
} }
ptr++; ptr++;
@ -162,7 +160,7 @@ static char *temp=nullptr;
end=ptr; end=ptr;
while((end=strchr(end+1,'"'))!=nullptr && *(end-1)=='\\'); while((end=strchr(end+1,'"'))!=nullptr && *(end-1)=='\\');
if (end) { if (end) {
string sub; std::string sub;
sub.assign(ptr+1,end-ptr-1); sub.assign(ptr+1,end-ptr-1);
Unprotect(sub,'"'); Unprotect(sub,'"');
if (!ItemParse(sub.c_str(),sub.length(),items,id_pos,name_pos,max_field,level+1)) { if (!ItemParse(sub.c_str(),sub.length(),items,id_pos,name_pos,max_field,level+1)) {
@ -170,14 +168,14 @@ static char *temp=nullptr;
} }
ptr=end+1; ptr=end+1;
} else { } else {
cerr << "ItemParse: Level " << level << ": (6) Expected closing '\"' not found near '" << (ptr+1) << "'" << endl; std::cerr << "ItemParse: Level " << level << ": (6) Expected closing '\"' not found near '" << (ptr+1) << "'" << std::endl;
return false; return false;
} }
} }
if (*ptr=='|') { if (*ptr=='|') {
ptr++; ptr++;
} else if (i<9) { } else if (i<9) {
cerr << "ItemParse: Level " << level << ": (7) Expected '|' (#" << i << ") not found near '" << ptr << "'" << endl; std::cerr << "ItemParse: Level " << level << ": (7) Expected '|' (#" << i << ") not found near '" << ptr << "'" << std::endl;
return false; return false;
} }
@ -185,12 +183,12 @@ static char *temp=nullptr;
return true; return true;
} }
int Tokenize(string s,map<int,string> & tokens, char delim) int Tokenize(std::string s,std::map<int,std::string> & tokens, char delim)
{ {
int i,len; int i,len;
string::size_type end; std::string::size_type end;
//char temp[1024]; //char temp[1024];
string x; std::string x;
tokens.clear(); tokens.clear();
i=0; i=0;
while(s.length()) { while(s.length()) {
@ -199,10 +197,10 @@ string x;
tokens[i++]=""; tokens[i++]="";
} else { } else {
end=0; end=0;
while((end=s.find(delim,end+1))!=string::npos && s[end-1]=='\\'); while((end=s.find(delim,end+1))!=std::string::npos && s[end-1]=='\\');
if (end!=string::npos) { if (end!=std::string::npos) {
x=s; x=s;
x.erase(end,string::npos); x.erase(end,std::string::npos);
s.erase(0,end+1); s.erase(0,end+1);
Unprotect(x,'|'); Unprotect(x,'|');
tokens[i++]=x; tokens[i++]=x;
@ -392,7 +390,7 @@ void decode_chunk(char *in, char *out)
*(out+2) = DEC(in[2]) << 6 | DEC(in[3]); *(out+2) = DEC(in[2]) << 6 | DEC(in[3]);
} }
void dump_message_column(unsigned char *buffer, unsigned long length, string leader, FILE *to) void dump_message_column(unsigned char *buffer, unsigned long length, std::string leader, FILE *to)
{ {
unsigned long i,j; unsigned long i,j;
unsigned long rows,offset=0; unsigned long rows,offset=0;
@ -418,7 +416,7 @@ unsigned long rows,offset=0;
} }
} }
string long2ip(unsigned long ip) std::string long2ip(unsigned long ip)
{ {
char temp[16]; char temp[16];
union { unsigned long ip; struct { unsigned char a,b,c,d; } octet;} ipoctet; union { unsigned long ip; struct { unsigned char a,b,c,d; } octet;} ipoctet;
@ -426,10 +424,10 @@ union { unsigned long ip; struct { unsigned char a,b,c,d; } octet;} ipoctet;
ipoctet.ip=ip; ipoctet.ip=ip;
sprintf(temp,"%d.%d.%d.%d",ipoctet.octet.a,ipoctet.octet.b,ipoctet.octet.c,ipoctet.octet.d); sprintf(temp,"%d.%d.%d.%d",ipoctet.octet.a,ipoctet.octet.b,ipoctet.octet.c,ipoctet.octet.d);
return string(temp); return std::string(temp);
} }
string string_from_time(string pattern, time_t now) std::string string_from_time(std::string pattern, time_t now)
{ {
struct tm *now_tm; struct tm *now_tm;
char time_string[51]; char time_string[51];
@ -440,18 +438,18 @@ char time_string[51];
strftime(time_string,51,pattern.c_str(),now_tm); strftime(time_string,51,pattern.c_str(),now_tm);
return string(time_string); return std::string(time_string);
} }
string timestamp(time_t now) std::string timestamp(time_t now)
{ {
return string_from_time("[%Y%m%d.%H%M%S] ",now); return string_from_time("[%Y%m%d.%H%M%S] ",now);
} }
string pop_arg(string &s, string seps, bool obey_quotes) std::string pop_arg(std::string &s, std::string seps, bool obey_quotes)
{ {
string ret; std::string ret;
unsigned long i; unsigned long i;
bool in_quote=false; bool in_quote=false;
@ -463,7 +461,7 @@ bool in_quote=false;
} }
if (in_quote) if (in_quote)
continue; continue;
if (seps.find(c)!=string::npos) { if (seps.find(c)!=std::string::npos) {
break; break;
} }
} }
@ -523,9 +521,9 @@ char *bptr;
return (bptr-buffer); return (bptr-buffer);
} }
string generate_key(int length) std::string generate_key(int length)
{ {
string key; std::string key;
//TODO: write this for win32... //TODO: write this for win32...
#ifndef WIN32 #ifndef WIN32
int i; int i;

View File

@ -5,17 +5,15 @@
#include <string> #include <string>
#include <map> #include <map>
using namespace std;
#define ITEMFIELDCOUNT 116 #define ITEMFIELDCOUNT 116
void Unprotect(string &s, char what); void Unprotect(std::string &s, char what);
void Protect(string &s, char what); void Protect(std::string &s, char what);
bool ItemParse(const char *data, int length, map<int,map<int,string> > &items, int id_pos, int name_pos, int max_field, int level=0); bool ItemParse(const char *data, int length, std::map<int,std::map<int,std::string> > &items, int id_pos, int name_pos, int max_field, int level=0);
int Tokenize(string s, map<int,string> & tokens, char delim='|'); int Tokenize(std::string s, std::map<int,std::string> & tokens, char delim='|');
void LoadItemDBFieldNames(); void LoadItemDBFieldNames();
@ -30,13 +28,13 @@ void decode_chunk(char *in, char *out);
int print_stacktrace(); int print_stacktrace();
#endif #endif
void dump_message_column(unsigned char *buffer, unsigned long length, string leader="", FILE *to = stdout); void dump_message_column(unsigned char *buffer, unsigned long length, std::string leader="", FILE *to = stdout);
string string_from_time(string pattern, time_t now=0); std::string string_from_time(std::string pattern, time_t now=0);
string timestamp(time_t now=0); std::string timestamp(time_t now=0);
string long2ip(unsigned long ip); std::string long2ip(unsigned long ip);
string pop_arg(string &s, string seps, bool obey_quotes); std::string pop_arg(std::string &s, std::string seps, bool obey_quotes);
int EQsprintf(char *buffer, const char *pattern, const char *arg1, const char *arg2, const char *arg3, const char *arg4, const char *arg5, const char *arg6, const char *arg7, const char *arg8, const char *arg9); int EQsprintf(char *buffer, const char *pattern, const char *arg1, const char *arg2, const char *arg3, const char *arg4, const char *arg5, const char *arg6, const char *arg7, const char *arg8, const char *arg9);
string generate_key(int length); std::string generate_key(int length);
void build_hex_line(const char *buffer, unsigned long length, unsigned long offset, char *out_buffer, unsigned char padding=4); void build_hex_line(const char *buffer, unsigned long length, unsigned long offset, char *out_buffer, unsigned char padding=4);
void print_hex(const char *buffer, unsigned long length); void print_hex(const char *buffer, unsigned long length);

View File

@ -2,13 +2,11 @@
#include <map> #include <map>
#include <string> #include <string>
using namespace std; std::map<unsigned long, std::string> opcode_map;
map<unsigned long, string> opcode_map; std::string get_opcode_name(unsigned long opcode)
string get_opcode_name(unsigned long opcode)
{ {
map<unsigned long, string>::iterator itr;; std::map<unsigned long, std::string>::iterator itr;;
return (itr=opcode_map.find(opcode))!=opcode_map.end() ? itr->second : "OP_Unknown"; return (itr=opcode_map.find(opcode))!=opcode_map.end() ? itr->second : "OP_Unknown";
} }

View File

@ -25,7 +25,6 @@
#include <map> #include <map>
#include <string> #include <string>
using namespace std;
OpcodeManager::OpcodeManager() { OpcodeManager::OpcodeManager() {
loaded = false; loaded = false;
@ -38,7 +37,7 @@ bool OpcodeManager::LoadOpcodesFile(const char *filename, OpcodeSetStrategy *s,
return(false); return(false);
} }
map<string, uint16> eq; std::map<std::string, uint16> eq;
//load the opcode file into eq, could swap in a nice XML parser here //load the opcode file into eq, could swap in a nice XML parser here
char line[2048]; char line[2048];
@ -82,7 +81,7 @@ bool OpcodeManager::LoadOpcodesFile(const char *filename, OpcodeSetStrategy *s,
//do the mapping and store them in the shared memory array //do the mapping and store them in the shared memory array
bool ret = true; bool ret = true;
EmuOpcode emu_op; EmuOpcode emu_op;
map<string, uint16>::iterator res; std::map<std::string, uint16>::iterator res;
//stupid enum wont let me ++ on it... //stupid enum wont let me ++ on it...
for(emu_op = OP_Unknown; emu_op < _maxEmuOpcode; emu_op=(EmuOpcode)(emu_op+1)) { for(emu_op = OP_Unknown; emu_op < _maxEmuOpcode; emu_op=(EmuOpcode)(emu_op+1)) {
//get the name of this emu opcode //get the name of this emu opcode
@ -260,13 +259,13 @@ bool EmptyOpcodeManager::ReloadOpcodes(const char *filename, bool report_errors)
} }
uint16 EmptyOpcodeManager::EmuToEQ(const EmuOpcode emu_op) { uint16 EmptyOpcodeManager::EmuToEQ(const EmuOpcode emu_op) {
map<EmuOpcode, uint16>::iterator f; std::map<EmuOpcode, uint16>::iterator f;
f = emu_to_eq.find(emu_op); f = emu_to_eq.find(emu_op);
return(f == emu_to_eq.end()? 0 : f->second); return(f == emu_to_eq.end()? 0 : f->second);
} }
EmuOpcode EmptyOpcodeManager::EQToEmu(const uint16 eq_op) { EmuOpcode EmptyOpcodeManager::EQToEmu(const uint16 eq_op) {
map<uint16, EmuOpcode>::iterator f; std::map<uint16, EmuOpcode>::iterator f;
f = eq_to_emu.find(eq_op); f = eq_to_emu.find(eq_op);
return(f == eq_to_emu.end()?OP_Unknown:f->second); return(f == eq_to_emu.end()?OP_Unknown:f->second);
} }

View File

@ -24,7 +24,6 @@
#include "emu_opcodes.h" #include "emu_opcodes.h"
#include <map> #include <map>
using namespace std;
//enable the use of shared mem opcodes for world and zone only //enable the use of shared mem opcodes for world and zone only
#ifdef ZONE #ifdef ZONE
@ -156,8 +155,8 @@ public:
//fake it, just used for testing anyways //fake it, just used for testing anyways
virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op); virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op);
protected: protected:
map<EmuOpcode, uint16> emu_to_eq; std::map<EmuOpcode, uint16> emu_to_eq;
map<uint16, EmuOpcode> eq_to_emu; std::map<uint16, EmuOpcode> eq_to_emu;
}; };
#endif #endif

View File

@ -20,8 +20,6 @@
#include <iomanip> #include <iomanip>
#include <stdio.h> #include <stdio.h>
using namespace std;
#include "packet_dump.h" #include "packet_dump.h"
#include "EQPacket.h" #include "EQPacket.h"
#include "../common/servertalk.h" #include "../common/servertalk.h"
@ -32,22 +30,22 @@ void DumpPacketAscii(const uchar* buf, uint32 size, uint32 cols, uint32 skip) {
{ {
if ((i-skip)%cols==0) if ((i-skip)%cols==0)
{ {
cout << endl << setw(3) << setfill(' ') << i-skip << ":"; std::cout << std::endl << std::setw(3) << std::setfill(' ') << i-skip << ":";
} }
else if ((i-skip)%(cols/2)==0) else if ((i-skip)%(cols/2)==0)
{ {
cout << " - "; std::cout << " - ";
} }
if (buf[i] > 32 && buf[i] < 127) if (buf[i] > 32 && buf[i] < 127)
{ {
cout << buf[i]; std::cout << buf[i];
} }
else else
{ {
cout << '.'; std::cout << '.';
} }
} }
cout << endl << endl; std::cout << std::endl << std::endl;
} }
void DumpPacketHex(const uchar* buf, uint32 size, uint32 cols, uint32 skip) { void DumpPacketHex(const uchar* buf, uint32 size, uint32 cols, uint32 skip) {
@ -63,16 +61,16 @@ void DumpPacketHex(const uchar* buf, uint32 size, uint32 cols, uint32 skip) {
{ {
if ((i-skip)%cols==0) { if ((i-skip)%cols==0) {
if (i != skip) if (i != skip)
cout << " | " << ascii << endl; std::cout << " | " << ascii << std::endl;
cout << setw(4) << setfill(' ') << i-skip << ": "; std::cout << std::setw(4) << std::setfill(' ') << i-skip << ": ";
memset(ascii, 0, cols+1); memset(ascii, 0, cols+1);
j = 0; j = 0;
} }
else if ((i-skip)%(cols/2) == 0) { else if ((i-skip)%(cols/2) == 0) {
cout << "- "; std::cout << "- ";
} }
sprintf(output, "%02X ", (unsigned char)buf[i]); sprintf(output, "%02X ", (unsigned char)buf[i]);
cout << output; std::cout << output;
if (buf[i] >= 32 && buf[i] < 127) { if (buf[i] >= 32 && buf[i] < 127) {
ascii[j++] = buf[i]; ascii[j++] = buf[i];
@ -84,11 +82,11 @@ void DumpPacketHex(const uchar* buf, uint32 size, uint32 cols, uint32 skip) {
} }
uint32 k = ((i-skip)-1)%cols; uint32 k = ((i-skip)-1)%cols;
if (k < 8) if (k < 8)
cout << " "; std::cout << " ";
for (uint32 h = k+1; h < cols; h++) { for (uint32 h = k+1; h < cols; h++) {
cout << " "; std::cout << " ";
} }
cout << " | " << ascii << endl; std::cout << " | " << ascii << std::endl;
safe_delete_array(ascii); safe_delete_array(ascii);
} }
@ -100,8 +98,8 @@ void DumpPacket(const uchar* buf, uint32 size)
void DumpPacket(const ServerPacket* pack, bool iShowInfo) { void DumpPacket(const ServerPacket* pack, bool iShowInfo) {
if (iShowInfo) { if (iShowInfo) {
cout << "Dumping ServerPacket: 0x" << hex << setfill('0') << setw(4) << pack->opcode << dec; std::cout << "Dumping ServerPacket: 0x" << std::hex << std::setfill('0') << std::setw(4) << pack->opcode << std::dec;
cout << " size:" << pack->size << endl; std::cout << " size:" << pack->size << std::endl;
} }
DumpPacketHex(pack->pBuffer, pack->size); DumpPacketHex(pack->pBuffer, pack->size);
} }
@ -131,66 +129,66 @@ void DumpPacketBin(const void* iData, uint32 len) {
for (k=0; k<len; k++) { for (k=0; k<len; k++) {
if (k % 4 == 0) { if (k % 4 == 0) {
if (k != 0) { if (k != 0) {
cout << " | " << hex << setw(2) << setfill('0') << (int) data[k-4] << dec; std::cout << " | " << std::hex << std::setw(2) << std::setfill('0') << (int) data[k-4] << std::dec;
cout << " " << hex << setw(2) << setfill('0') << (int) data[k-3] << dec; std::cout << " " << std::hex << std::setw(2) << std::setfill('0') << (int) data[k-3] << std::dec;
cout << " " << hex << setw(2) << setfill('0') << (int) data[k-2] << dec; std::cout << " " << std::hex << std::setw(2) << std::setfill('0') << (int) data[k-2] << std::dec;
cout << " " << hex << setw(2) << setfill('0') << (int) data[k-1] << dec; std::cout << " " << std::hex << std::setw(2) << std::setfill('0') << (int) data[k-1] << std::dec;
cout << endl; std::cout << std::endl;
} }
cout << setw(4) << setfill('0') << k << ":"; std::cout << std::setw(4) << std::setfill('0') << k << ":";
} }
else if (k % 2 == 0) else if (k % 2 == 0)
cout << " "; std::cout << " ";
cout << " "; std::cout << " ";
if (data[k] & 1) if (data[k] & 1)
cout << "1"; std::cout << "1";
else else
cout << "0"; std::cout << "0";
if (data[k] & 2) if (data[k] & 2)
cout << "1"; std::cout << "1";
else else
cout << "0"; std::cout << "0";
if (data[k] & 4) if (data[k] & 4)
cout << "1"; std::cout << "1";
else else
cout << "0"; std::cout << "0";
if (data[k] & 8) if (data[k] & 8)
cout << "1"; std::cout << "1";
else else
cout << "0"; std::cout << "0";
if (data[k] & 16) if (data[k] & 16)
cout << "1"; std::cout << "1";
else else
cout << "0"; std::cout << "0";
if (data[k] & 32) if (data[k] & 32)
cout << "1"; std::cout << "1";
else else
cout << "0"; std::cout << "0";
if (data[k] & 64) if (data[k] & 64)
cout << "1"; std::cout << "1";
else else
cout << "0"; std::cout << "0";
if (data[k] & 128) if (data[k] & 128)
cout << "1"; std::cout << "1";
else else
cout << "0"; std::cout << "0";
} }
uint8 tmp = (k % 4); uint8 tmp = (k % 4);
if (!tmp) if (!tmp)
tmp = 4; tmp = 4;
if (tmp <= 3) if (tmp <= 3)
cout << " "; std::cout << " ";
if (tmp <= 2) if (tmp <= 2)
cout << " "; std::cout << " ";
if (tmp <= 1) if (tmp <= 1)
cout << " "; std::cout << " ";
cout << " | " << hex << setw(2) << setfill('0') << (int) data[k-4] << dec; std::cout << " | " << std::hex << std::setw(2) << std::setfill('0') << (int) data[k-4] << std::dec;
if (tmp > 1) if (tmp > 1)
cout << " " << hex << setw(2) << setfill('0') << (int) data[k-3] << dec; std::cout << " " << std::hex << std::setw(2) << std::setfill('0') << (int) data[k-3] << std::dec;
if (tmp > 2) if (tmp > 2)
cout << " " << hex << setw(2) << setfill('0') << (int) data[k-2] << dec; std::cout << " " << std::hex << std::setw(2) << std::setfill('0') << (int) data[k-2] << std::dec;
if (tmp > 3) if (tmp > 3)
cout << " " << hex << setw(2) << setfill('0') << (int) data[k-1] << dec; std::cout << " " << std::hex << std::setw(2) << std::setfill('0') << (int) data[k-1] << std::dec;
cout << endl; std::cout << std::endl;
} }

View File

@ -29,9 +29,6 @@
#ifdef _WINDOWS #ifdef _WINDOWS
#define snprintf _snprintf #define snprintf _snprintf
#if (_MSC_VER < 1500)
#define vsnprintf _vsnprintf
#endif
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#define strcasecmp _stricmp #define strcasecmp _stricmp
#else #else
@ -41,16 +38,14 @@
#include "EQStream.h" #include "EQStream.h"
#include "packet_dump_file.h" #include "packet_dump_file.h"
using namespace std;
void FileDumpPacketAscii(const char* filename, const uchar* buf, uint32 size, uint32 cols, uint32 skip) { void FileDumpPacketAscii(const char* filename, const uchar* buf, uint32 size, uint32 cols, uint32 skip) {
ofstream logfile(filename, ios::app); std::ofstream logfile(filename, std::ios::app);
// Output as ASCII // Output as ASCII
for(uint32 i=skip; i<size; i++) for(uint32 i=skip; i<size; i++)
{ {
if ((i-skip)%cols==0) if ((i-skip)%cols==0)
{ {
logfile << endl << setw(3) << setfill(' ') << i-skip << ":"; logfile << std::endl << std::setw(3) << std::setfill(' ') << i-skip << ":";
} }
else if ((i-skip)%(cols/2)==0) else if ((i-skip)%(cols/2)==0)
{ {
@ -65,19 +60,19 @@ void FileDumpPacketAscii(const char* filename, const uchar* buf, uint32 size, ui
logfile << '.'; logfile << '.';
} }
} }
logfile << endl << endl; logfile << std::endl << std::endl;
} }
void oldFileDumpPacketHex(const char* filename, const uchar* buf, uint32 size, uint32 cols, uint32 skip) void oldFileDumpPacketHex(const char* filename, const uchar* buf, uint32 size, uint32 cols, uint32 skip)
{ {
ofstream logfile(filename, ios::app); std::ofstream logfile(filename, std::ios::app);
// Output as HEX // Output as HEX
char output[4]; char output[4];
for(uint32 i=skip; i<size; i++) for(uint32 i=skip; i<size; i++)
{ {
if ((i-skip)%cols==0) if ((i-skip)%cols==0)
{ {
logfile << endl << setw(3) << setfill(' ') << i-skip << ": "; logfile << std::endl << std::setw(3) << std::setfill(' ') << i-skip << ": ";
} }
else if ((i-skip)%(cols/2) == 0) else if ((i-skip)%(cols/2) == 0)
{ {
@ -87,14 +82,14 @@ void oldFileDumpPacketHex(const char* filename, const uchar* buf, uint32 size, u
logfile << output; logfile << output;
// logfile << setfill(0) << setw(2) << hex << (int)buf[i] << " "; // logfile << setfill(0) << setw(2) << hex << (int)buf[i] << " ";
} }
logfile << endl << endl; logfile << std::endl << std::endl;
} }
void FileDumpPacketHex(const char* filename, const uchar* buf, uint32 size, uint32 cols, uint32 skip) void FileDumpPacketHex(const char* filename, const uchar* buf, uint32 size, uint32 cols, uint32 skip)
{ {
if (size == 0) if (size == 0)
return; return;
ofstream logfile(filename, ios::app); std::ofstream logfile(filename, std::ios::app);
// Output as HEX // Output as HEX
char output[4]; char output[4];
int j = 0; char* ascii = new char[cols+1]; memset(ascii, 0, cols+1); int j = 0; char* ascii = new char[cols+1]; memset(ascii, 0, cols+1);
@ -103,8 +98,8 @@ void FileDumpPacketHex(const char* filename, const uchar* buf, uint32 size, uint
{ {
if ((i-skip)%cols==0) { if ((i-skip)%cols==0) {
if (i != skip) if (i != skip)
logfile << " | " << ascii << endl; logfile << " | " << ascii << std::endl;
logfile << setw(4) << setfill(' ') << i-skip << ": "; logfile << std::setw(4) << std::setfill(' ') << i-skip << ": ";
memset(ascii, 0, cols+1); memset(ascii, 0, cols+1);
j = 0; j = 0;
} }
@ -128,7 +123,7 @@ void FileDumpPacketHex(const char* filename, const uchar* buf, uint32 size, uint
for (uint32 h = k+1; h < cols; h++) { for (uint32 h = k+1; h < cols; h++) {
logfile << " "; logfile << " ";
} }
logfile << " | " << ascii << endl; logfile << " | " << ascii << std::endl;
delete[] ascii; delete[] ascii;
} }
@ -161,13 +156,13 @@ void FileDumpPacket(const char* filename, const EQApplicationPacket* app)
if prefix_timestamp specified, prints the current date/time to the file + ": " + text if prefix_timestamp specified, prints the current date/time to the file + ": " + text
*/ */
void FilePrintLine(const char* filename, bool prefix_timestamp, const char* text, ...) { void FilePrintLine(const char* filename, bool prefix_timestamp, const char* text, ...) {
ofstream logfile(filename, ios::app); std::ofstream logfile(filename, std::ios::app);
if (prefix_timestamp) { if (prefix_timestamp) {
time_t rawtime; time_t rawtime;
struct tm* gmt_t; struct tm* gmt_t;
time(&rawtime); time(&rawtime);
gmt_t = gmtime(&rawtime); gmt_t = gmtime(&rawtime);
logfile << (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 << " GMT"; logfile << (gmt_t->tm_year + 1900) << "/" << std::setw(2) << std::setfill('0') << (gmt_t->tm_mon + 1) << "/" << std::setw(2) << std::setfill('0') << gmt_t->tm_mday << " " << std::setw(2) << std::setfill('0') << gmt_t->tm_hour << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_min << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_sec << " GMT";
} }
if (text != 0) { if (text != 0) {
@ -181,17 +176,17 @@ void FilePrintLine(const char* filename, bool prefix_timestamp, const char* text
logfile << ": "; logfile << ": ";
logfile << buffer; logfile << buffer;
} }
logfile << endl; logfile << std::endl;
} }
void FilePrint(const char* filename, bool newline, bool prefix_timestamp, const char* text, ...) { void FilePrint(const char* filename, bool newline, bool prefix_timestamp, const char* text, ...) {
ofstream logfile(filename, ios::app); std::ofstream logfile(filename, std::ios::app);
if (prefix_timestamp) { if (prefix_timestamp) {
time_t rawtime; time_t rawtime;
struct tm* gmt_t; struct tm* gmt_t;
time(&rawtime); time(&rawtime);
gmt_t = gmtime(&rawtime); gmt_t = gmtime(&rawtime);
logfile << (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 << " GMT"; logfile << (gmt_t->tm_year + 1900) << "/" << std::setw(2) << std::setfill('0') << (gmt_t->tm_mon + 1) << "/" << std::setw(2) << std::setfill('0') << gmt_t->tm_mday << " " << std::setw(2) << std::setfill('0') << gmt_t->tm_hour << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_min << ":" << std::setw(2) << std::setfill('0') << gmt_t->tm_sec << " GMT";
} }
if (text != 0) { if (text != 0) {
@ -207,6 +202,6 @@ void FilePrint(const char* filename, bool newline, bool prefix_timestamp, const
} }
if (newline) if (newline)
logfile << endl; logfile << std::endl;
} }

View File

@ -19,7 +19,6 @@
#define PACKET_DUMP_FILE_H #define PACKET_DUMP_FILE_H
#include <iostream> #include <iostream>
using namespace std;
#include "../common/types.h" #include "../common/types.h"

View File

@ -27,8 +27,6 @@
#include <netinet/in.h> #include <netinet/in.h>
#endif #endif
using namespace std;
void EncryptProfilePacket(EQApplicationPacket* app) { void EncryptProfilePacket(EQApplicationPacket* app) {
//EncryptProfilePacket(app->pBuffer, app->size); //EncryptProfilePacket(app->pBuffer, app->size);
} }
@ -209,10 +207,10 @@ uint32 InflatePacket(const uchar* indata, uint32 indatalen, uchar* outdata, uint
} }
else { else {
if (!iQuiet) { if (!iQuiet) {
cout << "Error: InflatePacket: inflate() returned " << zerror << " '"; std::cout << "Error: InflatePacket: inflate() returned " << zerror << " '";
if (zstream.msg) if (zstream.msg)
cout << zstream.msg; std::cout << zstream.msg;
cout << "'" << endl; std::cout << "'" << std::endl;
#ifdef EQDEBUG #ifdef EQDEBUG
DumpPacket(indata-16, indatalen+16); DumpPacket(indata-16, indatalen+16);
#endif #endif
@ -254,10 +252,10 @@ uint32 InflatePacket(const uchar* indata, uint32 indatalen, uchar* outdata, uint
} }
else { else {
if (!iQuiet) { if (!iQuiet) {
cout << "Error: InflatePacket: inflate() returned " << zerror << " '"; std::cout << "Error: InflatePacket: inflate() returned " << zerror << " '";
if (zstream.msg) if (zstream.msg)
cout << zstream.msg; std::cout << zstream.msg;
cout << "'" << endl; std::cout << "'" << std::endl;
#ifdef EQDEBUG #ifdef EQDEBUG
DumpPacket(indata-16, indatalen+16); DumpPacket(indata-16, indatalen+16);
#endif #endif

View File

@ -13,9 +13,6 @@
#include "../common/misc.h" #include "../common/misc.h"
#include <map> #include <map>
using namespace std;
PacketFileWriter::PacketFileWriter(bool _force_flush) { PacketFileWriter::PacketFileWriter(bool _force_flush) {
out = NULL; out = NULL;
force_flush = _force_flush; force_flush = _force_flush;

View File

@ -8,6 +8,7 @@
#include "../eq_packet_structs.h" #include "../eq_packet_structs.h"
#include "../MiscFunctions.h" #include "../MiscFunctions.h"
#include "../StringUtil.h"
#include "../Item.h" #include "../Item.h"
#include "../clientversions.h" #include "../clientversions.h"
#include "Client62_structs.h" #include "Client62_structs.h"
@ -24,7 +25,7 @@ void Register(EQStreamIdentifier &into) {
//create our opcode manager if we havent already //create our opcode manager if we havent already
if(opcodes == nullptr) { if(opcodes == nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
//load up the opcode manager. //load up the opcode manager.
@ -39,17 +40,17 @@ void Register(EQStreamIdentifier &into) {
//ok, now we have what we need to register. //ok, now we have what we need to register.
EQStream::Signature signature; EQStream::Signature signature;
string pname; std::string pname;
//register our world signature. //register our world signature.
pname = string(name) + "_world"; pname = std::string(name) + "_world";
signature.ignore_eq_opcode = 0; signature.ignore_eq_opcode = 0;
signature.first_length = sizeof(structs::LoginInfo_Struct); signature.first_length = sizeof(structs::LoginInfo_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo); signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo);
into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy); into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy);
//register our zone signature. //register our zone signature.
pname = string(name) + "_zone"; pname = std::string(name) + "_zone";
signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket); signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket);
signature.first_length = sizeof(structs::ClientZoneEntry_Struct); signature.first_length = sizeof(structs::ClientZoneEntry_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry); signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry);
@ -66,7 +67,7 @@ void Reload() {
if(opcodes != nullptr) { if(opcodes != nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
if(!opcodes->ReloadOpcodes(opfile.c_str())) { if(!opcodes->ReloadOpcodes(opfile.c_str())) {
@ -546,7 +547,7 @@ ENCODE(OP_CharInventory) {
//do the transform... //do the transform...
int r; int r;
string serial_string; std::string serial_string;
for(r = 0; r < itemcount; r++, eq++) { for(r = 0; r < itemcount; r++, eq++) {
uint32 length; uint32 length;
char *serialized=SerializeItem((ItemInst*)eq->inst,eq->slot_id,&length,0); char *serialized=SerializeItem((ItemInst*)eq->inst,eq->slot_id,&length,0);

View File

@ -8,6 +8,7 @@
#include "../eq_packet_structs.h" #include "../eq_packet_structs.h"
#include "../MiscFunctions.h" #include "../MiscFunctions.h"
#include "../StringUtil.h"
#include "../Item.h" #include "../Item.h"
#include "RoF_structs.h" #include "RoF_structs.h"
#include "../rulesys.h" #include "../rulesys.h"
@ -27,7 +28,7 @@ void Register(EQStreamIdentifier &into) {
//create our opcode manager if we havent already //create our opcode manager if we havent already
if(opcodes == nullptr) { if(opcodes == nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
//load up the opcode manager. //load up the opcode manager.
@ -42,17 +43,17 @@ void Register(EQStreamIdentifier &into) {
//ok, now we have what we need to register. //ok, now we have what we need to register.
EQStream::Signature signature; EQStream::Signature signature;
string pname; std::string pname;
//register our world signature. //register our world signature.
pname = string(name) + "_world"; pname = std::string(name) + "_world";
signature.ignore_eq_opcode = 0; signature.ignore_eq_opcode = 0;
signature.first_length = sizeof(structs::LoginInfo_Struct); signature.first_length = sizeof(structs::LoginInfo_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo); signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo);
into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy); into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy);
//register our zone signature. //register our zone signature.
pname = string(name) + "_zone"; pname = std::string(name) + "_zone";
signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket); signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket);
signature.first_length = sizeof(structs::ClientZoneEntry_Struct); signature.first_length = sizeof(structs::ClientZoneEntry_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry); signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry);
@ -71,7 +72,7 @@ void Reload() {
if(opcodes != nullptr) { if(opcodes != nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
if(!opcodes->ReloadOpcodes(opfile.c_str())) { if(!opcodes->ReloadOpcodes(opfile.c_str())) {

View File

@ -8,6 +8,7 @@
#include "../eq_packet_structs.h" #include "../eq_packet_structs.h"
#include "../MiscFunctions.h" #include "../MiscFunctions.h"
#include "../StringUtil.h"
#include "../Item.h" #include "../Item.h"
#include "SoD_structs.h" #include "SoD_structs.h"
#include "../rulesys.h" #include "../rulesys.h"
@ -27,7 +28,7 @@ void Register(EQStreamIdentifier &into) {
//create our opcode manager if we havent already //create our opcode manager if we havent already
if(opcodes == nullptr) { if(opcodes == nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
//load up the opcode manager. //load up the opcode manager.
@ -42,17 +43,17 @@ void Register(EQStreamIdentifier &into) {
//ok, now we have what we need to register. //ok, now we have what we need to register.
EQStream::Signature signature; EQStream::Signature signature;
string pname; std::string pname;
//register our world signature. //register our world signature.
pname = string(name) + "_world"; pname = std::string(name) + "_world";
signature.ignore_eq_opcode = 0; signature.ignore_eq_opcode = 0;
signature.first_length = sizeof(structs::LoginInfo_Struct); signature.first_length = sizeof(structs::LoginInfo_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo); signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo);
into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy); into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy);
//register our zone signature. //register our zone signature.
pname = string(name) + "_zone"; pname = std::string(name) + "_zone";
signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket); signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket);
signature.first_length = sizeof(structs::ClientZoneEntry_Struct); signature.first_length = sizeof(structs::ClientZoneEntry_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry); signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry);
@ -71,7 +72,7 @@ void Reload() {
if(opcodes != nullptr) { if(opcodes != nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
if(!opcodes->ReloadOpcodes(opfile.c_str())) { if(!opcodes->ReloadOpcodes(opfile.c_str())) {

View File

@ -7,7 +7,7 @@
#include "../crc32.h" #include "../crc32.h"
#include "../eq_packet_structs.h" #include "../eq_packet_structs.h"
#include "../MiscFunctions.h" #include "../StringUtil.h"
#include "../Item.h" #include "../Item.h"
#include "SoF_structs.h" #include "SoF_structs.h"
#include "../rulesys.h" #include "../rulesys.h"
@ -27,7 +27,7 @@ void Register(EQStreamIdentifier &into) {
//create our opcode manager if we havent already //create our opcode manager if we havent already
if(opcodes == nullptr) { if(opcodes == nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
//load up the opcode manager. //load up the opcode manager.
@ -42,17 +42,17 @@ void Register(EQStreamIdentifier &into) {
//ok, now we have what we need to register. //ok, now we have what we need to register.
EQStream::Signature signature; EQStream::Signature signature;
string pname; std::string pname;
//register our world signature. //register our world signature.
pname = string(name) + "_world"; pname = std::string(name) + "_world";
signature.ignore_eq_opcode = 0; signature.ignore_eq_opcode = 0;
signature.first_length = sizeof(structs::LoginInfo_Struct); signature.first_length = sizeof(structs::LoginInfo_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo); signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo);
into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy); into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy);
//register our zone signature. //register our zone signature.
pname = string(name) + "_zone"; pname = std::string(name) + "_zone";
signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket); signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket);
signature.first_length = sizeof(structs::ClientZoneEntry_Struct); signature.first_length = sizeof(structs::ClientZoneEntry_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry); signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry);
@ -71,7 +71,7 @@ void Reload() {
if(opcodes != nullptr) { if(opcodes != nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
if(!opcodes->ReloadOpcodes(opfile.c_str())) { if(!opcodes->ReloadOpcodes(opfile.c_str())) {

View File

@ -8,7 +8,7 @@
#include "../races.h" #include "../races.h"
#include "../eq_packet_structs.h" #include "../eq_packet_structs.h"
#include "../MiscFunctions.h" #include "../StringUtil.h"
#include "../Item.h" #include "../Item.h"
#include "Titanium_structs.h" #include "Titanium_structs.h"
#include <sstream> #include <sstream>
@ -25,7 +25,7 @@ void Register(EQStreamIdentifier &into) {
//create our opcode manager if we havent already //create our opcode manager if we havent already
if(opcodes == nullptr) { if(opcodes == nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
//load up the opcode manager. //load up the opcode manager.
@ -40,17 +40,17 @@ void Register(EQStreamIdentifier &into) {
//ok, now we have what we need to register. //ok, now we have what we need to register.
EQStream::Signature signature; EQStream::Signature signature;
string pname; std::string pname;
//register our world signature. //register our world signature.
pname = string(name) + "_world"; pname = std::string(name) + "_world";
signature.ignore_eq_opcode = 0; signature.ignore_eq_opcode = 0;
signature.first_length = sizeof(structs::LoginInfo_Struct); signature.first_length = sizeof(structs::LoginInfo_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo); signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo);
into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy); into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy);
//register our zone signature. //register our zone signature.
pname = string(name) + "_zone"; pname = std::string(name) + "_zone";
signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket); signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket);
signature.first_length = sizeof(structs::ClientZoneEntry_Struct); signature.first_length = sizeof(structs::ClientZoneEntry_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry); signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry);
@ -69,7 +69,7 @@ void Reload() {
if(opcodes != nullptr) { if(opcodes != nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
if(!opcodes->ReloadOpcodes(opfile.c_str())) { if(!opcodes->ReloadOpcodes(opfile.c_str())) {
@ -639,7 +639,7 @@ ENCODE(OP_CharInventory) {
//do the transform... //do the transform...
int r; int r;
string serial_string; std::string serial_string;
for(r = 0; r < itemcount; r++, eq++) { for(r = 0; r < itemcount; r++, eq++) {
uint32 length; uint32 length;
char *serialized=SerializeItem((const ItemInst*)eq->inst,eq->slot_id,&length,0); char *serialized=SerializeItem((const ItemInst*)eq->inst,eq->slot_id,&length,0);

View File

@ -8,6 +8,7 @@
#include "../eq_packet_structs.h" #include "../eq_packet_structs.h"
#include "../MiscFunctions.h" #include "../MiscFunctions.h"
#include "../StringUtil.h"
#include "../Item.h" #include "../Item.h"
#include "Underfoot_structs.h" #include "Underfoot_structs.h"
#include "../rulesys.h" #include "../rulesys.h"
@ -28,7 +29,7 @@ void Register(EQStreamIdentifier &into) {
//create our opcode manager if we havent already //create our opcode manager if we havent already
if(opcodes == nullptr) { if(opcodes == nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
//load up the opcode manager. //load up the opcode manager.
@ -43,17 +44,17 @@ void Register(EQStreamIdentifier &into) {
//ok, now we have what we need to register. //ok, now we have what we need to register.
EQStream::Signature signature; EQStream::Signature signature;
string pname; std::string pname;
//register our world signature. //register our world signature.
pname = string(name) + "_world"; pname = std::string(name) + "_world";
signature.ignore_eq_opcode = 0; signature.ignore_eq_opcode = 0;
signature.first_length = sizeof(structs::LoginInfo_Struct); signature.first_length = sizeof(structs::LoginInfo_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo); signature.first_eq_opcode = opcodes->EmuToEQ(OP_SendLoginInfo);
into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy); into.RegisterPatch(signature, pname.c_str(), &opcodes, &struct_strategy);
//register our zone signature. //register our zone signature.
pname = string(name) + "_zone"; pname = std::string(name) + "_zone";
signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket); signature.ignore_eq_opcode = opcodes->EmuToEQ(OP_AckPacket);
signature.first_length = sizeof(structs::ClientZoneEntry_Struct); signature.first_length = sizeof(structs::ClientZoneEntry_Struct);
signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry); signature.first_eq_opcode = opcodes->EmuToEQ(OP_ZoneEntry);
@ -72,7 +73,7 @@ void Reload() {
if(opcodes != nullptr) { if(opcodes != nullptr) {
//TODO: get this file name from the config file //TODO: get this file name from the config file
string opfile = "patch_"; std::string opfile = "patch_";
opfile += name; opfile += name;
opfile += ".conf"; opfile += ".conf";
if(!opcodes->ReloadOpcodes(opfile.c_str())) { if(!opcodes->ReloadOpcodes(opfile.c_str())) {

View File

@ -139,7 +139,7 @@ XS(XS_EQDBRes_fetch_row_array)
Perl_croak(aTHX_ "Usage: EQDBRes::fetch_row_array(THIS)"); Perl_croak(aTHX_ "Usage: EQDBRes::fetch_row_array(THIS)");
{ {
EQDBRes * THIS; EQDBRes * THIS;
vector<string> RETVAL; std::vector<std::string> RETVAL;
if (sv_derived_from(ST(0), "EQDBRes")) { if (sv_derived_from(ST(0), "EQDBRes")) {
IV tmp = SvIV((SV*)SvRV(ST(0))); IV tmp = SvIV((SV*)SvRV(ST(0)));
@ -160,7 +160,7 @@ XS(XS_EQDBRes_fetch_row_array)
/* grow the stack to the number of elements being returned */ /* grow the stack to the number of elements being returned */
EXTEND(SP, RETVAL.size()); EXTEND(SP, RETVAL.size());
for (ix_RETVAL = 0; ix_RETVAL < RETVAL.size(); ix_RETVAL++) { for (ix_RETVAL = 0; ix_RETVAL < RETVAL.size(); ix_RETVAL++) {
const string &it = RETVAL[ix_RETVAL]; const std::string &it = RETVAL[ix_RETVAL];
ST(ix_RETVAL) = sv_newmortal(); ST(ix_RETVAL) = sv_newmortal();
sv_setpvn(ST(ix_RETVAL), it.c_str(), it.length()); sv_setpvn(ST(ix_RETVAL), it.c_str(), it.length());
} }
@ -179,7 +179,7 @@ XS(XS_EQDBRes_fetch_row_hash)
Perl_croak(aTHX_ "Usage: EQDBRes::fetch_row_hash(THIS)"); Perl_croak(aTHX_ "Usage: EQDBRes::fetch_row_hash(THIS)");
{ {
EQDBRes * THIS; EQDBRes * THIS;
map<string,string> RETVAL; std::map<std::string,std::string> RETVAL;
if (sv_derived_from(ST(0), "EQDBRes")) { if (sv_derived_from(ST(0), "EQDBRes")) {
IV tmp = SvIV((SV*)SvRV(ST(0))); IV tmp = SvIV((SV*)SvRV(ST(0)));
@ -199,7 +199,7 @@ XS(XS_EQDBRes_fetch_row_hash)
sv_2mortal((SV*)hv); sv_2mortal((SV*)hv);
ST(0) = newRV((SV*)hv); ST(0) = newRV((SV*)hv);
map<string,string>::const_iterator cur, end; std::map<std::string,std::string>::const_iterator cur, end;
cur = RETVAL.begin(); cur = RETVAL.begin();
end = RETVAL.end(); end = RETVAL.end();
for(; cur != end; cur++) { for(; cur != end; cur++) {

View File

@ -20,7 +20,7 @@
#include "timer.h" #include "timer.h"
#include "ptimer.h" #include "ptimer.h"
#include "database.h" #include "database.h"
#include "MiscFunctions.h" #include "StringUtil.h"
#include <stdio.h> #include <stdio.h>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@ -289,7 +289,7 @@ PTimerList::PTimerList(uint32 char_id) {
} }
PTimerList::~PTimerList() { PTimerList::~PTimerList() {
map<pTimerType, PersistentTimer *>::iterator s; std::map<pTimerType, PersistentTimer *>::iterator s;
s = _list.begin(); s = _list.begin();
while(s != _list.end()) { while(s != _list.end()) {
if(s->second != nullptr) if(s->second != nullptr)
@ -300,7 +300,7 @@ PTimerList::~PTimerList() {
bool PTimerList::Load(Database *db) { bool PTimerList::Load(Database *db) {
map<pTimerType, PersistentTimer *>::iterator s; std::map<pTimerType, PersistentTimer *>::iterator s;
s = _list.begin(); s = _list.begin();
while(s != _list.end()) { while(s != _list.end()) {
if(s->second != nullptr) if(s->second != nullptr)
@ -362,7 +362,7 @@ bool PTimerList::Store(Database *db) {
printf("Storing all timers for char %lu\n", (unsigned long)_char_id); printf("Storing all timers for char %lu\n", (unsigned long)_char_id);
#endif #endif
map<pTimerType, PersistentTimer *>::iterator s; std::map<pTimerType, PersistentTimer *>::iterator s;
s = _list.begin(); s = _list.begin();
bool res = true; bool res = true;
while(s != _list.end()) { while(s != _list.end()) {
@ -462,11 +462,11 @@ PersistentTimer *PTimerList::Get(pTimerType type) {
return(_list[type]); return(_list[type]);
} }
void PTimerList::ToVector(vector< pair<pTimerType, PersistentTimer *> > &out) { void PTimerList::ToVector(std::vector< std::pair<pTimerType, PersistentTimer *> > &out) {
pair<pTimerType, PersistentTimer *> p; std::pair<pTimerType, PersistentTimer *> p;
map<pTimerType, PersistentTimer *>::iterator s; std::map<pTimerType, PersistentTimer *>::iterator s;
s = _list.begin(); s = _list.begin();
while(s != _list.end()) { while(s != _list.end()) {
if(s->second != nullptr) { if(s->second != nullptr) {

View File

@ -21,7 +21,6 @@
#include "types.h" #include "types.h"
#include <map> #include <map>
#include <vector> #include <vector>
using namespace std;
enum { //values for pTimerType enum { //values for pTimerType
pTimerStartAdventureTimer = 1, pTimerStartAdventureTimer = 1,
@ -120,13 +119,13 @@ public:
inline void SetCharID(uint32 char_id) { _char_id = char_id; } inline void SetCharID(uint32 char_id) { _char_id = char_id; }
void ToVector(vector< pair<pTimerType, PersistentTimer *> > &out); void ToVector(std::vector< std::pair<pTimerType, PersistentTimer *> > &out);
//Clear a timer for a char not logged in //Clear a timer for a char not logged in
//this is not defined on a char which is logged in! //this is not defined on a char which is logged in!
static bool ClearOffline(Database *db, uint32 char_id, pTimerType type); static bool ClearOffline(Database *db, uint32 char_id, pTimerType type);
typedef map<pTimerType, PersistentTimer *>::iterator iterator; typedef std::map<pTimerType, PersistentTimer *>::iterator iterator;
iterator begin() { return(_list.begin()); } iterator begin() { return(_list.begin()); }
iterator end() { return(_list.end()); } iterator end() { return(_list.end()); }
@ -135,7 +134,7 @@ public:
protected: protected:
uint32 _char_id; uint32 _char_id;
map<pTimerType, PersistentTimer *> _list; std::map<pTimerType, PersistentTimer *> _list;
}; };
//code prettying macros //code prettying macros

View File

@ -58,7 +58,7 @@ RDTSC_Timer::RDTSC_Timer(bool start_it) {
} }
int64 RDTSC_Timer::rdtsc() { int64 RDTSC_Timer::rdtsc() {
int64 res; int64 res = 0;
#ifdef USE_RDTSC #ifdef USE_RDTSC
#ifndef WIN64 #ifndef WIN64
#ifdef WIN32 #ifdef WIN32

View File

@ -19,7 +19,7 @@
#include "rulesys.h" #include "rulesys.h"
#include "logsys.h" #include "logsys.h"
#include "database.h" #include "database.h"
#include "MiscFunctions.h" #include "StringUtil.h"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>

View File

@ -1120,7 +1120,7 @@ struct QSPlayerLogTrade_Struct {
}; };
struct QSHandinItems_Struct { struct QSHandinItems_Struct {
char action_type[6]; // handin, return or reward char action_type[7]; // handin, return or reward
uint16 char_slot; uint16 char_slot;
uint32 item_id; uint32 item_id;
uint16 charges; uint16 charges;

View File

@ -1,12 +1,14 @@
#include "shareddb.h"
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include "shareddb.h"
#include "mysql.h"
#include "Item.h" #include "Item.h"
#include "classes.h" #include "classes.h"
#include "rulesys.h" #include "rulesys.h"
#include "seperator.h" #include "seperator.h"
#include "MiscFunctions.h" #include "StringUtil.h"
#include "eq_packet_structs.h" #include "eq_packet_structs.h"
#include "guilds.h" #include "guilds.h"
#include "extprofile.h" #include "extprofile.h"
@ -17,17 +19,15 @@
#include "faction.h" #include "faction.h"
#include "features.h" #include "features.h"
using namespace std;
SharedDatabase::SharedDatabase() SharedDatabase::SharedDatabase()
: Database(), skill_caps_mmf(nullptr), items_mmf(nullptr), items_hash(nullptr), faction_mmf(nullptr), faction_hash(nullptr), : Database(), skill_caps_mmf(nullptr), items_mmf(nullptr), items_hash(nullptr), faction_mmf(nullptr), faction_hash(nullptr),
loot_table_mmf(nullptr), loot_drop_mmf(nullptr), loot_table_hash(nullptr), loot_drop_hash(nullptr) loot_table_mmf(nullptr), loot_table_hash(nullptr), loot_drop_mmf(nullptr), loot_drop_hash(nullptr)
{ {
} }
SharedDatabase::SharedDatabase(const char* host, const char* user, const char* passwd, const char* database, uint32 port) SharedDatabase::SharedDatabase(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
: Database(host, user, passwd, database, port), skill_caps_mmf(nullptr), items_mmf(nullptr), items_hash(nullptr), : Database(host, user, passwd, database, port), skill_caps_mmf(nullptr), items_mmf(nullptr), items_hash(nullptr),
faction_mmf(nullptr), faction_hash(nullptr), loot_table_mmf(nullptr), loot_drop_mmf(nullptr), loot_table_hash(nullptr), faction_mmf(nullptr), faction_hash(nullptr), loot_table_mmf(nullptr), loot_table_hash(nullptr), loot_drop_mmf(nullptr),
loot_drop_hash(nullptr) loot_drop_hash(nullptr)
{ {
} }
@ -50,7 +50,7 @@ bool SharedDatabase::SetHideMe(uint32 account_id, uint8 hideme)
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET hideme = %i where id = %i", hideme, account_id), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET hideme = %i where id = %i", hideme, account_id), errbuf)) {
cerr << "Error in SetGMSpeed query '" << query << "' " << errbuf << endl; std::cerr << "Error in SetGMSpeed query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -85,7 +85,7 @@ uint8 SharedDatabase::GetGMSpeed(uint32 account_id)
else else
{ {
cerr << "Error in GetGMSpeed query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetGMSpeed query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -101,7 +101,7 @@ bool SharedDatabase::SetGMSpeed(uint32 account_id, uint8 gmspeed)
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET gmspeed = %i where id = %i", gmspeed, account_id), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET gmspeed = %i where id = %i", gmspeed, account_id), errbuf)) {
cerr << "Error in SetGMSpeed query '" << query << "' " << errbuf << endl; std::cerr << "Error in SetGMSpeed query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -140,7 +140,7 @@ uint32 SharedDatabase::GetTotalTimeEntitledOnAccount(uint32 AccountID) {
return EntitledTime; return EntitledTime;
} }
bool SharedDatabase::SaveCursor(uint32 char_id, list<ItemInst*>::const_iterator &start, list<ItemInst*>::const_iterator &end) bool SharedDatabase::SaveCursor(uint32 char_id, std::list<ItemInst*>::const_iterator &start, std::list<ItemInst*>::const_iterator &end)
{ {
iter_queue it; iter_queue it;
int i; int i;
@ -155,7 +155,7 @@ bool ret=true;
break; break;
} }
} else { } else {
cout << "Clearing cursor failed: " << errbuf << endl; std::cout << "Clearing cursor failed: " << errbuf << std::endl;
} }
safe_delete_array(query); safe_delete_array(query);
@ -337,8 +337,7 @@ int32 SharedDatabase::GetSharedPlatinum(uint32 account_id)
} }
else else
{ {
std::cerr << "Error in GetSharedPlatinum query '" << query << "' " << errbuf << std::endl;
cerr << "Error in GetSharedPlatinum query '" << query << "' " << errbuf << endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -352,7 +351,7 @@ bool SharedDatabase::SetSharedPlatinum(uint32 account_id, int32 amount_to_add)
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET sharedplat = sharedplat + %i WHERE id = %i", amount_to_add, account_id), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE account SET sharedplat = sharedplat + %i WHERE id = %i", amount_to_add, account_id), errbuf)) {
cerr << "Error in SetSharedPlatinum query '" << query << "' " << errbuf << endl; std::cerr << "Error in SetSharedPlatinum query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -1049,17 +1048,17 @@ const Item_Struct* SharedDatabase::IterateItems(uint32* id) {
return nullptr; return nullptr;
} }
string SharedDatabase::GetBook(const char *txtfile) std::string SharedDatabase::GetBook(const char *txtfile)
{ {
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
char txtfile2[20]; char txtfile2[20];
string txtout; std::string txtout;
strcpy(txtfile2,txtfile); strcpy(txtfile2,txtfile);
if (!RunQuery(query, MakeAnyLenString(&query, "SELECT txtfile FROM books where name='%s'", txtfile2), errbuf, &result)) { if (!RunQuery(query, MakeAnyLenString(&query, "SELECT txtfile FROM books where name='%s'", txtfile2), errbuf, &result)) {
cerr << "Error in GetBook query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetBook query '" << query << "' " << errbuf << std::endl;
if (query != 0) if (query != 0)
safe_delete_array(query); safe_delete_array(query);
txtout.assign(" ",1); txtout.assign(" ",1);
@ -1399,7 +1398,7 @@ int32 SharedDatabase::DeleteStalePlayerBackups() {
return affected_rows; return affected_rows;
} }
bool SharedDatabase::GetCommandSettings(map<string,uint8> &commands) { bool SharedDatabase::GetCommandSettings(std::map<std::string,uint8> &commands) {
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
MYSQL_RES *result; MYSQL_RES *result;
@ -1415,7 +1414,7 @@ bool SharedDatabase::GetCommandSettings(map<string,uint8> &commands) {
mysql_free_result(result); mysql_free_result(result);
return true; return true;
} else { } else {
cerr << "Error in GetCommands query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetCommands query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
@ -1973,7 +1972,7 @@ void SharedDatabase::GetPlayerInspectMessage(char* playername, InspectMessage_St
mysql_free_result(result); mysql_free_result(result);
} }
else { else {
cerr << "Error in GetPlayerInspectMessage query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetPlayerInspectMessage query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
} }
@ -1984,7 +1983,7 @@ void SharedDatabase::SetPlayerInspectMessage(char* playername, const InspectMess
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET inspectmessage='%s' WHERE name='%s'", message->text, playername), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET inspectmessage='%s' WHERE name='%s'", message->text, playername), errbuf)) {
cerr << "Error in SetPlayerInspectMessage query '" << query << "' " << errbuf << endl; std::cerr << "Error in SetPlayerInspectMessage query '" << query << "' " << errbuf << std::endl;
} }
safe_delete_array(query); safe_delete_array(query);
@ -2008,7 +2007,7 @@ void SharedDatabase::GetBotInspectMessage(uint32 botid, InspectMessage_Struct* m
mysql_free_result(result); mysql_free_result(result);
} }
else { else {
cerr << "Error in GetBotInspectMessage query '" << query << "' " << errbuf << endl; std::cerr << "Error in GetBotInspectMessage query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query); safe_delete_array(query);
} }
} }
@ -2019,7 +2018,7 @@ void SharedDatabase::SetBotInspectMessage(uint32 botid, const InspectMessage_Str
char *query = 0; char *query = 0;
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE bots SET BotInspectMessage='%s' WHERE BotID=%i", message->text, botid), errbuf)) { if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE bots SET BotInspectMessage='%s' WHERE BotID=%i", message->text, botid), errbuf)) {
cerr << "Error in SetBotInspectMessage query '" << query << "' " << errbuf << endl; std::cerr << "Error in SetBotInspectMessage query '" << query << "' " << errbuf << std::endl;
} }
safe_delete_array(query); safe_delete_array(query);

View File

@ -48,7 +48,7 @@ public:
void SetPlayerInspectMessage(char* playername, const InspectMessage_Struct* message); void SetPlayerInspectMessage(char* playername, const InspectMessage_Struct* message);
void GetBotInspectMessage(uint32 botid, InspectMessage_Struct* message); void GetBotInspectMessage(uint32 botid, InspectMessage_Struct* message);
void SetBotInspectMessage(uint32 botid, const InspectMessage_Struct* message); void SetBotInspectMessage(uint32 botid, const InspectMessage_Struct* message);
bool GetCommandSettings(map<string,uint8> &commands); bool GetCommandSettings(std::map<std::string,uint8> &commands);
uint32 GetTotalTimeEntitledOnAccount(uint32 AccountID); uint32 GetTotalTimeEntitledOnAccount(uint32 AccountID);
/* /*
@ -65,7 +65,7 @@ public:
bool SetStartingItems(PlayerProfile_Struct* pp, Inventory* inv, uint32 si_race, uint32 si_class, uint32 si_deity, uint32 si_current_zone, char* si_name, int admin); bool SetStartingItems(PlayerProfile_Struct* pp, Inventory* inv, uint32 si_race, uint32 si_class, uint32 si_deity, uint32 si_current_zone, char* si_name, int admin);
string GetBook(const char *txtfile); std::string GetBook(const char *txtfile);
/* /*
* Item Methods * Item Methods
@ -112,6 +112,7 @@ public:
protected: protected:
EQEmu::MemoryMappedFile *skill_caps_mmf;
EQEmu::MemoryMappedFile *items_mmf; EQEmu::MemoryMappedFile *items_mmf;
EQEmu::FixedMemoryHashSet<Item_Struct> *items_hash; EQEmu::FixedMemoryHashSet<Item_Struct> *items_hash;
EQEmu::MemoryMappedFile *faction_mmf; EQEmu::MemoryMappedFile *faction_mmf;
@ -120,7 +121,6 @@ protected:
EQEmu::FixedMemoryVariableHashSet<LootTable_Struct> *loot_table_hash; EQEmu::FixedMemoryVariableHashSet<LootTable_Struct> *loot_table_hash;
EQEmu::MemoryMappedFile *loot_drop_mmf; EQEmu::MemoryMappedFile *loot_drop_mmf;
EQEmu::FixedMemoryVariableHashSet<LootDrop_Struct> *loot_drop_hash; EQEmu::FixedMemoryVariableHashSet<LootDrop_Struct> *loot_drop_hash;
EQEmu::MemoryMappedFile *skill_caps_mmf;
}; };
#endif /*SHAREDDB_H_*/ #endif /*SHAREDDB_H_*/

View File

@ -36,7 +36,7 @@ TimeoutManager::TimeoutManager() {
} }
void TimeoutManager::CheckTimeouts() { void TimeoutManager::CheckTimeouts() {
vector<Timeoutable *>::iterator cur,end; std::vector<Timeoutable *>::iterator cur,end;
cur = members.begin(); cur = members.begin();
end = members.end(); end = members.end();
for(; cur != end; cur++) { for(; cur != end; cur++) {
@ -66,7 +66,7 @@ void TimeoutManager::DeleteMember(Timeoutable *who) {
#ifdef TIMEOUT_DEBUG #ifdef TIMEOUT_DEBUG
LogFile->write(EQEMuLog::Debug, "Removing timeoutable 0x%x\n", who); LogFile->write(EQEMuLog::Debug, "Removing timeoutable 0x%x\n", who);
#endif #endif
vector<Timeoutable *>::iterator cur,end; std::vector<Timeoutable *>::iterator cur,end;
cur = members.begin(); cur = members.begin();
end = members.end(); end = members.end();
for(; cur != end; cur++) { for(; cur != end; cur++) {

View File

@ -27,7 +27,6 @@
#include "timer.h" #include "timer.h"
#include <vector> #include <vector>
using namespace std;
//timeoutable objects automatically register themselves //timeoutable objects automatically register themselves
//with the global TimeoutManager object //with the global TimeoutManager object
@ -59,7 +58,7 @@ protected:
void AddMember(Timeoutable *who); void AddMember(Timeoutable *who);
void DeleteMember(Timeoutable *who); void DeleteMember(Timeoutable *who);
vector<Timeoutable *> members; std::vector<Timeoutable *> members;
}; };
extern TimeoutManager timeout_manager; extern TimeoutManager timeout_manager;

View File

@ -24,7 +24,6 @@
#endif #endif
#include <iostream> #include <iostream>
using namespace std;
#include "timer.h" #include "timer.h"
@ -77,7 +76,7 @@ bool Timer::Check(bool iReset)
{ {
_CP(Timer_Check); _CP(Timer_Check);
if (this==0) { if (this==0) {
cerr << "Null timer during ->Check()!?\n"; std::cerr << "Null timer during ->Check()!?\n";
return true; return true;
} }
// if (!current_time || !start_time || !timer_time) {cerr << "Timer::Check on a timer that does not have a vital member defined."; // if (!current_time || !start_time || !timer_time) {cerr << "Timer::Check on a timer that does not have a vital member defined.";

View File

@ -68,9 +68,6 @@ typedef const char Const_char; //for perl XS
#ifdef _WINDOWS #ifdef _WINDOWS
#define snprintf _snprintf #define snprintf _snprintf
#if (_MSC_VER < 1500)
#define vsnprintf _vsnprintf
#endif
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#define strcasecmp _stricmp #define strcasecmp _stricmp
typedef void ThreadReturnType; typedef void ThreadReturnType;
@ -80,8 +77,8 @@ typedef const char Const_char; //for perl XS
#define THREAD_RETURN(x) return(x); #define THREAD_RETURN(x) return(x);
#endif #endif
#define safe_delete(d) if(d) { delete d; d=0; } #define safe_delete(d) if(d) { delete d; d=nullptr; }
#define safe_delete_array(d) if(d) { delete[] d; d=0; } #define safe_delete_array(d) if(d) { delete[] d; d=nullptr; }
#define L32(i) ((uint32) i) #define L32(i) ((uint32) i)
#define H32(i) ((uint32) (i >> 32)) #define H32(i) ((uint32) (i >> 32))
#define L16(i) ((uint16) i) #define L16(i) ((uint16) i)

View File

@ -21,7 +21,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <iomanip> #include <iomanip>
using namespace std;
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>

View File

@ -13,10 +13,11 @@ SET(eqlaunch_headers
ADD_EXECUTABLE(eqlaunch ${eqlaunch_sources} ${eqlaunch_headers}) ADD_EXECUTABLE(eqlaunch ${eqlaunch_sources} ${eqlaunch_headers})
INSTALL(TARGETS eqlaunch RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
TARGET_LINK_LIBRARIES(eqlaunch Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) TARGET_LINK_LIBRARIES(eqlaunch Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(eqlaunch PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") SET_TARGET_PROPERTIES(eqlaunch PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(eqlaunch "Ws2_32.lib") TARGET_LINK_LIBRARIES(eqlaunch "Ws2_32.lib")
ENDIF(MSVC) ENDIF(MSVC)

View File

@ -30,8 +30,6 @@
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
using namespace std;
bool RunLoops = false; bool RunLoops = false;
void CatchSignal(int sig_num); void CatchSignal(int sig_num);
@ -40,7 +38,7 @@ int main(int argc, char *argv[]) {
RegisterExecutablePlatform(ExePlatformLaunch); RegisterExecutablePlatform(ExePlatformLaunch);
set_exception_handler(); set_exception_handler();
string launcher_name; std::string launcher_name;
if(argc == 2) { if(argc == 2) {
launcher_name = argv[1]; launcher_name = argv[1];
} }
@ -87,14 +85,14 @@ int main(int argc, char *argv[]) {
} }
#endif #endif
map<string, ZoneLaunch *> zones; std::map<std::string, ZoneLaunch *> zones;
WorldServer world(zones, launcher_name.c_str(), Config); WorldServer world(zones, launcher_name.c_str(), Config);
if (!world.Connect()) { if (!world.Connect()) {
_log(LAUNCHER__ERROR, "worldserver.Connect() FAILED! Will retry."); _log(LAUNCHER__ERROR, "worldserver.Connect() FAILED! Will retry.");
} }
map<string, ZoneLaunch *>::iterator zone, zend; std::map<std::string, ZoneLaunch *>::iterator zone, zend;
set<string> to_remove; std::set<std::string> to_remove;
Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect
@ -132,7 +130,7 @@ int main(int argc, char *argv[]) {
* Kill off any zones which have stopped * Kill off any zones which have stopped
*/ */
while(!to_remove.empty()) { while(!to_remove.empty()) {
string rem = *to_remove.begin(); std::string rem = *to_remove.begin();
to_remove.erase(rem); to_remove.erase(rem);
zone = zones.find(rem); zone = zones.find(rem);
if(zone == zones.end()) { if(zone == zones.end()) {

View File

@ -20,9 +20,10 @@
#include "../common/servertalk.h" #include "../common/servertalk.h"
#include "ZoneLaunch.h" #include "ZoneLaunch.h"
#include "../common/EQEmuConfig.h" #include "../common/EQEmuConfig.h"
#include "../common/StringUtil.h"
WorldServer::WorldServer(map<string, ZoneLaunch *> &zones, const char *name, const EQEmuConfig *config) WorldServer::WorldServer(std::map<std::string, ZoneLaunch *> &zones, const char *name, const EQEmuConfig *config)
: WorldConnection(EmuTCPConnection::packetModeLauncher, config->SharedKey.c_str()), : WorldConnection(EmuTCPConnection::packetModeLauncher, config->SharedKey.c_str()),
m_name(name), m_name(name),
m_config(config), m_config(config),
@ -97,7 +98,7 @@ void WorldServer::Process() {
break; break;
} }
case ZR_Restart: { case ZR_Restart: {
map<string, ZoneLaunch *>::iterator res = m_zones.find(lzr->short_name); std::map<std::string, ZoneLaunch *>::iterator res = m_zones.find(lzr->short_name);
if(res == m_zones.end()) { if(res == m_zones.end()) {
_log(LAUNCHER__ERROR, "World told us to restart zone %s, but it is not running.", lzr->short_name); _log(LAUNCHER__ERROR, "World told us to restart zone %s, but it is not running.", lzr->short_name);
} else { } else {
@ -107,7 +108,7 @@ void WorldServer::Process() {
break; break;
} }
case ZR_Stop: { case ZR_Stop: {
map<string, ZoneLaunch *>::iterator res = m_zones.find(lzr->short_name); std::map<std::string, ZoneLaunch *>::iterator res = m_zones.find(lzr->short_name);
if(res == m_zones.end()) { if(res == m_zones.end()) {
_log(LAUNCHER__ERROR, "World told us to stop zone %s, but it is not running.", lzr->short_name); _log(LAUNCHER__ERROR, "World told us to stop zone %s, but it is not running.", lzr->short_name);
} else { } else {

View File

@ -13,6 +13,7 @@ SET(eqlogin_sources
) )
IF(MSVC OR MINGW) IF(MSVC OR MINGW)
ADD_DEFINITIONS(-DNOMINMAX)
SET(eqlogin_sources ${eqlogin_sources} Encryption.cpp) SET(eqlogin_sources ${eqlogin_sources} Encryption.cpp)
ENDIF(MSVC OR MINGW) ENDIF(MSVC OR MINGW)
@ -40,10 +41,11 @@ ENDIF(UNIX)
ADD_EXECUTABLE(loginserver ${eqlogin_sources} ${eqlogin_headers}) ADD_EXECUTABLE(loginserver ${eqlogin_sources} ${eqlogin_headers})
INSTALL(TARGETS loginserver RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
TARGET_LINK_LIBRARIES(loginserver Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE}) TARGET_LINK_LIBRARIES(loginserver Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(loginserver PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") SET_TARGET_PROPERTIES(loginserver PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(loginserver "Ws2_32.lib") TARGET_LINK_LIBRARIES(loginserver "Ws2_32.lib")
ENDIF(MSVC) ENDIF(MSVC)

View File

@ -25,19 +25,19 @@ extern ErrorLog *server_log;
* First gets the map from the title * First gets the map from the title
* Then gets the argument from the map we got from title * Then gets the argument from the map we got from title
*/ */
string Config::GetVariable(string title, string parameter) std::string Config::GetVariable(std::string title, std::string parameter)
{ {
map<string, map<string, string> >::iterator iter = vars.find(title); std::map<std::string, std::map<std::string, std::string> >::iterator iter = vars.find(title);
if(iter != vars.end()) if(iter != vars.end())
{ {
map<string, string>::iterator arg_iter = iter->second.find(parameter); std::map<std::string, std::string>::iterator arg_iter = iter->second.find(parameter);
if(arg_iter != iter->second.end()) if(arg_iter != iter->second.end())
{ {
return arg_iter->second; return arg_iter->second;
} }
} }
return string(""); return std::string("");
} }
/** /**
@ -56,12 +56,12 @@ void Config::Parse(const char *file_name)
FILE *input = fopen(file_name, "r"); FILE *input = fopen(file_name, "r");
if(input) if(input)
{ {
list<string> tokens; std::list<std::string> tokens;
Tokenize(input, tokens); Tokenize(input, tokens);
char mode = 0; char mode = 0;
string title, param, arg; std::string title, param, arg;
list<string>::iterator iter = tokens.begin(); std::list<std::string>::iterator iter = tokens.begin();
while(iter != tokens.end()) while(iter != tokens.end())
{ {
if((*iter).compare("[") == 0) if((*iter).compare("[") == 0)
@ -114,7 +114,7 @@ void Config::Parse(const char *file_name)
{ {
arg = (*iter); arg = (*iter);
mode = 0; mode = 0;
map<string, map<string, string> >::iterator map_iter = vars.find(title); std::map<std::string, std::map<std::string, std::string> >::iterator map_iter = vars.find(title);
if(map_iter != vars.end()) if(map_iter != vars.end())
{ {
map_iter->second[param] = arg; map_iter->second[param] = arg;
@ -122,7 +122,7 @@ void Config::Parse(const char *file_name)
} }
else else
{ {
map<string, string> var_map; std::map<std::string, std::string> var_map;
var_map[param] = arg; var_map[param] = arg;
vars[title] = var_map; vars[title] = var_map;
} }
@ -142,10 +142,10 @@ void Config::Parse(const char *file_name)
* Breaks up the input character stream into tokens and puts them into the list provided. * Breaks up the input character stream into tokens and puts them into the list provided.
* Ignores # as a line comment * Ignores # as a line comment
*/ */
void Config::Tokenize(FILE *input, list<string> &tokens) void Config::Tokenize(FILE *input, std::list<std::string> &tokens)
{ {
char c = fgetc(input); char c = fgetc(input);
string lexeme; std::string lexeme;
while(c != EOF) while(c != EOF)
{ {

View File

@ -23,8 +23,6 @@
#include <map> #include <map>
#include <string> #include <string>
using namespace std;
/** /**
* Keeps track of all the configuration for the application with a small parser. * Keeps track of all the configuration for the application with a small parser.
* Note: This is not a thread safe class, but only parse writes to variables in the class. * Note: This is not a thread safe class, but only parse writes to variables in the class.
@ -44,10 +42,10 @@ public:
/** /**
* Gets a variable if it exists. * Gets a variable if it exists.
*/ */
string GetVariable(string title, string parameter); std::string GetVariable(std::string title, std::string parameter);
protected: protected:
map<string, map<string, string> > vars; std::map<std::string, std::map<std::string, std::string> > vars;
private: private:
/** /**
@ -56,7 +54,7 @@ private:
* may get it's input from other places than a C file pointer. (a http get request for example). * may get it's input from other places than a C file pointer. (a http get request for example).
* The programmer of a derived class would be expected to make their own Tokenize function for their own Parse(). * The programmer of a derived class would be expected to make their own Tokenize function for their own Parse().
*/ */
void Tokenize(FILE* input, list<string> &tokens); void Tokenize(FILE* input, std::list<std::string> &tokens);
}; };
#endif #endif

View File

@ -20,8 +20,6 @@
#include <string> #include <string>
using namespace std;
#define EQEMU_MYSQL_ENABLED #define EQEMU_MYSQL_ENABLED
//#define EQEMU_POSTGRESQL_ENABLED //#define EQEMU_POSTGRESQL_ENABLED
@ -44,37 +42,37 @@ public:
* Needed for client login procedure. * Needed for client login procedure.
* Returns true if the record was found, false otherwise. * Returns true if the record was found, false otherwise.
*/ */
virtual bool GetLoginDataFromAccountName(string name, string &password, unsigned int &id) { return false; } virtual bool GetLoginDataFromAccountName(std::string name, std::string &password, unsigned int &id) { return false; }
/** /**
* Retrieves the world registration from the long and short names provided. * Retrieves the world registration from the long and short names provided.
* Needed for world login procedure. * Needed for world login procedure.
* Returns true if the record was found, false otherwise. * Returns true if the record was found, false otherwise.
*/ */
virtual bool GetWorldRegistration(string long_name, string short_name, unsigned int &id, string &desc, unsigned int &list_id, virtual bool GetWorldRegistration(std::string long_name, std::string short_name, unsigned int &id, std::string &desc, unsigned int &list_id,
unsigned int &trusted, string &list_desc, string &account, string &password) { return false; } unsigned int &trusted, std::string &list_desc, std::string &account, std::string &password) { return false; }
/** /**
* Updates the ip address of the client with account id = id * Updates the ip address of the client with account id = id
*/ */
virtual void UpdateLSAccountData(unsigned int id, string ip_address) { } virtual void UpdateLSAccountData(unsigned int id, std::string ip_address) { }
/** /**
* Updates or creates the login server account with info from world server * Updates or creates the login server account with info from world server
*/ */
virtual void UpdateLSAccountInfo(unsigned int id, string name, string password, string email) { } virtual void UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email) { }
/** /**
* Updates the ip address of the world with account id = id * Updates the ip address of the world with account id = id
*/ */
virtual void UpdateWorldRegistration(unsigned int id, string long_name, string ip_address) { } virtual void UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address) { }
/** /**
* Creates new world registration for unregistered servers and returns new id * Creates new world registration for unregistered servers and returns new id
*/ */
virtual bool CreateWorldRegistration(string long_name, string short_name, unsigned int &id) { return false; } virtual bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id) { return false; }
protected: protected:
string user, pass, host, port, name; std::string user, pass, host, port, name;
}; };
#endif #endif

View File

@ -43,7 +43,8 @@ DatabaseMySQL::DatabaseMySQL(string user, string pass, string host, string port,
if(!mysql_real_connect(db, host.c_str(), user.c_str(), pass.c_str(), name.c_str(), atoi(port.c_str()), nullptr, 0)) if(!mysql_real_connect(db, host.c_str(), user.c_str(), pass.c_str(), name.c_str(), atoi(port.c_str()), nullptr, 0))
{ {
mysql_close(db); mysql_close(db);
server_log->Log(log_database, "Failed to connect to MySQL database."); server_log->Log(log_database, "Failed to connect to MySQL database. Error: %s", mysql_error(db));
exit(1);
} }
} }
else else

View File

@ -26,8 +26,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <mysql.h> #include <mysql.h>
using namespace std;
/** /**
* Mysql Database class * Mysql Database class
*/ */
@ -42,7 +40,7 @@ public:
/** /**
* Constructor, tries to set our database to connect to the supplied options. * Constructor, tries to set our database to connect to the supplied options.
*/ */
DatabaseMySQL(string user, string pass, string host, string port, string name); DatabaseMySQL(std::string user, std::string pass, std::string host, std::string port, std::string name);
/** /**
* Destructor, frees our database if needed. * Destructor, frees our database if needed.
@ -59,37 +57,37 @@ public:
* Needed for client login procedure. * Needed for client login procedure.
* Returns true if the record was found, false otherwise. * Returns true if the record was found, false otherwise.
*/ */
virtual bool GetLoginDataFromAccountName(string name, string &password, unsigned int &id); virtual bool GetLoginDataFromAccountName(std::string name, std::string &password, unsigned int &id);
/** /**
* Retrieves the world registration from the long and short names provided. * Retrieves the world registration from the long and short names provided.
* Needed for world login procedure. * Needed for world login procedure.
* Returns true if the record was found, false otherwise. * Returns true if the record was found, false otherwise.
*/ */
virtual bool GetWorldRegistration(string long_name, string short_name, unsigned int &id, string &desc, unsigned int &list_id, virtual bool GetWorldRegistration(std::string long_name, std::string short_name, unsigned int &id, std::string &desc, unsigned int &list_id,
unsigned int &trusted, string &list_desc, string &account, string &password); unsigned int &trusted, std::string &list_desc, std::string &account, std::string &password);
/** /**
* Updates the ip address of the client with account id = id * Updates the ip address of the client with account id = id
*/ */
virtual void UpdateLSAccountData(unsigned int id, string ip_address); virtual void UpdateLSAccountData(unsigned int id, std::string ip_address);
/** /**
* Updates or creates the login server account with info from world server * Updates or creates the login server account with info from world server
*/ */
virtual void UpdateLSAccountInfo(unsigned int id, string name, string password, string email); virtual void UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email);
/** /**
* Updates the ip address of the world with account id = id * Updates the ip address of the world with account id = id
*/ */
virtual void UpdateWorldRegistration(unsigned int id, string long_name, string ip_address); virtual void UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address);
/** /**
* Creates new world registration for unregistered servers and returns new id * Creates new world registration for unregistered servers and returns new id
*/ */
virtual bool CreateWorldRegistration(string long_name, string short_name, unsigned int &id); virtual bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id);
protected: protected:
string user, pass, host, port, name; std::string user, pass, host, port, name;
MYSQL *db; MYSQL *db;
}; };

View File

@ -18,10 +18,11 @@
#include "../common/debug.h" #include "../common/debug.h"
#include "Encryption.h" #include "Encryption.h"
#include "ErrorLog.h" #include "ErrorLog.h"
#include <string>
extern ErrorLog *server_log; extern ErrorLog *server_log;
bool Encryption::LoadCrypto(string name) bool Encryption::LoadCrypto(std::string name)
{ {
if(!Load(name.c_str())) if(!Load(name.c_str()))
{ {

View File

@ -22,8 +22,6 @@
#include <windows.h> #include <windows.h>
#include <string> #include <string>
using namespace std;
typedef char*(*DLLFUNC_DecryptUsernamePassword)(const char*, unsigned int, int); typedef char*(*DLLFUNC_DecryptUsernamePassword)(const char*, unsigned int, int);
typedef char*(*DLLFUNC_Encrypt)(const char*, unsigned int, unsigned int&); typedef char*(*DLLFUNC_Encrypt)(const char*, unsigned int, unsigned int&);
typedef void(*DLLFUNC_HeapDelete)(char*); typedef void(*DLLFUNC_HeapDelete)(char*);
@ -54,7 +52,7 @@ public:
* Loads the plugin. * Loads the plugin.
* True if there are no errors, false if there was an error. * True if there are no errors, false if there was an error.
*/ */
bool LoadCrypto(string name); bool LoadCrypto(std::string name);
/** /**
* Wrapper around the plugin's decrypt function. * Wrapper around the plugin's decrypt function.

View File

@ -25,8 +25,6 @@
#include "../common/Mutex.h" #include "../common/Mutex.h"
using namespace std;
/** /**
* Dictates the log type specified in ErrorLog for Log(...) * Dictates the log type specified in ErrorLog for Log(...)
*/ */

View File

@ -32,7 +32,6 @@ TimeoutManager timeout_manager;
LoginServer server; LoginServer server;
ErrorLog *server_log; ErrorLog *server_log;
bool run_server = true; bool run_server = true;
using namespace std;
void CatchSignal(int sig_num) void CatchSignal(int sig_num)
{ {
@ -45,7 +44,7 @@ int main()
//Create our error log, is of format login_<number>.log //Create our error log, is of format login_<number>.log
time_t current_time = time(nullptr); time_t current_time = time(nullptr);
stringstream log_name(stringstream::in | stringstream::out); std::stringstream log_name(std::stringstream::in | std::stringstream::out);
#ifdef WIN32 #ifdef WIN32
log_name << ".\\logs\\login_" << (unsigned int)current_time << ".log"; log_name << ".\\logs\\login_" << (unsigned int)current_time << ".log";
#else #else
@ -90,14 +89,14 @@ int main()
} }
//Parse encryption mode option. //Parse encryption mode option.
string mode = server.config->GetVariable("security", "mode"); std::string mode = server.config->GetVariable("security", "mode");
if(mode.size() > 0) if(mode.size() > 0)
{ {
server.options.EncryptionMode(atoi(mode.c_str())); server.options.EncryptionMode(atoi(mode.c_str()));
} }
//Parse local network option. //Parse local network option.
string ln = server.config->GetVariable("options", "local_network"); std::string ln = server.config->GetVariable("options", "local_network");
if(ln.size() > 0) if(ln.size() > 0)
{ {
server.options.LocalNetwork(ln); server.options.LocalNetwork(ln);

View File

@ -100,52 +100,52 @@ public:
/** /**
* Sets local_network. * Sets local_network.
*/ */
inline void LocalNetwork(string n) { local_network = n; } inline void LocalNetwork(std::string n) { local_network = n; }
/** /**
* Return the value of local_network. * Return the value of local_network.
*/ */
inline string GetLocalNetwork() const { return local_network; } inline std::string GetLocalNetwork() const { return local_network; }
/** /**
* Sets account table. * Sets account table.
*/ */
inline void AccountTable(string t) { account_table = t; } inline void AccountTable(std::string t) { account_table = t; }
/** /**
* Return the value of local_network. * Return the value of local_network.
*/ */
inline string GetAccountTable() const { return account_table; } inline std::string GetAccountTable() const { return account_table; }
/** /**
* Sets world account table. * Sets world account table.
*/ */
inline void WorldRegistrationTable(string t) { world_registration_table = t; } inline void WorldRegistrationTable(std::string t) { world_registration_table = t; }
/** /**
* Return the value of world account table. * Return the value of world account table.
*/ */
inline string GetWorldRegistrationTable() const { return world_registration_table; } inline std::string GetWorldRegistrationTable() const { return world_registration_table; }
/** /**
* Sets world admin account table. * Sets world admin account table.
*/ */
inline void WorldAdminRegistrationTable(string t) { world_admin_registration_table = t; } inline void WorldAdminRegistrationTable(std::string t) { world_admin_registration_table = t; }
/** /**
* Return the value of world admin account table. * Return the value of world admin account table.
*/ */
inline string GetWorldAdminRegistrationTable() const { return world_admin_registration_table; } inline std::string GetWorldAdminRegistrationTable() const { return world_admin_registration_table; }
/** /**
* Sets world server type table. * Sets world server type table.
*/ */
inline void WorldServerTypeTable(string t) { world_server_type_table = t; } inline void WorldServerTypeTable(std::string t) { world_server_type_table = t; }
/** /**
* Return the value of world admin account table. * Return the value of world admin account table.
*/ */
inline string GetWorldServerTypeTable() const { return world_server_type_table; } inline std::string GetWorldServerTypeTable() const { return world_server_type_table; }
/** /**
* Sets whether we are rejecting duplicate servers or not. * Sets whether we are rejecting duplicate servers or not.
@ -165,11 +165,11 @@ private:
bool dump_out_packets; bool dump_out_packets;
bool reject_duplicate_servers; bool reject_duplicate_servers;
int encryption_mode; int encryption_mode;
string local_network; std::string local_network;
string account_table; std::string account_table;
string world_registration_table; std::string world_registration_table;
string world_admin_registration_table; std::string world_admin_registration_table;
string world_server_type_table; std::string world_server_type_table;
}; };
#endif #endif

View File

@ -28,8 +28,6 @@
#include "Client.h" #include "Client.h"
#include <list> #include <list>
using namespace std;
/** /**
* Server manager class, deals with management of the world servers. * Server manager class, deals with management of the world servers.
*/ */
@ -64,12 +62,12 @@ public:
/** /**
* Checks to see if there is a server exists with this name, ignoring option. * Checks to see if there is a server exists with this name, ignoring option.
*/ */
bool ServerExists(string l_name, string s_name, WorldServer *ignore = nullptr); bool ServerExists(std::string l_name, std::string s_name, WorldServer *ignore = nullptr);
/** /**
* Destroys a server with this name, ignoring option. * Destroys a server with this name, ignoring option.
*/ */
void DestroyServerByName(string l_name, string s_name, WorldServer *ignore = nullptr); void DestroyServerByName(std::string l_name, std::string s_name, WorldServer *ignore = nullptr);
private: private:
/** /**
@ -84,7 +82,7 @@ private:
WorldServer* GetServerByAddress(unsigned int address); WorldServer* GetServerByAddress(unsigned int address);
EmuTCPServer* tcps; EmuTCPServer* tcps;
list<WorldServer*> world_servers; std::list<WorldServer*> world_servers;
}; };
#endif #endif

View File

@ -26,8 +26,6 @@
#include "../common/packet_dump.h" #include "../common/packet_dump.h"
#include <string> #include <string>
using namespace std;
/** /**
* World server class, controls the connected server processing. * World server class, controls the connected server processing.
*/ */
@ -78,12 +76,12 @@ public:
/** /**
* Gets the long name of the server. * Gets the long name of the server.
*/ */
string GetLongName() const { return long_name; } std::string GetLongName() const { return long_name; }
/** /**
* Gets the short name of the server. * Gets the short name of the server.
*/ */
string GetShortName() const { return short_name; } std::string GetShortName() const { return short_name; }
/** /**
* Gets whether the server is authorized to show up on the server list or not. * Gets whether the server is authorized to show up on the server list or not.
@ -93,12 +91,12 @@ public:
/** /**
* Gets the local ip of the server. * Gets the local ip of the server.
*/ */
string GetLocalIP() const { return local_ip; } std::string GetLocalIP() const { return local_ip; }
/** /**
* Gets the remote ip of the server. * Gets the remote ip of the server.
*/ */
string GetRemoteIP() const { return remote_ip; } std::string GetRemoteIP() const { return remote_ip; }
/** /**
* Gets what kind of server this server is (legends, preferred, normal) * Gets what kind of server this server is (legends, preferred, normal)
@ -133,7 +131,7 @@ public:
/** /**
* Informs world that there is a client incoming with the following data. * Informs world that there is a client incoming with the following data.
*/ */
void SendClientAuth(unsigned int ip, string account, string key, unsigned int account_id); void SendClientAuth(unsigned int ip, std::string account, std::string key, unsigned int account_id);
private: private:
@ -144,15 +142,15 @@ private:
unsigned int runtime_id; unsigned int runtime_id;
unsigned int server_list_id; unsigned int server_list_id;
unsigned int server_type; unsigned int server_type;
string desc; std::string desc;
string long_name; std::string long_name;
string short_name; std::string short_name;
string account_name; std::string account_name;
string account_password; std::string account_password;
string remote_ip; std::string remote_ip;
string local_ip; std::string local_ip;
string protocol; std::string protocol;
string version; std::string version;
bool authorized; bool authorized;
bool logged_in; bool logged_in;
bool trusted; bool trusted;

View File

@ -17,12 +17,13 @@ SET(qserv_headers
ADD_EXECUTABLE(queryserv ${qserv_sources} ${qserv_headers}) ADD_EXECUTABLE(queryserv ${qserv_sources} ${qserv_headers})
INSTALL(TARGETS queryserv RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
ADD_DEFINITIONS(-DQSERV) ADD_DEFINITIONS(-DQSERV)
TARGET_LINK_LIBRARIES(queryserv Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) TARGET_LINK_LIBRARIES(queryserv Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(queryserv PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") SET_TARGET_PROPERTIES(queryserv PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(queryserv "Ws2_32.lib") TARGET_LINK_LIBRARIES(queryserv "Ws2_32.lib")
ENDIF(MSVC) ENDIF(MSVC)

View File

@ -20,7 +20,6 @@
#include "../common/debug.h" #include "../common/debug.h"
#include <iostream> #include <iostream>
using namespace std;
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -44,7 +43,7 @@ using namespace std;
#include "database.h" #include "database.h"
#include "../common/eq_packet_structs.h" #include "../common/eq_packet_structs.h"
#include "../common/MiscFunctions.h" #include "../common/StringUtil.h"
#include "../common/servertalk.h" #include "../common/servertalk.h"
Database::Database () Database::Database ()

View File

@ -31,7 +31,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
using namespace std;
//atoi is not uint32 or uint32 safe!!!! //atoi is not uint32 or uint32 safe!!!!
#define atoul(str) strtoul(str, nullptr, 10) #define atoul(str) strtoul(str, nullptr, 10)

View File

@ -2,7 +2,7 @@
#include "lfguild.h" #include "lfguild.h"
#include "database.h" #include "database.h"
#include "worldserver.h" #include "worldserver.h"
#include "../common/MiscFunctions.h" #include "../common/StringUtil.h"
#include "../common/packet_dump.h" #include "../common/packet_dump.h"
#include "../common/rulesys.h" #include "../common/rulesys.h"

View File

@ -40,7 +40,7 @@ TimeoutManager timeout_manager;
Database database; Database database;
LFGuildManager lfguildmanager; LFGuildManager lfguildmanager;
string WorldShortName; std::string WorldShortName;
const queryservconfig *Config; const queryservconfig *Config;

View File

@ -22,7 +22,7 @@
queryservconfig *queryservconfig::_chat_config = nullptr; queryservconfig *queryservconfig::_chat_config = nullptr;
string queryservconfig::GetByName(const string &var_name) const { std::string queryservconfig::GetByName(const std::string &var_name) const {
return(EQEmuConfig::GetByName(var_name)); return(EQEmuConfig::GetByName(var_name));
} }

Some files were not shown because too many files have changed in this diff Show More