Add zone store

This commit is contained in:
Akkadius 2020-04-19 03:05:15 -05:00
parent 6a51bcf8fd
commit ebda1cf601
9 changed files with 352 additions and 172 deletions

View File

@ -249,7 +249,7 @@ public:
bool LoadPTimers(uint32 charid, PTimerList &into); bool LoadPTimers(uint32 charid, PTimerList &into);
bool LoadZoneNames(); bool LoadZoneNames();
const char* GetZoneName(uint32 zoneID, bool ErrorUnknown = false); const char* GetZoneName(uint32 zone_id, bool ErrorUnknown = false);
uint32 GetZoneGraveyardID(uint32 zone_id, uint32 version); uint32 GetZoneGraveyardID(uint32 zone_id, uint32 version);
uint32 GetZoneID(const char* zonename); uint32 GetZoneID(const char* zonename);

View File

@ -44,10 +44,10 @@ public:
float safe_y; float safe_y;
float safe_z; float safe_z;
float graveyard_id; float graveyard_id;
int8 min_level; int min_level;
int8 min_status; int min_status;
int zoneidnumber; int zoneidnumber;
int8 version; int version;
int timezone; int timezone;
int maxclients; int maxclients;
int ruleset; int ruleset;
@ -57,46 +57,46 @@ public:
float maxclip; float maxclip;
float fog_minclip; float fog_minclip;
float fog_maxclip; float fog_maxclip;
int8 fog_blue; int fog_blue;
int8 fog_red; int fog_red;
int8 fog_green; int fog_green;
int8 sky; int sky;
int8 ztype; int ztype;
float zone_exp_multiplier; float zone_exp_multiplier;
float walkspeed; float walkspeed;
int8 time_type; int time_type;
int8 fog_red1; int fog_red1;
int8 fog_green1; int fog_green1;
int8 fog_blue1; int fog_blue1;
float fog_minclip1; float fog_minclip1;
float fog_maxclip1; float fog_maxclip1;
int8 fog_red2; int fog_red2;
int8 fog_green2; int fog_green2;
int8 fog_blue2; int fog_blue2;
float fog_minclip2; float fog_minclip2;
float fog_maxclip2; float fog_maxclip2;
int8 fog_red3; int fog_red3;
int8 fog_green3; int fog_green3;
int8 fog_blue3; int fog_blue3;
float fog_minclip3; float fog_minclip3;
float fog_maxclip3; float fog_maxclip3;
int8 fog_red4; int fog_red4;
int8 fog_green4; int fog_green4;
int8 fog_blue4; int fog_blue4;
float fog_minclip4; float fog_minclip4;
float fog_maxclip4; float fog_maxclip4;
float fog_density; float fog_density;
std::string flag_needed; std::string flag_needed;
int8 canbind; int canbind;
int8 cancombat; int cancombat;
int8 canlevitate; int canlevitate;
int8 castoutdoor; int castoutdoor;
int8 hotzone; int hotzone;
int8 insttype; int insttype;
int shutdowndelay; int shutdowndelay;
int8 peqzone; int peqzone;
int8 expansion; int expansion;
int8 suspendbuffs; int suspendbuffs;
int rain_chance1; int rain_chance1;
int rain_chance2; int rain_chance2;
int rain_chance3; int rain_chance3;
@ -115,7 +115,7 @@ public:
int snow_duration4; int snow_duration4;
float gravity; float gravity;
int type; int type;
int8 skylock; int skylock;
int fast_regen_hp; int fast_regen_hp;
int fast_regen_mana; int fast_regen_mana;
int fast_regen_endurance; int fast_regen_endurance;

View File

