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/database_conversions.cpp b/common/database_conversions.cpp index 5287e74e3..8a938e8b5 100644 --- a/common/database_conversions.cpp +++ b/common/database_conversions.cpp @@ -462,31 +462,31 @@ bool Database::CheckDatabaseConversions() { CheckDatabaseConvertBotsPostPPDeblob(); CheckDatabaseConvertCorpseDeblob(); - /* Fetch Automatic Database Upgrade Script */ - // if (!std::ifstream("db_update.pl")){ - std::cout << "Pulling down automatic database upgrade script...\n" << std::endl; + /* Fetch Automatic Upgrade Script */ + if (!std::ifstream("eqemu_update.pl")){ + std::cout << "Pulling down automatic database upgrade script..." << std::endl; #ifdef _WIN32 - system("perl -MLWP::UserAgent -e \"require LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $response = $ua->get('https://raw.githubusercontent.com/EQEmu/Server/master/utils/scripts/db_update.pl'); if ($response->is_success){ open(FILE, '> db_update.pl'); print FILE $response->decoded_content; close(FILE); }\""); + system("perl -MLWP::UserAgent -e \"require LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $response = $ua->get('https://raw.githubusercontent.com/EQEmu/Server/master/utils/scripts/eqemu_update.pl'); if ($response->is_success){ open(FILE, '> eqemu_update.pl'); print FILE $response->decoded_content; close(FILE); }\""); #else - system("wget -O db_update.pl https://raw.githubusercontent.com/EQEmu/Server/master/utils/scripts/db_update.pl"); + system("wget --no-check-certificate -O eqemu_update.pl https://raw.githubusercontent.com/EQEmu/Server/master/utils/scripts/eqemu_update.pl"); #endif - // } + } /* - Automatic Database Upgrade Script - Script: db_update.pl V 1 - the number that world passes to the script will + Automatic (Database) Upgrade Script + Script: eqemu_update.pl V 1 - the number that world passes to the script will force the script to check for a newer version to update itself with - db_update.pl ran_from_world - won't bring up a menu if your database versions match - db_update.pl - ran standalone will bring up a menu prompt + eqemu_update.pl ran_from_world - won't bring up a menu if your database versions match + eqemu_update.pl - ran standalone will bring up a menu prompt */ /* Check for a new version of this script, the arg passed would have to be higher than the copy they have downloaded locally and they will re fetch */ - system("perl db_update.pl V 1"); + system("perl eqemu_update.pl V 2"); /* Run Automatic Database Upgrade Script */ - system("perl db_update.pl ran_from_world"); + system("perl eqemu_update.pl ran_from_world"); return true; } diff --git a/common/database_instances.cpp b/common/database_instances.cpp index 8ee16bfa2..5350d71f9 100644 --- a/common/database_instances.cpp +++ b/common/database_instances.cpp @@ -529,7 +529,7 @@ void Database::FlagInstanceByRaidLeader(uint32 zone, int16 version, uint32 chari void Database::GetCharactersInInstance(uint16 instance_id, std::list &charid_list) { - std::string query = StringFormat("SELECT `charid` FROM `instance_list_playe`r WHERE `id` = %u", instance_id); + std::string query = StringFormat("SELECT `charid` FROM `instance_list_player` WHERE `id` = %u", instance_id); auto results = QueryDatabase(query); if (!results.Success()) 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 diff --git a/utils/scripts/db_update.pl b/utils/scripts/eqemu_update.pl similarity index 95% rename from utils/scripts/db_update.pl rename to utils/scripts/eqemu_update.pl index 1cb0f46e8..21ef05b73 100644 --- a/utils/scripts/db_update.pl +++ b/utils/scripts/eqemu_update.pl @@ -1,22 +1,31 @@ #!/usr/bin/perl ########################################################### -#::: Automatic Database Upgrade Script +#::: Automatic (Database) Upgrade Script #::: Author: Akkadius #::: Purpose: To upgrade databases with ease and maintain versioning ########################################################### +$menu_displayed = 0; + +use Config; +$console_output .= " Operating System is: $Config{osname}\n"; +if($Config{osname}=~/linux/i){ $OS = "Linux"; } +if($Config{osname}=~/Win|MS/i){ $OS = "Windows"; } #::: If current version is less than what world is reporting, then download a new one... -$current_version = 1; +$current_version = 2; + if($ARGV[0] eq "V"){ if($ARGV[1] > $current_version){ - print "Retrieving latest database manifest...\n"; - GetRemoteFile("https://raw.githubusercontent.com/EQEmu/Server/master/utils/scripts/db_update.pl", "db_update.pl"); + print "eqemu_update.pl Automatic Database Upgrade Needs updating...\n"; + print " Current version: " . $current_version . "\n"; + print " New version: " . $ARGV[1] . "\n"; + GetRemoteFile("https://raw.githubusercontent.com/EQEmu/Server/master/utils/scripts/eqemu_update.pl", "eqemu_update.pl"); exit; } else{ - print "No update necessary \n"; + print "[Upgrade Script] No script update necessary \n"; } exit; } @@ -43,15 +52,10 @@ while() { $console_output = "============================================================ - EQEmu: Automatic Database Upgrade Check + EQEmu: Automatic Upgrade Check ============================================================ "; -use Config; -$console_output .= " Operating System is: $Config{osname}\n"; -if($Config{osname}=~/linux/i){ $OS = "Linux"; } -if($Config{osname}=~/Win|MS/i){ $OS = "Windows"; } - if($OS eq "Windows"){ $has_mysql_path = `echo %PATH%`; if($has_mysql_path=~/MySQL|MariaDB/i){ @@ -127,7 +131,7 @@ print " Binary Database Version: (" . $bin_db_ver . ")\n"; print " Local Database Version: (" . $local_db_ver . ")\n\n"; #::: If World ran this script, and our version is up to date, continue... -if($bin_db_ver == $local_db_ver && $ARGV[0] eq "ran_from_world"){ +if($bin_db_ver <= $local_db_ver && $ARGV[0] eq "ran_from_world"){ print " Database up to Date: Continuing World Bootup...\n"; print "============================================================\n"; exit; @@ -167,6 +171,11 @@ sub ShowMenuPrompt { next; } print MenuOptions(), '> '; + $menu_displayed++; + if($menu_displayed > 50){ + print "Safety: Menu looping too many times, exiting...\n"; + exit; + } } my $choice = <>; @@ -188,7 +197,7 @@ sub ShowMenuPrompt { } } -sub MenuOptions { +sub MenuOptions { if(@total_updates){ $option[3] = "Run pending REQUIRED updates... (" . scalar (@total_updates) . ")"; } @@ -280,7 +289,7 @@ sub GetRemoteFile{ } if($OS eq "Linux"){ #::: wget -O db_update/db_update_manifest.txt https://raw.githubusercontent.com/EQEmu/Server/master/utils/sql/db_update_manifest.txt - $wget = `wget --quiet -O $Dest_File $URL`; + $wget = `wget --no-check-certificate --quiet -O $Dest_File $URL`; print " URL: " . $URL . "\n"; print " Saved: " . $Dest_File . " \n"; if($wget=~/unable to resolve/i){ diff --git a/zone/command.cpp b/zone/command.cpp index ce6825a2e..8190bf9fc 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -282,6 +282,7 @@ int command_init(void) { command_add("motd", "[new motd] - Set message of the day", 150, command_motd) || command_add("movechar", "[charname] [zonename] - Move charname to zonename", 50, command_movechar) || command_add("myskills", "- Show details about your current skill levels", 0, command_myskills) || + command_add("mysqltest", "Akkadius MySQL Bench Test", 250, command_mysqltest) || command_add("mysql", "Mysql CLI, see 'help' for options.", 250, command_mysql) || command_add("mystats", "- Show details about you or your pet", 50, command_mystats) || command_add("name", "[newname] - Rename your player target", 150, command_name) || @@ -428,7 +429,7 @@ int command_init(void) { command_add("zsave", " - Saves zheader to the database", 80, command_zsave) || command_add("zsky", "[skytype] - Change zone sky type", 80, command_zsky) || command_add("zstats", "- Show info about zone header", 80, command_zstats) || - command_add("zunderworld", "[zcoord] - Sets the underworld using zcoord", 80, command_zunderworld) || + command_add("zunderworld", "[zcoord] - Sets the underworld using zcoord", 80, command_zunderworld) || command_add("zuwcoords", "[z coord] - Set underworld coord", 80, command_zuwcoords) ) { @@ -1778,10 +1779,12 @@ void command_itemtest(Client *c, const Seperator *sep) void command_gassign(Client *c, const Seperator *sep) { - if (sep->IsNumber(1) && c->GetTarget() && c->GetTarget()->IsNPC()) - database.AssignGrid(c, glm::vec2(c->GetTarget()->CastToNPC()->m_SpawnPoint), atoi(sep->arg[1])); + if (sep->IsNumber(1) && c->GetTarget() && c->GetTarget()->IsNPC() && c->GetTarget()->CastToNPC()->GetSpawnPointID() > 0) { + int spawn2id = c->GetTarget()->CastToNPC()->GetSpawnPointID(); + database.AssignGrid(c, atoi(sep->arg[1]), spawn2id); + } else - c->Message(0,"Usage: #gassign [num] - must have an npc target!"); + c->Message(0, "Usage: #gassign [num] - must have an npc target!"); } void command_ai(Client *c, const Seperator *sep) @@ -10541,3 +10544,17 @@ void command_logs(Client *c, const Seperator *sep){ c->Message(0, "--- #logs set [console|file|gmsay] - Sets log settings during the lifetime of the zone"); } } + +void command_mysqltest(Client *c, const Seperator *sep) +{ + clock_t t = std::clock(); /* Function timer start */ + if (sep->IsNumber(1)){ + uint32 i = 0; + t = std::clock(); + for (i = 0; i < atoi(sep->arg[1]); i++){ + std::string query = "SELECT * FROM `zone`"; + auto results = database.QueryDatabase(query); + } + } + Log.Out(Logs::General, Logs::Debug, "MySQL Test... Took %f seconds", ((float)(std::clock() - t)) / CLOCKS_PER_SEC); +} \ No newline at end of file diff --git a/zone/command.h b/zone/command.h index 4471cacb4..0560b8eff 100644 --- a/zone/command.h +++ b/zone/command.h @@ -323,6 +323,7 @@ void command_merchantcloseshop(Client *c, const Seperator *sep); void command_shownumhits(Client *c, const Seperator *sep); void command_tune(Client *c, const Seperator *sep); void command_logtest(Client *c, const Seperator *sep); +void command_mysqltest(Client *c, const Seperator *sep); void command_logs(Client *c, const Seperator *sep); #ifdef EQPROFILE diff --git a/zone/special_attacks.cpp b/zone/special_attacks.cpp index 749e5d256..4998150bd 100644 --- a/zone/special_attacks.cpp +++ b/zone/special_attacks.cpp @@ -999,7 +999,7 @@ void Mob::DoArcheryAttackDmg(Mob* other, const ItemInst* RangeWeapon, const Ite return;//Shouldn't reach this point, but just in case. //Weapon Proc - if(!RangeWeapon && other && !other->HasDied()) + if(RangeWeapon && other && !other->HasDied()) TryWeaponProc(RangeWeapon, other, MainRange); //Ammo Proc diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index 75054ef93..d3b85bf03 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -1033,76 +1033,21 @@ bool ZoneDatabase::GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist* return true; } -void ZoneDatabase::AssignGrid(Client *client, const glm::vec2& location, uint32 grid) -{ - int matches = 0, fuzzy = 0, spawn2id = 0; - - // looks like most of the stuff in spawn2 is straight integers - // so let's try that first - std::string query = StringFormat("SELECT id, x, y FROM spawn2 WHERE zone = '%s' AND x = %i AND y = %i", - zone->GetShortName(), (int)location.x, (int)location.y); +void ZoneDatabase::AssignGrid(Client *client, int grid, int spawn2id) { + std::string query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id); auto results = QueryDatabase(query); - if(!results.Success()) { + + if (!results.Success()) + return; + + if (results.RowsAffected() != 1) { return; } -// how much it's allowed to be off by -#define _GASSIGN_TOLERANCE 1.0 - if (results.RowCount() == 0) // try a fuzzy match if that didn't find it - { - query = StringFormat("SELECT id,x,y FROM spawn2 WHERE zone='%s' AND " - "ABS( ABS(x) - ABS(%f) ) < %f AND " - "ABS( ABS(y) - ABS(%f) ) < %f", - zone->GetShortName(), location.x, _GASSIGN_TOLERANCE, location.y, _GASSIGN_TOLERANCE); - results = QueryDatabase(query); - if (!results.Success()) { - return; - } - - fuzzy = 1; - matches = results.RowCount(); - } - - if (matches == 0) - { - client->Message(0, "ERROR: Unable to assign grid - can't find it in spawn2"); - return; - } - - if(matches > 1) - { - client->Message(0, "ERROR: Unable to assign grid - multiple spawn2 rows match"); - return; - } - - auto row = results.begin(); - - spawn2id = atoi(row[0]); - glm::vec2 dbLocation = glm::vec2(atof(row[1]), atof(row[2])); - - query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id); - results = QueryDatabase(query); - if (!results.Success()) { - return; - } - - if (results.RowsAffected() != 1) - { - client->Message(0, "ERROR: found spawn2 id %d but the update query failed", spawn2id); - return; - } - - if (!fuzzy) - { - client->Message(0, "Grid assign: spawn2 id = %d updated - exact match", spawn2id); - return; - } - - float difference = - sqrtf(pow(std::abs(location.x - dbLocation.x), 2) + pow(std::abs(location.y - dbLocation.y), 2)); - client->Message(0, "Grid assign: spawn2 id = %d updated - fuzzy match: deviation %f", spawn2id, difference); + client->Message(0, "Grid assign: spawn2 id = %d updated", spawn2id); } + /****************** * ModifyGrid - Either adds an empty grid, or removes a grid and all its waypoints, for a particular zone. * remove: TRUE if we are deleting the specified grid, FALSE if we are adding it diff --git a/zone/zonedb.h b/zone/zonedb.h index c605533bf..5c3ed3d0e 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -379,7 +379,7 @@ public: uint8 GetGridType(uint32 grid, uint32 zoneid); uint8 GetGridType2(uint32 grid, uint16 zoneid); bool GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist* wp); - void AssignGrid(Client *client, const glm::vec2& location, uint32 id); + void AssignGrid(Client *client, int grid, int spawn2id); int GetHighestGrid(uint32 zoneid); int GetHighestWaypoint(uint32 zoneid, uint32 gridid);