NPC Faction lists to new shared memory scheme

This commit is contained in:
KimLS
2013-02-23 13:45:19 -08:00
parent 8937c5be86
commit c31b2b65c1
47 changed files with 216 additions and 2459 deletions
+1 -4
View File
@@ -13,7 +13,6 @@ SET(common_sources
DBMemLeak.cpp
debug.cpp
emu_opcodes.cpp
EMuShareMem.cpp
EmuTCPConnection.cpp
EmuTCPServer.cpp
EQDB.cpp
@@ -54,7 +53,6 @@ SET(common_sources
rulesys.cpp
serverinfo.cpp
shareddb.cpp
SharedLibrary.cpp
spdat.cpp
StructStrategy.cpp
TCPConnection.cpp
@@ -108,7 +106,6 @@ SET(common_headers
deity.h
emu_opcodes.h
emu_oplist.h
EMuShareMem.h
EmuTCPConnection.h
EmuTCPServer.h
eq_constants.h
@@ -130,6 +127,7 @@ SET(common_headers
eqtime.h
errmsg.h
extprofile.h
faction.h
features.h
fixed_memory_hash_set.h
fixed_memory_variable_hash_set.h
@@ -169,7 +167,6 @@ SET(common_headers
serverinfo.h
servertalk.h
shareddb.h
SharedLibrary.h
skills.h
spdat.h
StructStrategy.h
-213
View File
@@ -1,213 +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
*/
#include "../common/debug.h"
#include <iostream>
using namespace std;
#include "../common/types.h"
#include "EMuShareMem.h"
#ifdef _WINDOWS
#define snprintf _snprintf
#if (_MSC_VER < 1500)
#define vsnprintf _vsnprintf
#endif
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#define EmuLibName "EMuShareMem"
#else
#define EmuLibName "libEMuShareMem.so"
#endif
LoadEMuShareMemDLL EMuShareMemDLL;
#ifndef WIN32
uint32 LoadEMuShareMemDLL::refCount = 0;
#endif
LoadEMuShareMemDLL::LoadEMuShareMemDLL() {
ClearFunc();
#ifndef WIN32
refCountU();
#endif
}
LoadEMuShareMemDLL::~LoadEMuShareMemDLL() {
#ifndef WIN32
if (refCountD() <= 0) {
#endif
Unload();
#ifndef WIN32
}
#endif
}
bool LoadEMuShareMemDLL::Load() {
if(loaded)
return(true);
if(!SharedLibrary::Load(EmuLibName))
return(false);
if (Loaded()) {
Items.GetItem = (DLLFUNC_GetItem) GetSym("GetItem");
Items.IterateItems = (DLLFUNC_IterateItems) GetSym("IterateItems");
Items.cbAddItem = (DLLFUNC_AddItem) GetSym("AddItem");
Items.DLLLoadItems = (DLLFUNC_DLLLoadItems) GetSym("DLLLoadItems");
Doors.GetDoor = (DLLFUNC_GetDoor) GetSym("GetDoor");
Doors.cbAddDoor = (DLLFUNC_AddDoor) GetSym("AddDoor");
Doors.DLLLoadDoors = (DLLFUNC_DLLLoadDoors) GetSym("DLLLoadDoors");
NPCFactionList.DLLLoadNPCFactionLists = (DLLFUNC_DLLLoadNPCFactionLists) GetSym("DLLLoadNPCFactionLists");
NPCFactionList.GetNPCFactionList = (DLLFUNC_GetNPCFactionList) GetSym("GetNPCFactionList");
NPCFactionList.cbAddNPCFactionList = (DLLFUNC_AddNPCFactionList) GetSym("AddNPCFactionList");
NPCFactionList.cbSetFaction = (DLLFUNC_SetFaction) GetSym("SetNPCFaction");
Loot.DLLLoadLoot = (DLLFUNC_DLLLoadLoot) GetSym("DLLLoadLoot");
Loot.cbAddLootTable = (DLLFUNC_AddLootTable) GetSym("AddLootTable");
Loot.cbAddLootDrop = (DLLFUNC_AddLootDrop) GetSym("AddLootDrop");
Loot.GetLootTable = (DLLFUNC_GetLootTable) GetSym("GetLootTable");
Loot.GetLootDrop = (DLLFUNC_GetLootDrop) GetSym("GetLootDrop");
if(Items.GetItem == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Items.GetItem");
return(false);
}
if(Items.IterateItems == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Items.IterateItems");
return(false);
}
if(Items.cbAddItem == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Items.cbAddItem");
return(false);
}
if(Items.DLLLoadItems == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Items.DLLLoadItems");
return(false);
}
if(Doors.GetDoor == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Doors.GetDoor");
return(false);
}
if(Doors.cbAddDoor == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Doors.cbAddDoor");
return(false);
}
if(Doors.DLLLoadDoors == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Doors.DLLLoadDoors");
return(false);
}
if(NPCFactionList.DLLLoadNPCFactionLists == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach NPCFactionList.DLLLoadNPCFactionLists");
return(false);
}
if(NPCFactionList.GetNPCFactionList == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach NPCFactionList.GetNPCFactionList");
return(false);
}
if(NPCFactionList.cbAddNPCFactionList == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach NPCFactionList.cbAddNPCFactionList");
return(false);
}
if(NPCFactionList.cbSetFaction == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach NPCFactionList.cbSetFaction");
return(false);
}
if(Loot.DLLLoadLoot == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Loot.DLLLoadLoot");
return(false);
}
if(Loot.cbAddLootTable == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Loot.cbAddLootTable");
return(false);
}
if(Loot.cbAddLootDrop == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Loot.cbAddLootDrop");
return(false);
}
if(Loot.GetLootTable == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Loot.GetLootTable");
return(false);
}
if(Loot.GetLootDrop == NULL) {
Unload();
LogFile->write(EQEMuLog::Error, "LoadEMuShareMemDLL::Load() failed to attach Loot.GetLootDrop");
return(false);
}
LogFile->write(EQEMuLog::Status, "%s loaded", EmuLibName);
loaded = true;
return true;
}
else {
LogFile->write(EQEMuLog::Error, "%s was not loaded, but did not report an error.", EmuLibName);
}
return false;
}
void LoadEMuShareMemDLL::Unload() {
ClearFunc();
SharedLibrary::Unload();
}
void LoadEMuShareMemDLL::ClearFunc() {
Items.GetItem = 0;
Items.IterateItems = 0;
Items.cbAddItem = 0;
Items.DLLLoadItems = 0;
Doors.GetDoor = 0;
Doors.cbAddDoor = 0;
Doors.DLLLoadDoors = 0;
NPCFactionList.DLLLoadNPCFactionLists = 0;
NPCFactionList.GetNPCFactionList = 0;
NPCFactionList.cbAddNPCFactionList = 0;
NPCFactionList.cbSetFaction = 0;
Loot.DLLLoadLoot = 0;
Loot.cbAddLootTable = 0;
Loot.cbAddLootDrop = 0;
Loot.GetLootTable = 0;
Loot.GetLootDrop = 0;
loaded = false;
}
-121
View File
@@ -1,121 +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 EMuShareMem_H
#define EMuShareMem_H
#ifdef _WINDOWS
#include <windows.h>
#else
#include "../common/unix.h"
#endif
#include "../common/eq_packet_structs.h"
#include "../zone/zonedump.h"
#include "../common/loottable.h"
#include "SharedLibrary.h"
////////////
// Items //
///////////
typedef bool(*CALLBACK_DBLoadItems)(int32, uint32);
typedef bool(*DLLFUNC_DLLLoadItems)(const CALLBACK_DBLoadItems, uint32, int32*, uint32*);
typedef const Item_Struct*(*DLLFUNC_GetItem)(uint32);
typedef const Item_Struct*(*DLLFUNC_IterateItems)(uint32*);
typedef bool(*DLLFUNC_AddItem)(uint32, const Item_Struct*);
struct ItemsDLLFunc_Struct {
DLLFUNC_DLLLoadItems DLLLoadItems;
DLLFUNC_GetItem GetItem;
DLLFUNC_IterateItems IterateItems;
DLLFUNC_AddItem cbAddItem;
};
////////////
// Doors ///
////////////
typedef bool(*CALLBACK_DBLoadDoors)(int32, uint32);
typedef bool(*DLLFUNC_DLLLoadDoors)(const CALLBACK_DBLoadDoors, uint32, int32*, uint32*);
typedef const Door*(*DLLFUNC_GetDoor)(uint32);
typedef bool(*DLLFUNC_AddDoor)(uint32, const Door*);
struct DoorsDLLFunc_Struct {
DLLFUNC_DLLLoadDoors DLLLoadDoors;
DLLFUNC_GetDoor GetDoor;
DLLFUNC_AddDoor cbAddDoor;
};
//////////////
// Factions //
//////////////
typedef bool(*CALLBACK_DBLoadNPCFactionLists)(int32, uint32);
typedef bool(*DLLFUNC_DLLLoadNPCFactionLists)(const CALLBACK_DBLoadNPCFactionLists, uint32, int32*, uint32*, uint8);
typedef const NPCFactionList*(*DLLFUNC_GetNPCFactionList)(uint32);
typedef bool(*DLLFUNC_AddNPCFactionList)(uint32, const NPCFactionList*);
typedef bool(*DLLFUNC_SetFaction)(uint32, uint32*, int32*, int8*, uint8*);
struct NPCFactionListDLLFunc_Struct {
DLLFUNC_DLLLoadNPCFactionLists DLLLoadNPCFactionLists;
DLLFUNC_GetNPCFactionList GetNPCFactionList;
DLLFUNC_AddNPCFactionList cbAddNPCFactionList;
DLLFUNC_SetFaction cbSetFaction;
};
////////////
// Loot //
///////////
typedef bool(*CALLBACK_DBLoadLoot)();
typedef bool(*DLLFUNC_DLLLoadLoot)(const CALLBACK_DBLoadLoot, uint32, uint32, uint32, uint32, uint32, uint32, uint32, uint32, uint32, uint32);
typedef bool(*DLLFUNC_AddLootTable)(uint32, const LootTable_Struct*);
typedef bool(*DLLFUNC_AddLootDrop)(uint32, const LootDrop_Struct*);
typedef const LootTable_Struct*(*DLLFUNC_GetLootTable)(uint32);
typedef const LootDrop_Struct*(*DLLFUNC_GetLootDrop)(uint32);
struct LootDLLFunc_Struct {
DLLFUNC_DLLLoadLoot DLLLoadLoot;
DLLFUNC_AddLootTable cbAddLootTable;
DLLFUNC_AddLootDrop cbAddLootDrop;
DLLFUNC_GetLootTable GetLootTable;
DLLFUNC_GetLootDrop GetLootDrop;
};
class LoadEMuShareMemDLL : public SharedLibrary {
public:
LoadEMuShareMemDLL();
~LoadEMuShareMemDLL();
bool Load();
void Unload();
ItemsDLLFunc_Struct Items;
DoorsDLLFunc_Struct Doors;
NPCFactionListDLLFunc_Struct NPCFactionList;
LootDLLFunc_Struct Loot;
private:
void ClearFunc();
bool loaded;
#ifdef _WINDOWS
#else
static uint32 refCount;
static uint32 refCountU() { return ++refCount; };
static uint32 refCountD() { return --refCount; };
#endif
};
#endif
-117
View File
@@ -1,117 +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
*/
#include "SharedLibrary.h"
#include <stdio.h>
#ifdef _WINDOWS
#define snprintf _snprintf
#if (_MSC_VER < 1500)
#define vsnprintf _vsnprintf
#endif
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#define EmuLibName "EMuShareMem"
#else
#define EmuLibName "libEMuShareMem.so"
#include "../common/unix.h"
#include <dlfcn.h>
#define GetProcAddress(a,b) dlsym(a,b)
#define LoadLibrary(a) dlopen(a, RTLD_NOW)
#define FreeLibrary(a) dlclose(a)
#define GetLastError() dlerror()
#endif
SharedLibrary::SharedLibrary() {
hDLL = NULL;
}
SharedLibrary::~SharedLibrary() {
Unload();
}
bool SharedLibrary::Load(const char *name)
{
#ifdef _WINDOWS
SetLastError(0);
#endif
hDLL = LoadLibrary(name);
if(!hDLL) {
const char *load_error = GetError();
fprintf(stderr, "[Error] Load Shared Library '%s' failed. Error=%s\n", name, load_error?load_error:"Null Return, no error");
return false;
}
#ifdef _WINDOWS
else { SetLastError(0); } // Clear the win9x error
#endif
return(true);
}
void SharedLibrary::Unload() {
if (hDLL != NULL) {
FreeLibrary(hDLL);
#ifndef WIN32
const char* error;
if ((error = GetError()) != NULL)
fprintf(stderr, "FreeLibrary() error = %s", error);
#endif
hDLL = NULL;
}
}
void *SharedLibrary::GetSym(const char *name) {
if (!Loaded())
return(NULL);
void *r = GetProcAddress(hDLL, name);
if(GetError() != NULL)
r = NULL;
return(r);
}
bool SharedLibrary::GetSym(const char *name, void **sym)
{
bool result=false;
if (Loaded()) {
*sym = GetProcAddress(hDLL, name);
result= (GetError() == NULL);
}
return result;
}
const char *SharedLibrary::GetError()
{
#ifdef _WINDOWS
//not thread safe, dont care.
static char ErrBuf[128];
unsigned long err = GetLastError();
if(err == 0)
return(NULL);
sprintf(ErrBuf, "Error #%lu", (unsigned long)err);
return(ErrBuf);
#else
return GetLastError();
#endif
}
-49
View File
@@ -1,49 +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 _SHAREDLIBRARY_H
#define _SHAREDLIBRARY_H
#ifdef _WINDOWS
#include <windows.h>
#endif
class SharedLibrary {
public:
SharedLibrary();
virtual ~SharedLibrary();
//two call styles for GetSym, one returns bool, other NULL for fail
bool GetSym(const char *name, void **sym);
void *GetSym(const char *name);
const char *GetError();
virtual bool Load(const char *file);
virtual void Unload();
inline bool Loaded() { return (hDLL != 0); }
protected:
#ifdef _WINDOWS
HINSTANCE hDLL;
#else
void* hDLL;
#endif
};
#endif
+76
View File
@@ -0,0 +1,76 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2013 EQEMu Development Team (http://eqemu.org)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
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 _EQEMU_FACTION_H
#define _EQEMU_FACTION_H
#include "types.h"
#include "features.h"
#include <map>
#include <string>
enum FACTION_VALUE {
FACTION_ALLY = 1,
FACTION_WARMLY = 2,
FACTION_KINDLY = 3,
FACTION_AMIABLE = 4,
FACTION_INDIFFERENT = 5,
FACTION_APPREHENSIVE = 6,
FACTION_DUBIOUS = 7,
FACTION_THREATENLY = 8,
FACTION_SCOWLS = 9
};
struct NPCFactionList {
uint32 id;
uint32 primaryfaction;
bool assistprimaryfaction;
uint32 factionid[MAX_NPC_FACTIONS];
int32 factionvalue[MAX_NPC_FACTIONS];
int8 factionnpcvalue[MAX_NPC_FACTIONS];
uint8 factiontemp[MAX_NPC_FACTIONS];
};
struct FactionMods
{
int32 base;
int32 class_mod;
int32 race_mod;
int32 deity_mod;
};
struct Faction {
int32 id;
std::map<std::string, int16> mods;
int16 base;
char name[50];
};
typedef map<uint32, int16> faction_map;
struct NPCFaction
{
uint32 factionID;
int32 value_mod;
int8 npc_value;
uint8 temp;
};
const char *FactionValueToString(FACTION_VALUE fv);
char* BuildFactionMessage(int32 tmpvalue, int32 faction_id, int32 totalvalue, uint8 temp);
FACTION_VALUE CalculateFaction(FactionMods* fm, int32 tmpCharacter_value);
#endif
-1
View File
@@ -186,7 +186,6 @@ namespace EQEmu {
void MemoryMappedFile::ZeroFile() {
memset(reinterpret_cast<void*>(memory_), 0, sizeof(shared_memory_struct));
memset(memory_->data, 0, size_);
memory_->loaded = false;
memory_->size = size_;
}
} // EQEmu
+1 -8
View File
@@ -35,7 +35,6 @@ namespace EQEmu {
//! Underlying data structure.
struct shared_memory_struct {
bool loaded;
uint32 size;
unsigned char data[1];
};
@@ -66,13 +65,7 @@ namespace EQEmu {
//! Get Size Function
inline uint32 Size() const { return memory_->size; }
//! Returns whether this memory is loaded or not
inline bool Loaded() const { return memory_->loaded; }
//! Sets the memory to be loaded
inline void SetLoaded() { memory_->loaded = true; }
//! Zeros all the memory in the file, and set it to be unloaded
void ZeroFile();
private:
-83
View File
@@ -23,19 +23,10 @@
#include <cstdlib>
#include <cstring>
#ifdef SHARED_OPCODES
#include "EMuShareMem.h"
extern LoadEMuShareMemDLL EMuShareMemDLL;
#endif
#include <map>
#include <string>
using namespace std;
//#define DEBUG_TRANSLATE
OpcodeManager::OpcodeManager() {
loaded = false;
}
@@ -141,80 +132,6 @@ EmuOpcode OpcodeManager::NameSearch(const char *name) {
return(OP_Unknown);
}
#ifdef SHARED_OPCODES
bool SharedOpcodeManager::LoadOpcodes(const char *filename, bool report_errors) {
if (!EMuShareMemDLL.Load()) {
printf("Unable to load EMuShareMem for opcodes.\n");
return false;
}
MOpcodes.lock();
loaded = true;
bool ret = EMuShareMemDLL.Opcodes.DLLLoadOpcodes(DLLLoadOpcodesCallback, sizeof(uint16), MAX_EQ_OPCODE, _maxEmuOpcode, filename);
MOpcodes.unlock();
return ret;
}
bool SharedOpcodeManager::DLLLoadOpcodesCallback(const char *filename) {
SharedMemStrategy s;
return(LoadOpcodesFile(filename, &s, true));
}
bool SharedOpcodeManager::ReloadOpcodes(const char *filename, bool report_errors) {
/* if(!loaded)
return(LoadOpcodes(filename));
MOpcodes.lock();
EMuShareMemDLL.Opcodes.ClearEQOpcodes();
SharedMemStrategy s;
bool ret = LoadOpcodesFile(filename, &s);
MOpcodes.unlock();
return(ret);*/
//shared memory is read only right now, cant reload it
return(false);
}
uint16 SharedOpcodeManager::EmuToEQ(const EmuOpcode emu_op) {
//opcode is checked for validity in GetEQOpcode
uint16 res;
MOpcodes.lock();
res = EMuShareMemDLL.Opcodes.GetEQOpcode((uint16)emu_op);
MOpcodes.unlock();
#ifdef DEBUG_TRANSLATE
fprintf(stderr, "S Translate Emu %s (%d) to EQ 0x%.4x\n", OpcodeNames[emu_op], emu_op, res);
#endif
return(res);
}
EmuOpcode SharedOpcodeManager::EQToEmu(const uint16 eq_op) {
//opcode is checked for validity in GetEmuOpcode
//Disabled since current live EQ uses the entire uint16 bitspace for opcodes
// if(eq_op > MAX_EQ_OPCODE)
// return(OP_Unknown);
uint16 res;
MOpcodes.lock();
res = EMuShareMemDLL.Opcodes.GetEmuOpcode(eq_op);
MOpcodes.unlock();
#ifdef DEBUG_TRANSLATE
fprintf(stderr, "S Translate EQ 0x%.4x to Emu %s (%d)\n", eq_op, OpcodeNames[res], res);
#endif
return((EmuOpcode)res);
}
void SharedOpcodeManager::SharedMemStrategy::Set(EmuOpcode emu_op, uint16 eq_op) {
EMuShareMemDLL.Opcodes.SetOpcodePair((uint16)emu_op, eq_op);
}
#endif
RegularOpcodeManager::RegularOpcodeManager()
: MutableOpcodeManager()
{
+124 -183
View File
@@ -4,7 +4,6 @@
#include <cstring>
#include <cstdlib>
#include "Item.h"
#include "EMuShareMem.h"
#include "classes.h"
#include "rulesys.h"
#include "seperator.h"
@@ -15,20 +14,22 @@
#include "memory_mapped_file.h"
#include "ipc_mutex.h"
#include "eqemu_exception.h"
#include "loottable.h"
#include "faction.h"
#include "features.h"
using namespace std;
extern LoadEMuShareMemDLL EMuShareMemDLL;
SharedDatabase::SharedDatabase()
: Database(), skill_caps_mmf(NULL), items_mmf(NULL), items_hash(NULL), faction_mmf(NULL),
: Database(), skill_caps_mmf(NULL), items_mmf(NULL), items_hash(NULL), faction_mmf(NULL), faction_hash(NULL),
loot_table_mmf(NULL), loot_drop_mmf(NULL), loot_table_hash(NULL), loot_drop_hash(NULL)
{
}
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(NULL), items_mmf(NULL), items_hash(NULL),
faction_mmf(NULL), loot_table_mmf(NULL), loot_drop_mmf(NULL), loot_table_hash(NULL), loot_drop_hash(NULL)
faction_mmf(NULL), faction_hash(NULL), loot_table_mmf(NULL), loot_drop_mmf(NULL), loot_table_hash(NULL),
loot_drop_hash(NULL)
{
}
@@ -37,6 +38,7 @@ SharedDatabase::~SharedDatabase() {
safe_delete(items_mmf);
safe_delete(items_hash);
safe_delete(faction_mmf);
safe_delete(faction_hash);
safe_delete(loot_table_mmf);
safe_delete(loot_drop_mmf);
safe_delete(loot_table_hash);
@@ -715,31 +717,26 @@ bool SharedDatabase::GetInventory(uint32 account_id, char* name, Inventory* inv)
}
int32 SharedDatabase::GetItemsCount(uint32* max_id) {
void SharedDatabase::GetItemsCount(int32 &item_count, uint32 &max_id) {
char errbuf[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result;
MYSQL_ROW row;
int32 ret = -1;
item_count = -1;
max_id = 0;
char query[] = "SELECT MAX(id), count(*) FROM items";
if (RunQuery(query, static_cast<uint32>(strlen(query)), errbuf, &result)) {
row = mysql_fetch_row(result);
if (row != NULL && row[1] != 0) {
ret = atoi(row[1]);
if (max_id) {
if (row[0])
*max_id = atoi(row[0]);
else
*max_id = 0;
}
item_count = atoi(row[1]);
if(row[0])
max_id = atoi(row[0]);
}
mysql_free_result(result);
}
else {
LogFile->write(EQEMuLog::Error, "Error in GetItemsCount '%s': '%s'", query, errbuf);
}
return ret;
}
bool SharedDatabase::LoadItems() {
@@ -752,8 +749,9 @@ bool SharedDatabase::LoadItems() {
mutex.Lock();
items_mmf = new EQEmu::MemoryMappedFile("shared/items");
int32 items = -1;
uint32 max_item = 0;
int32 items = GetItemsCount(&max_item);
GetItemsCount(items, max_item);
if(items == -1) {
EQ_EXCEPT("SharedDatabase", "Database returned no result");
}
@@ -1085,151 +1083,120 @@ string SharedDatabase::GetBook(const char *txtfile)
}
}
void SharedDatabase::GetFactionListInfo(uint32 &list_count, uint32 &max_lists) {
list_count = 0;
max_lists = 0;
const char *query = "SELECT COUNT(*), MAX(id) FROM npc_faction";
char errbuf[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result;
MYSQL_ROW row;
bool SharedDatabase::extDBLoadNPCFactionLists(int32 iNPCFactionListCount, uint32 iMaxNPCFactionListID) {
return false;
//return s_usedb->DBLoadNPCFactionLists(iNPCFactionListCount, iMaxNPCFactionListID);
if(RunQuery(query, strlen(query), errbuf, &result)) {
if(row = mysql_fetch_row(result)) {
list_count = static_cast<uint32>(atoul(row[0]));
max_lists = static_cast<uint32>(atoul(row[1]));
}
mysql_free_result(result);
} else {
LogFile->write(EQEMuLog::Error, "Error getting npc faction info from database: %s, %s", query, errbuf);
}
}
const NPCFactionList* SharedDatabase::GetNPCFactionEntry(uint32 id) {
return NULL;
//return EMuShareMemDLL.NPCFactionList.GetNPCFactionList(id);
if(!faction_hash) {
return NULL;
}
if(faction_hash->exists(id)) {
return &(faction_hash->at(id));
}
return NULL;
}
void SharedDatabase::LoadNPCFactionLists(void *data, uint32 size, uint32 list_count, uint32 max_lists) {
EQEmu::FixedMemoryHashSet<NPCFactionList> hash(reinterpret_cast<uint8*>(data), size, list_count, max_lists);
const char *query = "SELECT npc_faction.id, npc_faction.primaryfaction, npc_faction.ignore_primary_assist, "
"npc_faction_entries.faction_id, npc_faction_entries.value, npc_faction_entries.npc_value, npc_faction_entries.temp "
"FROM npc_faction JOIN npc_faction_entries ON npc_faction.id = npc_faction_entries.npc_faction_id ORDER BY "
"npc_faction.id;";
char errbuf[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result;
MYSQL_ROW row;
NPCFactionList faction;
if(RunQuery(query, strlen(query), errbuf, &result)) {
uint32 current_id = 0;
uint32 current_entry = 0;
while(row = mysql_fetch_row(result)) {
uint32 id = static_cast<uint32>(atoul(row[0]));
if(id != current_id) {
if(current_id != 0) {
hash.insert(current_id, faction);
}
memset(&faction, 0, sizeof(faction));
current_entry = 0;
current_id = id;
faction.id = id;
faction.primaryfaction = static_cast<uint32>(atoul(row[1]));
faction.assistprimaryfaction = (atoi(row[2]) == 0);
}
if(current_entry >= MAX_NPC_FACTIONS) {
continue;
}
faction.factionid[current_entry] = static_cast<uint32>(atoul(row[3]));
faction.factionvalue[current_entry] = static_cast<int32>(atoi(row[4]));
faction.factionnpcvalue[current_entry] = static_cast<int8>(atoi(row[5]));
faction.factiontemp[current_entry] = static_cast<uint8>(atoi(row[6]));
}
if(current_id != 0) {
hash.insert(current_id, faction);
}
mysql_free_result(result);
} else {
LogFile->write(EQEMuLog::Error, "Error getting npc faction info from database: %s, %s", query, errbuf);
}
}
bool SharedDatabase::LoadNPCFactionLists() {
//if (!EMuShareMemDLL.Load())
// return false;
//int32 tmp = -1;
//uint32 tmp_npcfactionlist_max;
//tmp = GetNPCFactionListsCount(&tmp_npcfactionlist_max);
//if (tmp < 0) {
// cout << "Error: SharedDatabase::LoadNPCFactionLists-ShareMem: GetNPCFactionListsCount() returned < 0" << endl;
// return false;
//}
//bool ret = EMuShareMemDLL.NPCFactionList.DLLLoadNPCFactionLists(&extDBLoadNPCFactionLists, sizeof(NPCFactionList), &tmp, &tmp_npcfactionlist_max, MAX_NPC_FACTIONS);
//return ret;
if(faction_hash) {
return true;
}
try {
EQEmu::IPCMutex mutex("faction");
mutex.Lock();
faction_mmf = new EQEmu::MemoryMappedFile("shared/faction");
uint32 list_count = 0;
uint32 max_lists = 0;
GetFactionListInfo(list_count, max_lists);
if(list_count == 0) {
EQ_EXCEPT("SharedDatabase", "Database returned no result");
}
uint32 size = static_cast<uint32>(EQEmu::FixedMemoryHashSet<NPCFactionList>::estimated_size(
list_count, max_lists));
if(faction_mmf->Size() != size) {
EQ_EXCEPT("SharedDatabase", "Couldn't load npc factions because faction_mmf->Size() != size");
}
faction_hash = new EQEmu::FixedMemoryHashSet<NPCFactionList>(reinterpret_cast<uint8*>(faction_mmf->Get()), size);
mutex.Unlock();
} catch(std::exception& ex) {
LogFile->write(EQEMuLog::Error, "Error Loading npc factions: %s", ex.what());
return false;
}
return true;
}
bool SharedDatabase::DBLoadNPCFactionLists(int32 iNPCFactionListCount, uint32 iMaxNPCFactionListID) {
_CP(Database_DBLoadNPCFactionLists);
LogFile->write(EQEMuLog::Status, "Loading NPC Faction Lists from database...");
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 npc_faction");
if (RunQuery(query, strlen(query), errbuf, &result)) {
safe_delete_array(query);
row = mysql_fetch_row(result);
if (row && row[0]) {
if ((uint32)atoi(row[0]) > iMaxNPCFactionListID) {
cout << "Error: Insufficient shared memory to load NPC Faction Lists." << endl;
cout << "Max(id): " << atoi(row[0]) << ", iMaxNPCFactionListID: " << iMaxNPCFactionListID << endl;
cout << "Fix this by increasing the MMF_MAX_NPCFactionList_ID define statement" << endl;
mysql_free_result(result);
return false;
}
if (atoi(row[1]) != iNPCFactionListCount) {
cout << "Error: number of NPCFactionLists in memshare doesnt match database." << endl;
cout << "Count(*): " << atoi(row[1]) << ", iNPCFactionListCount: " << iNPCFactionListCount << endl;
mysql_free_result(result);
return false;
}
//npcfactionlist_max = atoi(row[0]);
mysql_free_result(result);
NPCFactionList tmpnfl;
if (RunQuery(query, MakeAnyLenString(&query, "SELECT id, primaryfaction, ignore_primary_assist from npc_faction"), errbuf, &result)) {
safe_delete_array(query);
while((row = mysql_fetch_row(result))) {
memset(&tmpnfl, 0, sizeof(NPCFactionList));
tmpnfl.id = atoi(row[0]);
tmpnfl.primaryfaction = atoi(row[1]);
//if we have ignore_primary_assist set to non-zero then we will not assist our own faction
//else we will assist (this is the default)
tmpnfl.assistprimaryfaction = (atoi(row[2]) == 0) ? true : false;
if (!EMuShareMemDLL.NPCFactionList.cbAddNPCFactionList(tmpnfl.id, &tmpnfl)) {
mysql_free_result(result);
cout << "Error: SharedDatabase::DBLoadNPCFactionLists: !EMuShareMemDLL.NPCFactionList.cbAddNPCFactionList" << endl;
return false;
}
Sleep(0);
}
mysql_free_result(result);
}
else {
cerr << "Error in DBLoadNPCFactionLists query2 '" << query << "' " << errbuf << endl;
safe_delete_array(query);
return false;
}
if (RunQuery(query, MakeAnyLenString(&query, "SELECT npc_faction_id, faction_id, value, npc_value, temp FROM npc_faction_entries order by npc_faction_id"), errbuf, &result)) {
safe_delete_array(query);
int8 i = 0;
uint32 curflid = 0;
uint32 tmpflid = 0;
uint32 tmpfactionid[MAX_NPC_FACTIONS];
int32 tmpfactionvalue[MAX_NPC_FACTIONS];
int8 tmpfactionnpcvalue[MAX_NPC_FACTIONS];
uint8 tmpfactiontemp[MAX_NPC_FACTIONS];
memset(tmpfactionid, 0, sizeof(tmpfactionid));
memset(tmpfactionvalue, 0, sizeof(tmpfactionvalue));
memset(tmpfactionnpcvalue, 0, sizeof(tmpfactionnpcvalue));
memset(tmpfactiontemp, 0, sizeof(tmpfactiontemp));
while((row = mysql_fetch_row(result))) {
tmpflid = atoi(row[0]);
if (curflid != tmpflid && curflid != 0) {
if (!EMuShareMemDLL.NPCFactionList.cbSetFaction(curflid, tmpfactionid, tmpfactionvalue, tmpfactionnpcvalue, tmpfactiontemp)) {
mysql_free_result(result);
cout << "Error: SharedDatabase::DBLoadNPCFactionLists: !EMuShareMemDLL.NPCFactionList.cbSetFaction" << endl;
return false;
}
memset(tmpfactionid, 0, sizeof(tmpfactionid));
memset(tmpfactionvalue, 0, sizeof(tmpfactionvalue));
memset(tmpfactionnpcvalue, 0, sizeof(tmpfactionnpcvalue));
memset(tmpfactiontemp, 0, sizeof(tmpfactiontemp));
i = 0;
}
curflid = tmpflid;
tmpfactionid[i] = atoi(row[1]);
tmpfactionvalue[i] = atoi(row[2]);
tmpfactionnpcvalue[i] = atoi(row[3]);
tmpfactiontemp[i] = atoi(row[4]);
i++;
if (i >= MAX_NPC_FACTIONS) {
cerr << "Error in DBLoadNPCFactionLists: More than MAX_NPC_FACTIONS factions returned, flid=" << tmpflid << endl;
break;
}
Sleep(0);
}
if (tmpflid) {
EMuShareMemDLL.NPCFactionList.cbSetFaction(curflid, tmpfactionid, tmpfactionvalue, tmpfactionnpcvalue, tmpfactiontemp);
}
mysql_free_result(result);
}
else {
cerr << "Error in DBLoadNPCFactionLists query3 '" << query << "' " << errbuf << endl;
safe_delete_array(query);
return false;
}
}
else {
mysql_free_result(result);
//return false;
}
}
else {
cerr << "Error in DBLoadNPCFactionLists query1 '" << query << "' " << errbuf << endl;
safe_delete_array(query);
return false;
}
return true;
}
// Get the player profile and inventory for the given account "account_id" and
// character name "name". Return true if the character was found, otherwise false.
// False will also be returned if there is a database error.
@@ -1428,37 +1395,6 @@ int32 SharedDatabase::DeleteStalePlayerBackups() {
return affected_rows;
}
int32 SharedDatabase::GetNPCFactionListsCount(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 npc_faction");
if (RunQuery(query, strlen(query), errbuf, &result)) {
safe_delete_array(query);
row = mysql_fetch_row(result);
if (row != NULL && row[1] != 0) {
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 GetNPCFactionListsCount query '" << query << "' " << errbuf << endl;
safe_delete_array(query);
return -1;
}
return -1;
}
bool SharedDatabase::GetCommandSettings(map<string,uint8> &commands) {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
@@ -1894,6 +1830,11 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
++(lt->NumEntries);
++current_entry;
}
if(current_id != 0) {
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) +
(sizeof(LootTableEntries_Struct) * lt->NumEntries)));
}
mysql_free_result(result);
} else {
LogFile->write(EQEMuLog::Error, "Error getting loot table info from database: %s, %s", query, errbuf);
+6 -9
View File
@@ -79,17 +79,19 @@ public:
*/
//items
int32 GetItemsCount(uint32* max_id = 0);
void GetItemsCount(int32 &item_count, uint32 &max_id);
void LoadItems(void *data, uint32 size, int32 items, uint32 max_item_id);
bool LoadItems();
const Item_Struct* IterateItems(uint32* id);
const Item_Struct* GetItem(uint32 id);
const EvolveInfo* GetEvolveInfo(uint32 loregroup);
const EvolveInfo* GetEvolveInfo(uint32 loregroup);
//faction lists
void GetFactionListInfo(uint32 &list_count, uint32 &max_lists);
const NPCFactionList* GetNPCFactionEntry(uint32 id);
void LoadNPCFactionLists(void *data, uint32 size, uint32 list_count, uint32 max_lists);
bool LoadNPCFactionLists();
bool DBLoadNPCFactionLists(int32 iNPCFactionListCount, uint32 iMaxNPCFactionListID);
//bool DBLoadNPCFactionLists(int32 iNPCFactionListCount, uint32 iMaxNPCFactionListID);
//loot
void GetLootTableInfo(uint32 &loot_table_count, uint32 &max_loot_table, uint32 &loot_table_entries);
@@ -111,15 +113,10 @@ public:
protected:
/*
* Private shared mem stuff
*/
int32 GetNPCFactionListsCount(uint32* oMaxID = 0);
static bool extDBLoadNPCFactionLists(int32 iNPCFactionListCount, uint32 iMaxNPCFactionListID);
EQEmu::MemoryMappedFile *items_mmf;
EQEmu::FixedMemoryHashSet<Item_Struct> *items_hash;
EQEmu::MemoryMappedFile *faction_mmf;
EQEmu::FixedMemoryHashSet<NPCFactionList> *faction_hash;
EQEmu::MemoryMappedFile *loot_table_mmf;
EQEmu::FixedMemoryVariableHashSet<LootTable_Struct> *loot_table_hash;
EQEmu::MemoryMappedFile *loot_drop_mmf;