diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index b5f6768bf..1f613a885 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -10,7 +10,6 @@ SET(common_sources database.cpp dbasync.cpp dbcore.cpp - DBMemLeak.cpp debug.cpp emu_opcodes.cpp EmuTCPConnection.cpp @@ -103,7 +102,6 @@ SET(common_headers database.h dbasync.h dbcore.h - DBMemLeak.h debug.h deity.h emu_opcodes.h diff --git a/common/Condition.cpp b/common/Condition.cpp index bb4dba96e..7d99d0a43 100644 --- a/common/Condition.cpp +++ b/common/Condition.cpp @@ -20,134 +20,129 @@ #include "Condition.h" #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 -#include -#include -#include + #include + #include + #include + + 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 << "."< 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 << "."< -#include -#include -#include "../common/Mutex.h" -#include "DBMemLeak.h" - -#include - -#ifdef _WINDOWS -#define snprintf _snprintf -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#endif - -DBMemLeak dbmemleak; -LinkedList* list = 0; -Mutex MDBMemLeak; - -DBMemLeak::DBMemLeak() { - list = new LinkedList; -} - -DBMemLeak::~DBMemLeak() { - LinkedListIterator 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 iterator(*list); - iterator.Reset(); - while (iterator.MoreElements()) { - if (result == iterator.GetData()->result) - iterator.RemoveCurrent(); - else - iterator.Advance(); - } -} -#endif diff --git a/common/DBMemLeak.h b/common/DBMemLeak.h deleted file mode 100644 index 48f3f7374..000000000 --- a/common/DBMemLeak.h +++ /dev/null @@ -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 diff --git a/common/EQStream.cpp b/common/EQStream.cpp index 2127fc31e..1c17c4871 100644 --- a/common/EQStream.cpp +++ b/common/EQStream.cpp @@ -15,15 +15,32 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #include "debug.h" +#include "EQPacket.h" +#include "EQStream.h" +#include "misc.h" +#include "Mutex.h" +#include "op_codes.h" +#include "CRC16.h" + #include #include #include #include -#include +#include + +#if defined(ZONE) || defined(WORLD) + #define RETRANSMITS +#endif +#ifdef RETRANSMITS + #include "rulesys.h" +#endif + #ifdef _WINDOWS #include #else + #include #include #include #include @@ -32,20 +49,6 @@ #include #include #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 #define _L "%s:%d: " diff --git a/common/Item.cpp b/common/Item.cpp index 4a1b9e917..3e798363e 100644 --- a/common/Item.cpp +++ b/common/Item.cpp @@ -16,20 +16,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifdef _WINDOWS - // VS6 doesn't like the length of STL generated names: disabling - #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 -#include -#include +#include "debug.h" +#include "StringUtil.h" #include "Item.h" #include "database.h" #include "misc.h" @@ -37,6 +25,11 @@ #include "shareddb.h" #include "classes.h" +#include + +#include +#include + int32 NextItemInstSerialNumber = 1; static inline int32 GetNextItemInstSerialNumber() { @@ -1059,103 +1052,75 @@ int16 Inventory::FindFreeSlot(bool for_bag, bool try_cursor, uint8 min_size, boo 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 &collection) { iter_inst it; iter_contents itb; ItemInst* inst = nullptr; - - // Check item: After failed checks, check bag contents (if bag) - printf("Worn items:\n"); - for (it=m_worn.begin(); it!=m_worn.end(); it++) { + + for (it=collection.begin(); it!=collection.end(); it++) { inst = it->second; it->first; if(!inst || !inst->GetItem()) 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()); - - // 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()); - } - } + dumpBagContents(inst, &it); } +} - printf("Inventory items:\n"); - for (it=m_inv.begin(); it!=m_inv.end(); it++) { - inst = it->second; - it->first; - if(!inst || !inst->GetItem()) - continue; +void Inventory::dumpWornItems() { + std::cout << "Worn items:" << std::endl; + dumpItemCollection(m_worn); +} - 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 - 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()); +void Inventory::dumpBankItems() { + + std::cout << "Bank items:" << std::endl; + dumpItemCollection(m_bank); +} - } - } - } +void Inventory::dumpSharedBankItems() { + + std::cout << "Shared Bank items:" << std::endl; + dumpItemCollection(m_shbank); +} - printf("Bank items:\n"); - for (it=m_bank.begin(); it!=m_bank.end(); it++) { - inst = it->second; - it->first; - if(!inst || !inst->GetItem()) - continue; +void Inventory::dumpEntireInventory() { - 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("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); + dumpWornItems(); + dumpInventory(); + dumpBankItems(); + dumpSharedBankItems(); + + std::cout << std::endl; } // Internal Method: Retrieves item within an inventory bucket diff --git a/common/Item.h b/common/Item.h index b0f1ec449..5631f4fd5 100644 --- a/common/Item.h +++ b/common/Item.h @@ -195,7 +195,11 @@ public: // Test whether a given slot can support a container item static bool SupportsContainers(int16 slot_id); + void dumpEntireInventory(); + void dumpWornItems(); 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, int value); @@ -207,6 +211,9 @@ protected: // Protected Methods /////////////////////////////// + void dumpItemCollection(const std::map &collection); + void dumpBagContents(ItemInst *inst, iter_inst *it); + // Retrieves item within an inventory bucket ItemInst* _GetItem(const std::map& bucket, int16 slot_id) const; diff --git a/common/ProcLauncher.cpp b/common/ProcLauncher.cpp index b4b95bb91..da0cd81e9 100644 --- a/common/ProcLauncher.cpp +++ b/common/ProcLauncher.cpp @@ -15,21 +15,25 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include +#include + #include "debug.h" #include "ProcLauncher.h" #ifdef _WINDOWS -#include + #include #else -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include #endif ProcLauncher ProcLauncher::s_launcher; diff --git a/common/StringUtil.cpp b/common/StringUtil.cpp index b1269bf46..bba3433fb 100644 --- a/common/StringUtil.cpp +++ b/common/StringUtil.cpp @@ -126,27 +126,6 @@ bool strn0cpyt(char* dest, const char* source, uint32 size) { 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) diff --git a/common/StringUtil.h b/common/StringUtil.h index e98bd9c0f..ecfacc97d 100644 --- a/common/StringUtil.h +++ b/common/StringUtil.h @@ -23,19 +23,9 @@ void vStringFormat(std::string& output, const char* format, va_list args); void StringFormat(std::string& output, const char* format, ...); -////////////////////////////////////////////////////////////////////// -// -// MakeUpperString -// i : source - allocated null-terminated string -// return: pointer to static buffer with the target string -const char *MakeUpperString(const char *source); + const char *MakeLowerString(const char *source); -////////////////////////////////////////////////////////////////////// -// -// MakeUpperString -// i : source - allocated null-terminated string -// io: target - allocated buffer, at least of size strlen(source)+1 -void MakeUpperString(const char *source, char *target); + void MakeLowerString(const char *source, char *target); diff --git a/common/database.h b/common/database.h index 22474a807..b194476b8 100644 --- a/common/database.h +++ b/common/database.h @@ -216,7 +216,7 @@ public: const char *GetRaidLeaderName(uint32 rid); /* - * Database Varaibles + * Database Variables */ bool GetVariable(const char* varname, char* varvalue, uint16 varvalue_len); bool SetVariable(const char* varname, const char* varvalue); diff --git a/common/dbcore.h b/common/dbcore.h index b43752c1f..ed5e62133 100644 --- a/common/dbcore.h +++ b/common/dbcore.h @@ -7,7 +7,6 @@ //#include #endif #include -#include "../common/DBMemLeak.h" #include "../common/types.h" #include "../common/Mutex.h" #include "../common/linked_list.h" diff --git a/common/debug.h b/common/debug.h index 3961598a6..de04fe0ff 100644 --- a/common/debug.h +++ b/common/debug.h @@ -45,22 +45,9 @@ #ifndef _CRTDBG_MAP_ALLOC #include #include - #if (_MSC_VER < 1300) - #include - #include - #define _CRTDBG_MAP_ALLOC - #define new new(_NORMAL_BLOCK, __FILE__, __LINE__) - #define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__) - #endif #endif #endif -#ifdef _WINDOWS - // VS6 doesn't like the length of STL generated names: disabling - #pragma warning(disable:4786) - #pragma warning(disable:4996) -#endif - #ifndef EQDEBUG_H #define EQDEBUG_H diff --git a/common/logsys_eqemu.cpp b/common/logsys_eqemu.cpp index 79ea82ec0..5086114f5 100644 --- a/common/logsys_eqemu.cpp +++ b/common/logsys_eqemu.cpp @@ -18,9 +18,12 @@ #include "debug.h" #include "logsys.h" +#include "StringUtil.h" + #include #include -#include + +#include void log_message(LogType type, const char *fmt, ...) { 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) { - char prefix_buffer[256]; - snprintf(prefix_buffer, 255, "[%s] ", log_type_info[type].name); - prefix_buffer[255] = '\0'; - - LogFile->writePVA(EQEMuLog::Debug, prefix_buffer, fmt, args); + std::string prefix_buffer; + + StringFormat(prefix_buffer, "[%s] ", log_type_info[type].name); + + LogFile->writePVA(EQEMuLog::Debug, prefix_buffer.c_str(), fmt, args); } diff --git a/common/shareddb.cpp b/common/shareddb.cpp index a9745bbca..fa6af0f58 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -1,7 +1,9 @@ -#include "shareddb.h" #include #include #include + +#include "shareddb.h" +#include "mysql.h" #include "Item.h" #include "classes.h" #include "rulesys.h" diff --git a/loginserver/Encryption.cpp b/loginserver/Encryption.cpp index bd947593b..c846e5130 100644 --- a/loginserver/Encryption.cpp +++ b/loginserver/Encryption.cpp @@ -20,6 +20,8 @@ #include "ErrorLog.h" #include +#include + extern ErrorLog *server_log; bool Encryption::LoadCrypto(std::string name) diff --git a/world/client.cpp b/world/client.cpp index 10472969f..475df7a17 100644 --- a/world/client.cpp +++ b/world/client.cpp @@ -2,8 +2,34 @@ #include "../common/EQPacket.h" #include "../common/EQStreamIntf.h" #include "../common/misc.h" +#include "../common/rulesys.h" +#include "../common/emu_opcodes.h" +#include "../common/eq_packet_structs.h" +#include "../common/packet_dump.h" +#include "../common/EQStreamIntf.h" +#include "../common/Item.h" +#include "../common/races.h" +#include "../common/classes.h" +#include "../common/languages.h" +#include "../common/skills.h" +#include "../common/extprofile.h" +#include "../common/StringUtil.h" +#include "../common/clientversions.h" + +#include "client.h" +#include "worlddb.h" +#include "WorldConfig.h" +#include "LoginServer.h" +#include "LoginServerList.h" +#include "zoneserver.h" +#include "zonelist.h" +#include "clientlist.h" +#include "wguild_mgr.h" +#include "SoFCharCreateData.h" + #include #include + #include #include #include @@ -17,44 +43,18 @@ #ifdef _WINDOWS #include #include - #define snprintf _snprintf - #define strncasecmp _strnicmp - #define strcasecmp _stricmp #else + + #ifdef FREEBSD //Timothy Whitman - January 7, 2003 + #include + #endif + #include -#ifdef FREEBSD //Timothy Whitman - January 7, 2003 - #include -#endif #include #include #include #endif - -#include "client.h" -#include "../common/emu_opcodes.h" -#include "../common/eq_packet_structs.h" -#include "../common/packet_dump.h" -#include "../common/EQStreamIntf.h" -#include "worlddb.h" -#include "../common/Item.h" -#include "../common/races.h" -#include "../common/classes.h" -#include "../common/languages.h" -#include "../common/skills.h" -#include "../common/extprofile.h" -#include "../common/StringUtil.h" -#include "WorldConfig.h" -#include "LoginServer.h" -#include "LoginServerList.h" -#include "zoneserver.h" -#include "zonelist.h" -#include "clientlist.h" -#include "wguild_mgr.h" -#include "../common/rulesys.h" -#include "SoFCharCreateData.h" -#include "../common/clientversions.h" - std::vector character_create_allocations; std::vector character_create_race_class_combos; diff --git a/world/world_logsys.cpp b/world/world_logsys.cpp index 2d94a4042..f60186a86 100644 --- a/world/world_logsys.cpp +++ b/world/world_logsys.cpp @@ -1,18 +1,21 @@ #include "../common/debug.h" #include "../common/logsys.h" +#include "../common/StringUtil.h" + #include "zoneserver.h" #include "client.h" + #include #include void log_message_clientVA(LogType type, Client *who, const char *fmt, va_list args) { - char prefix_buffer[256]; - snprintf(prefix_buffer, 255, "[%s] %s: ", log_type_info[type].name, who->GetAccountName()); - prefix_buffer[255] = '\0'; - LogFile->writePVA(EQEMuLog::Debug, prefix_buffer, fmt, args); + std::string prefix_buffer; + StringFormat(prefix_buffer,"[%s] %s: ", log_type_info[type].name, who->GetAccountName()); + + LogFile->writePVA(EQEMuLog::Debug, prefix_buffer.c_str(), fmt, args); } void log_message_client(LogType type, Client *who, const char *fmt, ...) { @@ -24,18 +27,17 @@ void log_message_client(LogType type, Client *who, const char *fmt, ...) { void log_message_zoneVA(LogType type, ZoneServer *who, const char *fmt, va_list args) { - char prefix_buffer[256]; - char zone_tag[65]; + std::string prefix_buffer, zone_tag; const char *zone_name=who->GetZoneName(); - if (*zone_name==0) - snprintf(zone_tag,64,"[%d]", who->GetID()); + + if (zone_name == nullptr) + StringFormat(zone_tag,"[%d]", who->GetID()); else - snprintf(zone_tag,64,"[%d] [%s]",who->GetID(),zone_name); + StringFormat(zone_tag,"[%d] [%s]",who->GetID(),zone_name); - snprintf(prefix_buffer, 255, "[%s] %s ", log_type_info[type].name, zone_tag); - prefix_buffer[255] = '\0'; + StringFormat(prefix_buffer, "[%s] %s ", log_type_info[type].name, zone_tag.c_str()); - LogFile->writePVA(EQEMuLog::Debug, prefix_buffer, fmt, args); + LogFile->writePVA(EQEMuLog::Debug, prefix_buffer.c_str(), fmt, args); } void log_message_zone(LogType type, ZoneServer *who, const char *fmt, ...) { diff --git a/zone/PlayerCorpse.cpp b/zone/PlayerCorpse.cpp index 03607b64f..d2f9120df 100644 --- a/zone/PlayerCorpse.cpp +++ b/zone/PlayerCorpse.cpp @@ -27,12 +27,10 @@ Child of the Mob class. #include #include #ifdef _WINDOWS -#define snprintf _snprintf -#if (_MSC_VER < 1500) + #define snprintf _snprintf #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #endif #include "masterentity.h" diff --git a/zone/attack.cpp b/zone/attack.cpp index e8c009efd..7d428d6f8 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -1476,7 +1476,7 @@ void Client::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_ if (killerMob != nullptr) { if (killerMob->IsNPC()) { - parse->EventNPC(EVENT_SLAY, killerMob->CastToNPC(), this, "", 0); + parse->EventNPC(EVENT_SLAY, killerMob->CastToNPC(), this, "", 0); mod_client_death_npc(killerMob); @@ -2124,7 +2124,7 @@ void NPC::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_ski /* Send the EVENT_KILLED_MERIT event for all raid members */ for (int i = 0; i < MAX_RAID_MEMBERS; i++) { if (kr->members[i].member != nullptr) { // If Group Member is Client - parse->EventNPC(EVENT_KILLED_MERIT, this, kr->members[i].member, "killed", 0); + parse->EventNPC(EVENT_KILLED_MERIT, this, kr->members[i].member, "killed", 0); mod_npc_killed_merit(kr->members[i].member); @@ -2167,7 +2167,7 @@ void NPC::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_ski for (int i = 0; i < MAX_GROUP_MEMBERS; i++) { if (kg->members[i] != nullptr && kg->members[i]->IsClient()) { // If Group Member is Client Client *c = kg->members[i]->CastToClient(); - parse->EventNPC(EVENT_KILLED_MERIT, this, c, "killed", 0); + parse->EventNPC(EVENT_KILLED_MERIT, this, c, "killed", 0); mod_npc_killed_merit(c); @@ -2214,7 +2214,7 @@ void NPC::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_ski } } /* Send the EVENT_KILLED_MERIT event */ - parse->EventNPC(EVENT_KILLED_MERIT, this, give_exp_client, "killed", 0); + parse->EventNPC(EVENT_KILLED_MERIT, this, give_exp_client, "killed", 0); mod_npc_killed_merit(give_exp_client); @@ -2347,7 +2347,7 @@ void NPC::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_ski // Parse quests even if we're killed by an NPC if(killerMob) { Mob *oos = killerMob->GetOwnerOrSelf(); - parse->EventNPC(EVENT_DEATH, this, oos, "", 0); + parse->EventNPC(EVENT_DEATH, this, oos, "", 0); mod_npc_killed(oos); @@ -4234,7 +4234,7 @@ void Mob::ApplyMeleeDamageBonus(uint16 skill, int32 &damage){ if(!RuleB(Combat, UseIntervalAC)){ if(IsNPC()){ //across the board NPC damage bonuses. - //only account for STR here, assume their base STR was factored into their DB damages + //only account for STR here, assume their base STR was factored into their DB damages int dmgbonusmod = 0; dmgbonusmod += (100*(itembonuses.STR + spellbonuses.STR))/3; dmgbonusmod += (100*(spellbonuses.ATK + itembonuses.ATK))/5; diff --git a/zone/beacon.cpp b/zone/beacon.cpp index 2d2d9a942..9b88dd524 100644 --- a/zone/beacon.cpp +++ b/zone/beacon.cpp @@ -24,13 +24,12 @@ target to center around. */ #include "../common/debug.h" + #ifdef _WINDOWS -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define snprintf _snprintf + #define vsnprintf _vsnprintf + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #endif #include "masterentity.h" diff --git a/zone/client.cpp b/zone/client.cpp index 8784f02f2..8779246c0 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -26,19 +26,13 @@ // for windows compile #ifdef _WINDOWS -#define abs64 _abs64 -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define abs64 _abs64 #else -#include -#include -#include -#include "../common/unix.h" -#define abs64 abs + #include + #include + #include + #include "../common/unix.h" + #define abs64 abs #endif extern volatile bool RunLoops; @@ -601,7 +595,7 @@ bool Client::Save(uint8 iCommitNow) { p_timers.Store(&database); // printf("Dumping inventory on save:\n"); -// m_inv.dumpInventory(); +// m_inv.dumpEntireInventory(); SaveTaskState(); if (iCommitNow <= 1) { diff --git a/zone/client.h b/zone/client.h index 296f5c4cd..2a51bdca2 100644 --- a/zone/client.h +++ b/zone/client.h @@ -19,8 +19,6 @@ #define CLIENT_H class Client; - - #include "../common/timer.h" #include "../common/ptimer.h" #include "../common/emu_opcodes.h" @@ -30,29 +28,39 @@ class Client; #include "../common/EQPacket.h" #include "../common/linked_list.h" #include "../common/extprofile.h" -#include "zonedb.h" -#include "errno.h" #include "../common/classes.h" #include "../common/races.h" #include "../common/deity.h" +#include "../common/seperator.h" +#include "../common/Item.h" +#include "../common/guilds.h" +#include "../common/item_struct.h" +#include "../common/clientversions.h" + +#include "zonedb.h" +#include "errno.h" #include "mob.h" #include "npc.h" #include "merc.h" #include "zone.h" #include "AA.h" -#include "../common/seperator.h" -#include "../common/Item.h" #include "updatemgr.h" -#include "../common/guilds.h" #include "questmgr.h" +#include "QGlobals.h" + +#ifdef _WINDOWS + // since windows defines these within windef.h (which windows.h include) + // we are required to undefine these to use min and max from + #undef min + #undef max +#endif + #include #include #include -#include "../common/item_struct.h" -#include "../common/clientversions.h" -#include "QGlobals.h" #include + #define CLIENT_TIMEOUT 90000 #define CLIENT_LD_TIMEOUT 30000 // length of time client stays in zone after LDing #define TARGETING_RANGE 200 // range for /assist and /target diff --git a/zone/client_mods.cpp b/zone/client_mods.cpp index 5ed426789..73774ca6b 100644 --- a/zone/client_mods.cpp +++ b/zone/client_mods.cpp @@ -15,19 +15,21 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "../common/debug.h" -#include "masterentity.h" -#include "worldserver.h" -#include "zonedb.h" #include "../common/spdat.h" #include "../common/packet_dump.h" #include "../common/packet_functions.h" -#include "petitions.h" #include "../common/serverinfo.h" #include "../common/ZoneNumbers.h" #include "../common/moremath.h" #include "../common/guilds.h" #include "../common/logsys.h" +#include "masterentity.h" +#include "worldserver.h" +#include "zonedb.h" +#include "petitions.h" #include "StringIDs.h" #include "NpcAI.h" diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index a6c8c4eba..adc7ca95e 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -9192,7 +9192,7 @@ bool Client::FinishConnState2(DBAsyncWork* dbaw) { #ifdef _EQDEBUG printf("Dumping inventory on load:\n"); - m_inv.dumpInventory(); + m_inv.dumpEntireInventory(); #endif //lost in current PP diff --git a/zone/entity.h b/zone/entity.h index f6fcd7d46..9d25ceeeb 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -20,12 +20,13 @@ #include "../common/types.h" #include "../common/linked_list.h" -#include "zonedb.h" -#include "../common/eq_constants.h" -#include "zonedump.h" -#include "zonedbasync.h" #include "../common/servertalk.h" #include "../common/bodytypes.h" +#include "../common/eq_constants.h" + +#include "zonedb.h" +#include "zonedump.h" +#include "zonedbasync.h" #include "QGlobals.h" // max number of newspawns to send per bulk packet diff --git a/zone/net.cpp b/zone/net.cpp index b9a63b4d1..4108894bc 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -1,4 +1,3 @@ -#define DONT_SHARED_OPCODES /* EQEMu: Everquest Server Emulator Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) @@ -16,34 +15,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#define DONT_SHARED_OPCODES + #include "../common/debug.h" #include "../common/features.h" -#include -#include -#include -#include -#include -#include - #ifdef _CRTDBG_MAP_ALLOC - #undef new - #endif -#include - #ifdef _CRTDBG_MAP_ALLOC - #define new new(_NORMAL_BLOCK, __FILE__, __LINE__) - #endif -#ifdef _WINDOWS -#include -#define snprintf _snprintf -#if (_MSC_VER < 1500) - #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#endif - -volatile bool RunLoops = true; -extern volatile bool ZoneLoaded; - #include "../common/queue.h" #include "../common/timer.h" #include "../common/EQStream.h" @@ -52,7 +28,6 @@ extern volatile bool ZoneLoaded; #include "../common/Mutex.h" #include "../common/version.h" #include "../common/EQEMuError.h" -#include "ZoneConfig.h" #include "../common/packet_dump_file.h" #include "../common/opcodemgr.h" #include "../common/guilds.h" @@ -60,16 +35,18 @@ extern volatile bool ZoneLoaded; #include "../common/patches/patches.h" #include "../common/rulesys.h" #include "../common/MiscFunctions.h" +#include "../common/StringUtil.h" #include "../common/platform.h" #include "../common/crash.h" #include "../common/ipc_mutex.h" #include "../common/memory_mapped_file.h" #include "../common/eqemu_exception.h" +#include "../common/spdat.h" +#include "ZoneConfig.h" #include "masterentity.h" #include "worldserver.h" #include "net.h" -#include "../common/spdat.h" #include "zone.h" #include "command.h" #include "parser.h" @@ -82,6 +59,33 @@ extern volatile bool ZoneLoaded; #include "tasks.h" #include "QuestParserCollection.h" +#include +#include +#include + +#include +#include +#include +#include + +#ifdef _CRTDBG_MAP_ALLOC + #undef new + #define new new(_NORMAL_BLOCK, __FILE__, __LINE__) +#endif + +#ifdef _WINDOWS + #include + #include +#else + #include + #include "../common/unix.h" +#endif + +volatile bool RunLoops = true; +extern volatile bool ZoneLoaded; + + + TimeoutManager timeout_manager; NetConnection net; EntityList entity_list; @@ -102,13 +106,6 @@ const SPDat_Spell_Struct* spells; void LoadSpells(EQEmu::MemoryMappedFile **mmf); int32 SPDAT_RECORDS = -1; -#ifdef _WINDOWS -#include -#else -#include -#include "../common/unix.h" -#endif - void Shutdown(); extern void MapOpcodes(); diff --git a/zone/tribute.cpp b/zone/tribute.cpp index bc9fbfa92..2f25fc660 100644 --- a/zone/tribute.cpp +++ b/zone/tribute.cpp @@ -25,21 +25,18 @@ #include #ifdef _WINDOWS -#include -#include -#include - -#define snprintf _snprintf -#if (_MSC_VER < 1500) + #include + #include + #include + #define snprintf _snprintf #define vsnprintf _vsnprintf -#endif -#define strncasecmp _strnicmp -#define strcasecmp _stricmp + #define strncasecmp _strnicmp + #define strcasecmp _stricmp #else -#include -#include -#include -#include "../common/unix.h" + #include + #include + #include + #include "../common/unix.h" #endif /*