diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 02119fd57..a9ae3fce3 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -95,7 +95,6 @@ SET(common_headers base_packet.h base_data.h bodytypes.h - breakdowns.h classes.h condition.h crash.h diff --git a/common/breakdowns.h b/common/breakdowns.h deleted file mode 100644 index 18dfb803f..000000000 --- a/common/breakdowns.h +++ /dev/null @@ -1,134 +0,0 @@ -/* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which - are required to give you total support for your newly bought product; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#ifndef BREAKDOWNS_H_ -#define BREAKDOWNS_H_ - -#include "types.h" - - -#pragma pack(1) -struct uint16_breakdown { - union { - uint16 all; - struct { - uint8 b1; - uint8 b2; - } bytes; - }; - inline uint16& operator=(const uint16& val) { return (all=val); } - inline uint16* operator&() { return &all; } - inline operator uint16&() { return all; } - inline uint8& b1() { return bytes.b1; } - inline uint8& b2() { return bytes.b2; } -}; - -struct uint32_breakdown { - union { - uint32 all; - struct { - uint16 w1; - uint16 w2; - } words; - struct { - uint8 b1; - union { - struct { - uint8 b2; - uint8 b3; - } middle; - uint16 w2_3; // word bytes 2 to 3 - }; - uint8 b4; - } bytes; - }; - inline uint32& operator=(const uint32& val) { return (all=val); } - inline uint32* operator&() { return &all; } - inline operator uint32&() { return all; } - - inline uint16& w1() { return words.w1; } - inline uint16& w2() { return words.w2; } - inline uint16& w2_3() { return bytes.w2_3; } - inline uint8& b1() { return bytes.b1; } - inline uint8& b2() { return bytes.middle.b2; } - inline uint8& b3() { return bytes.middle.b3; } - inline uint8& b4() { return bytes.b4; } -}; -/* -struct uint64_breakdown { - union { - uint64 all; - struct { - uint16 w1; // 1 2 - uint16 w2; // 3 4 - uint16 w3; // 5 6 - uint16 w4; // 7 8 - }; - struct { - uint32 dw1; // 1 4 - uint32 dw2; // 5 6 - }; - struct { - uint8 b1; - union { - struct { - uint16 w2_3; - uint16 w4_5; - uint16 w6_7; - }; - uint32 dw2_5; - struct { - uint8 b2; - union { - uint32 dw3_6; - struct { - uint8 b3; - union { - uint32 dw4_7; - struct { - uint8 b4; - uint8 b5; - uint8 b6; - uint8 b7; - }; - }; - }; - }; - }; - }; - }; - }; - inline uint64* operator&() { return &all; } - inline operator uint64&() { return all; } -}; -*/ -#pragma pack() - - - - - - - - - - - - - - -#endif /*BREAKDOWNS_H_*/ diff --git a/common/dbmemshare.cpp b/common/dbmemshare.cpp deleted file mode 100644 index 8447f6d0d..000000000 --- a/common/dbmemshare.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// Doors -#ifdef SHAREMEM -int32 Database::GetDoorsCount(uint32* oMaxID) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - query = new char[256]; - strcpy(query, "SELECT MAX(id), count(*) FROM doors"); - if (RunQuery(query, strlen(query), errbuf, &result)) { - safe_delete(query); - row = mysql_fetch_row(result); - if (row && row[1]) { - int32 ret = atoi(row[1]); - if (oMaxID) { - if (row[0]) - *oMaxID = atoi(row[0]); - else - *oMaxID = 0; - } - mysql_free_result(result); - return ret; - } - } - else { - cerr << "Error in GetDoorsCount query '" << query << "' " << errbuf << endl; - delete[] query; - return -1; - } - - return -1; -} - -extern "C" bool extDBLoadDoors(uint32 iDoorCount, uint32 iMaxDoorID) { return database.DBLoadDoors(iDoorCount, iMaxDoorID); } -const Door* Database::GetDoor(uint8 door_id, const char* zone_name) { - for(uint32 i=0; idoor_id == door_id && strcasecmp(door->zone_name, zone_name) == 0) - return door; - } - return 0; -} - -const Door* Database::GetDoorDBID(uint32 db_id) { - return EMuShareMemDLL.Doors.GetDoor(db_id); -} - -bool Database::LoadDoors() { - if (!EMuShareMemDLL.Load()) - return false; - int32 tmp_max_door_type = -1; - uint32 tmp = 0; - tmp_max_door_type = GetDoorsCount(&tmp); - if (tmp_max_door_type < 0) { - cout << "Error: Database::LoadDoors-ShareMem: GetDoorsCount() returned < 0" << endl; - return false; - } - max_door_type = tmp_max_door_type; - bool ret = EMuShareMemDLL.Doors.DLLLoadDoors(&extDBLoadDoors, sizeof(Door), max_door_type, tmp); - return ret; -} - -bool Database::DBLoadDoors(uint32 iDoorCount, uint32 iMaxDoorID) { - cout << "Loading Doors from database..." << endl; - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - query = new char[256]; - strcpy(query, "SELECT MAX(id), Count(*) FROM doors"); - if (RunQuery(query, strlen(query), errbuf, &result)) - { - safe_delete(query); - row = mysql_fetch_row(result); - if (row && row[0]) { - if (atoi(row[0]) > iMaxDoorID) { - cout << "Error: Insufficient shared memory to load doors." << endl; - cout << "Max(id): " << atoi(row[0]) << ", iMaxDoorID: " << iMaxDoorID << endl; - cout << "Fix this by increasing the MMF_MAX_Door_ID define statement" << endl; - return false; - } - if (atoi(row[1]) != iDoorCount) { - cout << "Error: Insufficient shared memory to load doors." << endl; - cout << "Count(*): " << atoi(row[1]) << ", iDoorCount: " << iDoorCount << endl; - return false; - } - max_door_type = atoi(row[0]); - mysql_free_result(result); - Door tmpDoor; - MakeAnyLenString(&query, "SELECT id,doorid,zone,name,pos_x,pos_y,pos_z,heading,opentype,guild,lockpick,keyitem,triggerdoor,triggertype from doors");//WHERE zone='%s'", zone_name - if (RunQuery(query, strlen(query), errbuf, &result)) - { - safe_delete(query); - while((row = mysql_fetch_row(result))) { - memset(&tmpDoor, 0, sizeof(Door)); - tmpDoor.db_id = atoi(row[0]); - tmpDoor.door_id = atoi(row[1]); - strn0cpy(tmpDoor.zone_name,row[2],32); - strn0cpy(tmpDoor.door_name,row[3],32); - tmpDoor.pos_x = (float)atof(row[4]); - tmpDoor.pos_y = (float)atof(row[5]); - tmpDoor.pos_z = (float)atof(row[6]); - tmpDoor.heading = atoi(row[7]); - tmpDoor.opentype = atoi(row[8]); - tmpDoor.guild_id = atoi(row[9]); - tmpDoor.lockpick = atoi(row[10]); - tmpDoor.keyitem = atoi(row[11]); - tmpDoor.trigger_door = atoi(row[12]); - tmpDoor.trigger_type = atoi(row[13]); - EMuShareMemDLL.Doors.cbAddDoor(tmpDoor.db_id, &tmpDoor); - Sleep(0); - } - mysql_free_result(result); - } - else - { - cerr << "Error in DBLoadDoors query '" << query << "' " << errbuf << endl; - delete[] query; - return false; - } - } - } - return true; -} -#endif - diff --git a/common/queues.h b/common/queues.h deleted file mode 100644 index 474d7d898..000000000 --- a/common/queues.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Code for generell handling of priority Queues. - Implemention of queues from "Algoritms in C" by Robert Sedgewick. - Copyright Monty Program KB. - By monty. -*/ - -#ifndef _queues_h -#define _queues_h -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct st_queue { - byte **root; - void *first_cmp_arg; - uint elements; - uint max_elements; - uint offset_to_key; /* compare is done on element+offset */ - int max_at_top; /* Set if queue_top gives max */ - int (*compare)(void *, byte *,byte *); -} QUEUE; - -#define queue_top(queue) ((queue)->root[1]) -#define queue_element(queue,index) ((queue)->root[index+1]) -#define queue_end(queue) ((queue)->root[(queue)->elements]) -#define queue_replaced(queue) _downheap(queue,1) - -int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key, - pbool max_at_top, int (*compare)(void *,byte *, byte *), - void *first_cmp_arg); -int reinit_queue(QUEUE *queue,uint max_elements,uint offset_to_key, - pbool max_at_top, int (*compare)(void *,byte *, byte *), - void *first_cmp_arg); -void delete_queue(QUEUE *queue); -void queue_insert(QUEUE *queue,byte *element); -byte *queue_remove(QUEUE *queue,uint idx); -void _downheap(QUEUE *queue,uint idx); -#define is_queue_inited(queue) ((queue)->root != 0) - -#ifdef __cplusplus -} -#endif -#endif diff --git a/common/seperator-2.h b/common/seperator-2.h deleted file mode 100644 index a57b5617a..000000000 --- a/common/seperator-2.h +++ /dev/null @@ -1,233 +0,0 @@ -/* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which - are required to give you total support for your newly bought product; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -// This class will split up a string smartly at the div character (default is space) -// Seperator.arg[i] is a copy of the string chopped at the divs -// Seperator.argplus[i] is a pointer to the original string so it doesnt end at the div - -// Written by Quagmire -#ifndef SEPERATOR2_H -#define SEPERATOR2_H -#define arglen 400 -#define argnum 100 // Not including 0 -#define arglenz 100 -#define argnumz 10 // Not including 0 -#define arghlenz 400 -#define arghnumz 2048 // Not including 0 -#define arghlenza 100 -#define arghnumza 10 // Not including 0 - -class Seperator2 -{ -public: - Seperator2(char* messagez, char divz = '|') { - int iz; - for (iz=0; iz <= argnumz; iz++) { - memset(argz[iz], 0, sizeof(argz[iz])); - argplusz[iz] = argz[iz]; - } - - int lenz = strlen(messagez); - int az = 0, sz = 0, lz = 0; - bool inargz = (!(messagez[0] == divz)); - argplusz[0] = messagez; - for (iz=0; iz <= lenz; iz++) { - if (inargz) { - if (messagez[iz] == divz) { - lz = iz-sz; - if (lz >= (arglenz-1)) - lz = (arglenz-1); - memcpy(argz[az], argplusz[az], lz); - memset(&argz[az][lz], 0, 1); - az++; - inargz = false; - } - } - else { - sz = iz; - argplusz[az] = &messagez[iz]; - if (!(messagez[iz] == divz)) { - inargz = true; - } - } - if (az > argnumz) - break; - } - if (inargz) - memcpy(argz[az], argplusz[az], (iz-sz) - 1); - } - ~Seperator2() {} - char argz[argnumz+1][arglenz]; - char* argplusz[argnumz+1]; - bool IsNumberz(int numz) { - bool SeenDecz = false; - int lenz = strlen(argz[numz]); - if (lenz == 0) { - return false; - } - int iz; - for (iz = 0; iz < lenz; iz++) { - if (argz[numz][iz] < '0' || argz[numz][iz] > '9') { - if (argz[numz][iz] == '.' && !SeenDecz) { - SeenDecz = true; - } - else if (iz == 0 && (argz[numz][iz] == '-' || argz[numz][iz] == '+') && !argz[numz][iz+1] == 0) { - // this is ok, do nothin - } - else { - return false; - } - } - } - return true; - } -}; - -class Seperator3 -{ -public: - Seperator3(char* messagez, char divz = 10) { - int iz; - for (iz=0; iz <= arghnumz; iz++) { - memset(arghz[iz], 0, sizeof(arghz[iz])); - arghplusz[iz] = arghz[iz]; - } - - int lenz = strlen(messagez); - int az = 0, sz = 0, lz = 0; - bool inarghz = (!(messagez[0] == divz)); - arghplusz[0] = messagez; - for (iz=0; iz <= lenz; iz++) { - if (inarghz) { - if (messagez[iz] == divz) { - lz = iz-sz; - if (lz >= (arghlenz-1)) - lz = (arghlenz-1); - memcpy(arghz[az], arghplusz[az], lz); - memset(&arghz[az][lz], 0, 1); - az++; - inarghz = false; - } - } - else { - sz = iz; - arghplusz[az] = &messagez[iz]; - if (!(messagez[iz] == divz)) { - inarghz = true; - } - } - if (az > arghnumz) - break; - } - if (inarghz) - memcpy(arghz[az], arghplusz[az], (iz-sz) - 1); - } - ~Seperator3() {} - char arghz[arghnumz+1][arghlenz]; - char* arghplusz[arghnumz+1]; - bool IsNumberz(int numz) { - bool SeenDecz = false; - int lenz = strlen(arghz[numz]); - if (lenz == 0) { - return false; - } - int iz; - for (iz = 0; iz < lenz; iz++) { - if (arghz[numz][iz] < '0' || arghz[numz][iz] > '9') { - if (arghz[numz][iz] == '.' && !SeenDecz) { - SeenDecz = true; - } - else if (iz == 0 && (arghz[numz][iz] == '-' || arghz[numz][iz] == '+') && !arghz[numz][iz+1] == 0) { - // this is ok, do nothin - } - else { - return false; - } - } - } - return true; - } -}; - -class Seperator4 -{ -public: - Seperator4(char* messageza, char divza = ':') { - int iza; - for (iza=0; iza <= arghnumza; iza++) { - memset(arghza[iza], 0, sizeof(arghza[iza])); - arghplusza[iza] = arghza[iza]; - } - - int lenza = strlen(messageza); - int aza = 0, sza = 0, lza = 0; - bool inarghza = (!(messageza[0] == divza)); - arghplusza[0] = messageza; - for (iza=0; iza <= lenza; iza++) { - if (inarghza) { - if (messageza[iza] == divza) { - lza = iza-sza; - if (lza >= (arghlenza-1)) - lza = (arghlenza-1); - memcpy(arghza[aza], arghplusza[aza], lza); - memset(&arghza[aza][lza], 0, 1); - aza++; - inarghza = false; - } - } - else { - sza = iza; - arghplusza[aza] = &messageza[iza]; - if (!(messageza[iza] == divza)) { - inarghza = true; - } - } - if (aza > arghnumza) - break; - } - if (inarghza) - memcpy(arghza[aza], arghplusza[aza], (iza-sza) - 1); - } - ~Seperator4() {} - char arghza[arghnumza+1][arghlenza]; - char* arghplusza[arghnumza+1]; - bool IsNumberza(int numza) { - bool SeenDecza = false; - int lenza = strlen(arghza[numza]); - if (lenza == 0) { - return false; - } - int iza; - for (iza = 0; iza < lenza; iza++) { - if (arghza[numza][iza] < '0' || arghza[numza][iza] > '9') { - if (arghza[numza][iza] == '.' && !SeenDecza) { - SeenDecza = true; - } - else if (iza == 0 && (arghza[numza][iza] == '-' || arghza[numza][iza] == '+') && !arghza[numza][iza+1] == 0) { - // this is ok, do nothin - } - else { - return false; - } - } - } - return true; - } -}; - - -#endif diff --git a/common/string_util.cpp b/common/string_util.cpp index 63da1b08c..eb1f333f0 100644 --- a/common/string_util.cpp +++ b/common/string_util.cpp @@ -44,26 +44,8 @@ const std::string vStringFormat(const char* format, va_list args) int characters_used = vsnprintf(nullptr, 0, format, tmpargs); va_end(tmpargs); - if (characters_used < 0) { - // Looks like we have an invalid format string. - // return empty string. - return ""; - } - 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); - output.resize(characters_used); - - 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, return empty string; - return ""; - } - return std::move(output); - } - else { + // Looks like we have a valid format string. + if (characters_used > 0) { output.resize(characters_used + 1); va_copy(tmpargs,args); @@ -72,13 +54,12 @@ const std::string vStringFormat(const char* format, va_list args) output.resize(characters_used); - 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, return empty string; - return ""; - } - return std::move(output); + // We shouldn't have a format error by this point, but I can't imagine what error we + // could have by this point. Still, return empty string; + if (characters_used < 0) + output.clear(); } + return output; } const std::string StringFormat(const char* format, ...) @@ -87,7 +68,7 @@ const std::string StringFormat(const char* format, ...) va_start(args, format); std::string output = vStringFormat(format,args); va_end(args); - return std::move(output); + return output; } @@ -426,4 +407,4 @@ bool isAlphaNumeric(const char *text) } return true; -} \ No newline at end of file +} diff --git a/common/win_getopt.cpp b/common/win_getopt.cpp deleted file mode 100644 index 59e6b7079..000000000 --- a/common/win_getopt.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 1987, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* based on @(#)getopt.c 8.1 (Berkeley) 6/4/93 */ - -#ifndef __STDC__ -#define const -#endif -#include -#include -#include -#include "win_getopt.h" - -/* - * get option letter from argument vector - */ -int opterr = 1, /* if error message should be printed */ - optind = 1, /* index into parent argv vector */ - optopt, /* character checked for validity */ - optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ - -#define BADCH (int)'?' -#define BADARG (int)':' -#define EMSG "" - -int getopt(int nargc, char * const *nargv, const char *ostr) -{ - static char *place = EMSG; /* option letter processing */ - register char *oli; /* option letter list index */ - char *p; - - if (optreset || !*place) { /* update scanning pointer */ - optreset = 0; - if (optind >= nargc || *(place = nargv[optind]) != '-') { - place = EMSG; - return(-1); - } - if (place[1] && *++place == '-') { /* found "--" */ - ++optind; - place = EMSG; - return(-1); - } - } /* option letter okay? */ - if ((optopt = (int)*place++) == (int)':' || - !(oli = strchr(ostr, optopt))) { - /* - * if the user didn't specify '-' as an option, - * assume it means EOF. - */ - if (optopt == (int)'-') - return(-1); - if (!*place) - ++optind; - if (opterr && *ostr != ':') { - if (!(p = strrchr(*nargv, '/'))) - p = *nargv; - else - ++p; - (void)fprintf(stderr, "%s: illegal option -- %c\n", - p, optopt); - } - return(BADCH); - } - if (*++oli != ':') { /* don't need argument */ - optarg = NULL; - if (!*place) - ++optind; - } - else { /* need an argument */ - if (*place) /* no white space */ - optarg = place; - else if (nargc <= ++optind) { /* no arg */ - place = EMSG; - if (!(p = strrchr(*nargv, '/'))) - p = *nargv; - else - ++p; - if (*ostr == ':') - return(BADARG); - if (opterr) - (void)fprintf(stderr, - "%s: option requires an argument -- %c\n", - p, optopt); - return(BADCH); - } - else /* white space */ - optarg = nargv[optind]; - place = EMSG; - ++optind; - } - return(optopt); /* dump back option letter */ -} - diff --git a/common/win_getopt.h b/common/win_getopt.h deleted file mode 100644 index 737e476a7..000000000 --- a/common/win_getopt.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef WIN_GETOPT_H -#define WIN_GETOPT_H - -#ifdef WIN32 - -#ifdef __cplusplus -extern "C" { -#endif - -extern int opterr, /* if error message should be printed */ - optind, /* index into parent argv vector */ - optopt, /* character checked for validity */ - optreset; /* reset getopt */ -extern char *optarg; /* argument associated with option */ - -extern int getopt(int nargc, char * const *nargv, const char *ostr); - - -#ifdef __cplusplus -}; -#endif - -#endif -#endif