@ -1,25 +1,27 @@
/* EQEMu: Everquest Server Emulator /**
Copyright (C) 2001-2016 EQEMu Development Team (http://eqemulator.org) * EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
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 * This program is free software; you can redistribute it and/or modify
the Free Software Foundation; version 2 of the License. * 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 * This program is distributed in the hope that it will be useful,
are required to give you total support for your newly bought product; * but WITHOUT ANY WARRANTY except by those people which sell it, which
without even the implied warranty of MERCHANTABILITY or FITNESS FOR * are required to give you total support for your newly bought product;
A PARTICULAR PURPOSE. See the GNU General Public License for more details. * 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 * You should have received a copy of the GNU General Public License
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * along with this program; if not, write to the Free Software
*/ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef SHAREDDB_H_ #ifndef SHAREDDB_H_
#define SHAREDDB_H_ #define SHAREDDB_H_
#define MAX_ITEM_ID 200000 #define MAX_ITEM_ID 200000
#include "database.h" #include "database.h"
#include "skills.h" #include "skills.h"
@ -41,8 +43,7 @@ struct NPCFactionList;
struct LootTable_Struct; struct LootTable_Struct;
struct LootDrop_Struct; struct LootDrop_Struct;
namespace EQEmu namespace EQEmu {
{
struct ItemData; struct ItemData;
class ItemInstance; class ItemInstance;
class InventoryProfile; class InventoryProfile;
@ -54,114 +55,149 @@ namespace EQEmu
and is mainly here to facilitate shared memory, and other and is mainly here to facilitate shared memory, and other
things which only world and zone need. things which only world and zone need.
*/ */
class SharedDatabase : public Database class SharedDatabase : public Database {
{ public:
public: SharedDatabase();
SharedDatabase(); SharedDatabase(const char *host, const char *user, const char *passwd, const char *database, uint32 port);
SharedDatabase(const char* host, const char* user, const char* passwd, const char* database, uint32 port); virtual ~SharedDatabase();
virtual ~SharedDatabase();
/* /**
General Character Related Stuff * Character
*/ */
bool SetGMSpeed(uint32 account_id, uint8 gmspeed); bool SetGMSpeed(uint32 account_id, uint8 gmspeed);
uint8 GetGMSpeed(uint32 account_id); uint8 GetGMSpeed(uint32 account_id);
bool SetHideMe(uint32 account_id, uint8 hideme); bool SetHideMe(uint32 account_id, uint8 hideme);
int32 DeleteStalePlayerCorpses(); int32 DeleteStalePlayerCorpses();
void LoadCharacterInspectMessage(uint32 character_id, InspectMessage_Struct* message); void LoadCharacterInspectMessage(uint32 character_id, InspectMessage_Struct *message);
void SaveCharacterInspectMessage(uint32 character_id, const InspectMessage_Struct* message); void SaveCharacterInspectMessage(uint32 character_id, const InspectMessage_Struct *message);
bool GetCommandSettings(std::map<std::string, std::pair<uint8, std::vector<std::string>>> &command_settings); bool GetCommandSettings(std::map<std::string, std::pair<uint8, std::vector<std::string>>> &command_settings);
bool UpdateInjectedCommandSettings(const std::vector<std::pair<std::string, uint8>> &injected); bool UpdateInjectedCommandSettings(const std::vector<std::pair<std::string, uint8>> &injected);
bool UpdateOrphanedCommandSettings(const std::vector<std::string> &orphaned); bool UpdateOrphanedCommandSettings(const std::vector<std::string> &orphaned);
uint32 GetTotalTimeEntitledOnAccount(uint32 AccountID); uint32 GetTotalTimeEntitledOnAccount(uint32 AccountID);
void SetMailKey(int CharID, int IPAddress, int MailKey); void SetMailKey(int CharID, int IPAddress, int MailKey);
std::string GetMailKey(int CharID, bool key_only = false); std::string GetMailKey(int CharID, bool key_only = false);
bool SaveCursor(
uint32 char_id,
std::list<EQEmu::ItemInstance *>::const_iterator &start,
std::list<EQEmu::ItemInstance *>::const_iterator &end
);
bool SaveInventory(uint32 char_id, const EQEmu::ItemInstance *inst, int16 slot_id);
bool DeleteSharedBankSlot(uint32 char_id, int16 slot_id);
bool DeleteInventorySlot(uint32 char_id, int16 slot_id);
bool UpdateInventorySlot(uint32 char_id, const EQEmu::ItemInstance *inst, int16 slot_id);
bool UpdateSharedBankSlot(uint32 char_id, const EQEmu::ItemInstance *inst, int16 slot_id);
bool VerifyInventory(uint32 account_id, int16 slot_id, const EQEmu::ItemInstance *inst);
bool GetSharedBank(uint32 id, EQEmu::InventoryProfile *inv, bool is_charid);
int32 GetSharedPlatinum(uint32 account_id);
bool SetSharedPlatinum(uint32 account_id, int32 amount_to_add);
bool GetInventory(uint32 char_id, EQEmu::InventoryProfile *inv);
bool GetInventory(uint32 account_id, char *name, EQEmu::InventoryProfile *inv); // deprecated
std::map<uint32, uint32> GetItemRecastTimestamps(uint32 char_id);
uint32 GetItemRecastTimestamp(uint32 char_id, uint32 recast_type);
void ClearOldRecastTimestamps(uint32 char_id);
bool SetStartingItems(
PlayerProfile_Struct *pp,
EQEmu::InventoryProfile *inv,
uint32 si_race,
uint32 si_class,
uint32 si_deity,
uint32 si_current_zone,
char *si_name,
int admin
);
/* std::string GetBook(const char *txtfile, int16 *language);
Character InventoryProfile
*/
bool SaveCursor(uint32 char_id, std::list<EQEmu::ItemInstance*>::const_iterator &start, std::list<EQEmu::ItemInstance*>::const_iterator &end);
bool SaveInventory(uint32 char_id, const EQEmu::ItemInstance* inst, int16 slot_id);
bool DeleteSharedBankSlot(uint32 char_id, int16 slot_id);
bool DeleteInventorySlot(uint32 char_id, int16 slot_id);
bool UpdateInventorySlot(uint32 char_id, const EQEmu::ItemInstance* inst, int16 slot_id);
bool UpdateSharedBankSlot(uint32 char_id, const EQEmu::ItemInstance* inst, int16 slot_id);
bool VerifyInventory(uint32 account_id, int16 slot_id, const EQEmu::ItemInstance* inst);
bool GetSharedBank(uint32 id, EQEmu::InventoryProfile* inv, bool is_charid);
int32 GetSharedPlatinum(uint32 account_id);
bool SetSharedPlatinum(uint32 account_id, int32 amount_to_add);
bool GetInventory(uint32 char_id, EQEmu::InventoryProfile* inv);
bool GetInventory(uint32 account_id, char* name, EQEmu::InventoryProfile* inv); // deprecated
std::map<uint32, uint32> GetItemRecastTimestamps(uint32 char_id);
uint32 GetItemRecastTimestamp(uint32 char_id, uint32 recast_type);
void ClearOldRecastTimestamps(uint32 char_id);
bool SetStartingItems(PlayerProfile_Struct* pp, EQEmu::InventoryProfile* inv, uint32 si_race, uint32 si_class, uint32 si_deity, uint32 si_current_zone, char* si_name, int admin);
/**
* items
*/
EQEmu::ItemInstance *CreateItem(
uint32 item_id,
int16 charges = 0,
uint32 aug1 = 0,
uint32 aug2 = 0,
uint32 aug3 = 0,
uint32 aug4 = 0,
uint32 aug5 = 0,
uint32 aug6 = 0,
uint8 attuned = 0
);
EQEmu::ItemInstance *CreateItem(
const EQEmu::ItemData *item,
int16 charges = 0,
uint32 aug1 = 0,
uint32 aug2 = 0,
uint32 aug3 = 0,
uint32 aug4 = 0,
uint32 aug5 = 0,
uint32 aug6 = 0,
uint8 attuned = 0
);
EQEmu::ItemInstance *CreateBaseItem(const EQEmu::ItemData *item, int16 charges = 0);
std::string GetBook(const char *txtfile, int16 *language); void GetItemsCount(int32 &item_count, uint32 &max_id);
void LoadItems(void *data, uint32 size, int32 items, uint32 max_item_id);
bool LoadItems(const std::string &prefix);
const EQEmu::ItemData *IterateItems(uint32 *id);
const EQEmu::ItemData *GetItem(uint32 id);
const EvolveInfo *GetEvolveInfo(uint32 loregroup);
/* /**
Item Methods * faction
*/ */
EQEmu::ItemInstance* CreateItem(uint32 item_id, int16 charges = 0, uint32 aug1 = 0, uint32 aug2 = 0, uint32 aug3 = 0, uint32 aug4 = 0, uint32 aug5 = 0, uint32 aug6 = 0, uint8 attuned = 0); void GetFactionListInfo(uint32 &list_count, uint32 &max_lists);
EQEmu::ItemInstance* CreateItem(const EQEmu::ItemData* item, int16 charges = 0, uint32 aug1 = 0, uint32 aug2 = 0, uint32 aug3 = 0, uint32 aug4 = 0, uint32 aug5 = 0, uint32 aug6 = 0, uint8 attuned = 0); const NPCFactionList *GetNPCFactionEntry(uint32 id);
EQEmu::ItemInstance* CreateBaseItem(const EQEmu::ItemData* item, int16 charges = 0); void LoadNPCFactionLists(void *data, uint32 size, uint32 list_count, uint32 max_lists);
bool LoadNPCFactionLists(const std::string &prefix);
/* /**
Shared Memory crap * loot
*/ */
void GetLootTableInfo(uint32 &loot_table_count, uint32 &max_loot_table, uint32 &loot_table_entries);
void GetLootDropInfo(uint32 &loot_drop_count, uint32 &max_loot_drop, uint32 &loot_drop_entries);
void LoadLootTables(void *data, uint32 size);
void LoadLootDrops(void *data, uint32 size);
bool LoadLoot(const std::string &prefix);
const LootTable_Struct *GetLootTable(uint32 loottable_id);
const LootDrop_Struct *GetLootDrop(uint32 lootdrop_id);
//items /**
void GetItemsCount(int32 &item_count, uint32 &max_id); * skills
void LoadItems(void *data, uint32 size, int32 items, uint32 max_item_id); */
bool LoadItems(const std::string &prefix); void LoadSkillCaps(void *data);
const EQEmu::ItemData* IterateItems(uint32* id); bool LoadSkillCaps(const std::string &prefix);
const EQEmu::ItemData* GetItem(uint32 id); uint16 GetSkillCap(uint8 Class_, EQEmu::skills::SkillType Skill, uint8 Level);
const EvolveInfo* GetEvolveInfo(uint32 loregroup); uint8 GetTrainLevel(uint8 Class_, EQEmu::skills::SkillType Skill, uint8 Level);
//faction lists /**
void GetFactionListInfo(uint32 &list_count, uint32 &max_lists); * spells
const NPCFactionList* GetNPCFactionEntry(uint32 id); */
void LoadNPCFactionLists(void *data, uint32 size, uint32 list_count, uint32 max_lists); int GetMaxSpellID();
bool LoadNPCFactionLists(const std::string &prefix); bool LoadSpells(const std::string &prefix, int32 *records, const SPDat_Spell_Struct **sp);
void LoadSpells(void *data, int max_spells);
void LoadDamageShieldTypes(SPDat_Spell_Struct *sp, int32 iMaxSpellID);
//loot /**
void GetLootTableInfo(uint32 &loot_table_count, uint32 &max_loot_table, uint32 &loot_table_entries); * basedata
void GetLootDropInfo(uint32 &loot_drop_count, uint32 &max_loot_drop, uint32 &loot_drop_entries); */
void LoadLootTables(void *data, uint32 size); int GetMaxBaseDataLevel();
void LoadLootDrops(void *data, uint32 size); bool LoadBaseData(const std::string &prefix);
bool LoadLoot(const std::string &prefix); void LoadBaseData(void *data, int max_level);
const LootTable_Struct* GetLootTable(uint32 loottable_id); const BaseDataStruct *GetBaseData(int lvl, int cl);
const LootDrop_Struct* GetLootDrop(uint32 lootdrop_id);
void LoadSkillCaps(void *data); protected:
bool LoadSkillCaps(const std::string &prefix);
uint16 GetSkillCap(uint8 Class_, EQEmu::skills::SkillType Skill, uint8 Level);
uint8 GetTrainLevel(uint8 Class_, EQEmu::skills::SkillType Skill, uint8 Level);
int GetMaxSpellID(); std::unique_ptr<EQEmu::MemoryMappedFile> skill_caps_mmf;
bool LoadSpells(const std::string &prefix, int32 *records, const SPDat_Spell_Struct **sp); std::unique_ptr<EQEmu::MemoryMappedFile> items_mmf;
void LoadSpells(void *data, int max_spells); std::unique_ptr<EQEmu::FixedMemoryHashSet<EQEmu::ItemData>> items_hash;
void LoadDamageShieldTypes(SPDat_Spell_Struct* sp, int32 iMaxSpellID); std::unique_ptr<EQEmu::MemoryMappedFile> faction_mmf;
std::unique_ptr<EQEmu::FixedMemoryHashSet<NPCFactionList>> faction_hash;
int GetMaxBaseDataLevel(); std::unique_ptr<EQEmu::MemoryMappedFile> loot_table_mmf;
bool LoadBaseData(const std::string &prefix); std::unique_ptr<EQEmu::FixedMemoryVariableHashSet<LootTable_Struct>> loot_table_hash;
void LoadBaseData(void *data, int max_level); std::unique_ptr<EQEmu::MemoryMappedFile> loot_drop_mmf;
const BaseDataStruct* GetBaseData(int lvl, int cl); std::unique_ptr<EQEmu::FixedMemoryVariableHashSet<LootDrop_Struct>> loot_drop_hash;
std::unique_ptr<EQEmu::MemoryMappedFile> base_data_mmf;
protected: std::unique_ptr<EQEmu::MemoryMappedFile> spells_mmf;
std::unique_ptr<EQEmu::MemoryMappedFile> skill_caps_mmf;
std::unique_ptr<EQEmu::MemoryMappedFile> items_mmf;
std::unique_ptr<EQEmu::FixedMemoryHashSet<EQEmu::ItemData>> items_hash;
std::unique_ptr<EQEmu::MemoryMappedFile> faction_mmf;
std::unique_ptr<EQEmu::FixedMemoryHashSet<NPCFactionList>> faction_hash;
std::unique_ptr<EQEmu::MemoryMappedFile> loot_table_mmf;
std::unique_ptr<EQEmu::FixedMemoryVariableHashSet<LootTable_Struct>> loot_table_hash;
std::unique_ptr<EQEmu::MemoryMappedFile> loot_drop_mmf;
std::unique_ptr<EQEmu::FixedMemoryVariableHashSet<LootDrop_Struct>> loot_drop_hash;
std::unique_ptr<EQEmu::MemoryMappedFile> base_data_mmf;
std::unique_ptr<EQEmu::MemoryMappedFile> spells_mmf;
}; };
#endif /*SHAREDDB_H_*/ #endif /*SHAREDDB_H_*/

View File

@ -457,10 +457,10 @@ sub translate_mysql_data_type_to_c {
my $struct_data_type = "std::string"; my $struct_data_type = "std::string";
if ($mysql_data_type =~ /tinyint/) { if ($mysql_data_type =~ /tinyint/) {
$struct_data_type = 'int8'; $struct_data_type = 'int';
} }
elsif ($mysql_data_type =~ /smallint/) { elsif ($mysql_data_type =~ /smallint/) {
$struct_data_type = 'int16'; $struct_data_type = 'int';
} }
elsif ($mysql_data_type =~ /bigint/) { elsif ($mysql_data_type =~ /bigint/) {
$struct_data_type = 'int'; $struct_data_type = 'int';

View File

@ -142,6 +142,7 @@ SET(zone_sources
zone_config.cpp zone_config.cpp
zonedb.cpp zonedb.cpp
zone_reload.cpp zone_reload.cpp
zone_store.cpp
zoning.cpp zoning.cpp
) )
@ -249,7 +250,9 @@ SET(zone_headers
zone_config.h zone_config.h
zonedb.h zonedb.h
zonedump.h zonedump.h
zone_reload.h ) zone_reload.h
zone_store.h
)
ADD_EXECUTABLE(zone ${zone_sources} ${zone_headers}) ADD_EXECUTABLE(zone ${zone_sources} ${zone_headers})

View File

@ -1,20 +1,22 @@
/* EQEMu: Everquest Server Emulator /**
Copyright (C) 2001-2016 EQEMu Development Team (http://eqemu.org) * EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
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 * This program is free software; you can redistribute it and/or modify
the Free Software Foundation; version 2 of the License. * 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 * This program is distributed in the hope that it will be useful,
are required to give you total support for your newly bought product; * but WITHOUT ANY WARRANTY except by those people which sell it, which
without even the implied warranty of MERCHANTABILITY or FITNESS FOR * are required to give you total support for your newly bought product;
A PARTICULAR PURPOSE. See the GNU General Public License for more details. * 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 * You should have received a copy of the GNU General Public License
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 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 #define DONT_SHARED_OPCODES
#define PLATFORM_ZONE 1 #define PLATFORM_ZONE 1
@ -93,6 +95,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#else #else
#include <pthread.h> #include <pthread.h>
#include "../common/unix.h" #include "../common/unix.h"
#include "zone_store.h"
#endif #endif
@ -101,6 +104,7 @@ extern volatile bool is_zone_loaded;
EntityList entity_list; EntityList entity_list;
WorldServer worldserver; WorldServer worldserver;
ZoneStore zone_store;
uint32 numclients = 0; uint32 numclients = 0;
char errorname[32]; char errorname[32];
extern Zone* zone; extern Zone* zone;
@ -318,6 +322,8 @@ int main(int argc, char** argv) {
content_db.LoadZoneNames(); content_db.LoadZoneNames();
database.zonename_array = content_db.zonename_array; database.zonename_array = content_db.zonename_array;
zone_store.LoadZonesStore();
LogInfo("Loading items"); LogInfo("Loading items");
if (!database.LoadItems(hotfix_name)) { if (!database.LoadItems(hotfix_name)) {
LogError("Loading items failed!"); LogError("Loading items failed!");
@ -373,7 +379,7 @@ int main(int argc, char** argv) {
LogInfo("Loading commands"); LogInfo("Loading commands");
int retval = command_init(); int retval = command_init();
if (retval<0) if (retval < 0)
LogError("Command loading failed"); LogError("Command loading failed");
else else
LogInfo("{} commands loaded", retval); LogInfo("{} commands loaded", retval);
@ -466,7 +472,7 @@ int main(int argc, char** argv) {
if (!strlen(zone_name) || !strcmp(zone_name, ".")) { if (!strlen(zone_name) || !strcmp(zone_name, ".")) {
LogInfo("Entering sleep mode"); LogInfo("Entering sleep mode");
} }
else if (!Zone::Bootup(content_db.GetZoneID(zone_name), instance_id, true)) { else if (!Zone::Bootup(ZoneID(zone_name), instance_id, true)) {
LogError("Zone Bootup failed :: Zone::Bootup"); LogError("Zone Bootup failed :: Zone::Bootup");
zone = 0; zone = 0;
} }

View File

@ -335,7 +335,6 @@ public:
double GetMaxMovementUpdateRange() const { return max_movement_update_range; } double GetMaxMovementUpdateRange() const { return max_movement_update_range; }
/** /**
* Modding hooks * Modding hooks
*/ */

77
zone/zone_store.cpp Normal file
View File

@ -0,0 +1,77 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* 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 "zone_store.h"
ZoneStore::ZoneStore() = default;
ZoneStore::~ZoneStore() = default;
void ZoneStore::LoadZonesStore()
{
zones = ZoneRepository::All();
}
uint32 ZoneStore::GetZoneID(const char *in_zone_name)
{
if (in_zone_name == nullptr) {
return 0;
}
std::string zone_name = in_zone_name;
return GetZoneID(zone_name);
}
uint32 ZoneStore::GetZoneID(std::string zone_name)
{
for (auto &z: zones) {
if (z.short_name == zone_name) {
return z.zoneidnumber;
}
}
return 0;
}
const char *ZoneStore::GetZoneName(uint32 zone_id, bool error_unknown)
{
for (auto &z: zones) {
if (z.zoneidnumber == zone_id) {
return z.short_name.c_str();
}
}
if (error_unknown) {
return "UNKNOWN";
}
return nullptr;
}
std::string ZoneStore::GetZoneName(uint32 zone_id)
{
for (auto &z: zones) {
if (z.zoneidnumber == zone_id) {
return z.short_name;
}
}
return std::string();
}

59
zone/zone_store.h Normal file
View File

@ -0,0 +1,59 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* 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_ZONE_STORE_H
#define EQEMU_ZONE_STORE_H
#include "zonedb.h"
#include "../common/repositories/zone_repository.h"
class ZoneStore {
public:
ZoneStore();
virtual ~ZoneStore();
std::vector<ZoneRepository::Zone> zones;
void LoadZonesStore();
uint32 GetZoneID(const char *in_zone_name);
uint32 GetZoneID(std::string zone_name);
std::string GetZoneName(uint32 zone_id);
const char *GetZoneName(uint32 zone_id, bool error_unknown);
};
extern ZoneStore zone_store;
/**
* Global helpers
*/
inline uint32 ZoneID(const char *in_zone_name) { return zone_store.GetZoneID(in_zone_name); }
inline uint32 ZoneID(std::string zone_name) { return zone_store.GetZoneID(zone_name); }
inline std::string ZoneName(uint32 zone_id) { return zone_store.GetZoneName(zone_id); }
inline const char *ZoneName(uint32 zone_id, bool error_unknown)
{
return zone_store.GetZoneName(
zone_id,
error_unknown
);
}
#endif //EQEMU_ZONE_STORE_H