Merge branch 'feature/peq-expansions' of https://github.com/EQEmu/Server into feature/generated-repositories

This commit is contained in:
Akkadius 2020-04-05 23:21:21 -05:00
commit a19bb7b544
21 changed files with 639 additions and 325 deletions

View File

@ -26,8 +26,10 @@
#include "../../common/crash.h"
#include "../../common/rulesys.h"
#include "../../common/string_util.h"
#include "../../common/content/world_content_service.h"
EQEmuLogSys LogSys;
WorldContentService content_service;
void ExportSpells(SharedDatabase *db);
void ExportSkillCaps(SharedDatabase *db);

View File

@ -24,8 +24,10 @@
#include "../../common/crash.h"
#include "../../common/rulesys.h"
#include "../../common/string_util.h"
#include "../../common/content/world_content_service.h"
EQEmuLogSys LogSys;
WorldContentService content_service;
void ImportSpells(SharedDatabase *db);
void ImportSkillCaps(SharedDatabase *db);

View File

@ -28,7 +28,7 @@ namespace Expansion {
enum ExpansionNumber {
Classic = 0,
TheRuinsOfKunark,
TheShardsOfVelious,
TheScarsOfVelious,
TheShadowsOfLuclin,
ThePlanesOfPower,
TheLegacyOfYkesha,
@ -62,8 +62,10 @@ namespace Expansion {
static const char *ExpansionName[ExpansionNumber::MaxId] = {
"Classic",
"The Ruins of Kunark",
"The Scars of Velious",
"The Shadows of Luclin",
"The Planes of Power",
"The Legacy of Ykesha",
"Lost Dungeons of Norrath",
"Gates of Discord",
"Omens of War",
@ -96,7 +98,7 @@ public:
bool IsClassicEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::Classic; }
bool IsTheRuinsOfKunarkEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheRuinsOfKunark; }
bool IsTheShardsOfVeliousEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheShardsOfVelious; }
bool IsTheScarsOfVeliousEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheScarsOfVelious; }
bool IsTheShadowsOfLuclinEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheShadowsOfLuclin; }
bool IsThePlanesOfPowerEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::ThePlanesOfPower; }
bool IsTheLegacyOfYkeshaEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheLegacyOfYkesha; }
@ -124,7 +126,7 @@ public:
bool IsCurrentExpansionClassic() { return current_expansion == Expansion::ExpansionNumber::Classic; }
bool IsCurrentExpansionTheRuinsOfKunark() { return current_expansion == Expansion::ExpansionNumber::TheRuinsOfKunark; }
bool IsCurrentExpansionTheShardsOfVelious() { return current_expansion == Expansion::ExpansionNumber::TheShardsOfVelious; }
bool IsCurrentExpansionTheScarsOfVelious() { return current_expansion == Expansion::ExpansionNumber::TheScarsOfVelious; }
bool IsCurrentExpansionTheShadowsOfLuclin() { return current_expansion == Expansion::ExpansionNumber::TheShadowsOfLuclin; }
bool IsCurrentExpansionThePlanesOfPower() { return current_expansion == Expansion::ExpansionNumber::ThePlanesOfPower; }
bool IsCurrentExpansionTheLegacyOfYkesha() { return current_expansion == Expansion::ExpansionNumber::TheLegacyOfYkesha; }

View File

@ -26,29 +26,48 @@
#include "../../string_util.h"
namespace ContentFilterCriteria {
static std::string apply()
static std::string apply(std::string table_prefix = "")
{
std::string criteria;
if (!table_prefix.empty()) {
table_prefix = table_prefix + ".";
}
criteria += fmt::format(
" AND (min_expansion >= {} OR min_expansion = 0)",
content_service.GetCurrentExpansion()
" AND ({}min_expansion <= {} OR {}min_expansion = 0)",
table_prefix,
content_service.GetCurrentExpansion(),
table_prefix
);
criteria += fmt::format(
" AND (max_expansion <= {} OR max_expansion = 0)",
content_service.GetCurrentExpansion()
" AND ({}max_expansion >= {} OR {}max_expansion = 0)",
table_prefix,
content_service.GetCurrentExpansion(),
table_prefix
);
std::vector<std::string> flags = content_service.GetContentFlags();
for (auto &flag: flags) {
flag = "'" + flag + "'";
}
criteria += fmt::format(
" AND (content_flags IS NULL OR content_flags IN ({}))",
std::string flags_in_filter;
if (!flags.empty()) {
flags_in_filter = fmt::format(
" OR {}content_flags IN ({})",
table_prefix,
implode(", ", flags)
);
}
criteria += fmt::format(
" AND ({}content_flags IS NULL{})",
table_prefix,
flags_in_filter
);
return std::string(criteria);
};

View File

@ -38,6 +38,7 @@
#include "shareddb.h"
#include "string_util.h"
#include "eqemu_config.h"
#include "repositories/criteria/content_filter_criteria.h"
namespace ItemField
{
@ -431,16 +432,25 @@ bool SharedDatabase::SetSharedPlatinum(uint32 account_id, int32 amount_to_add) {
bool SharedDatabase::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_level) {
const EQEmu::ItemData* myitem;
const EQEmu::ItemData *myitem;
std::string query = StringFormat("SELECT itemid, item_charges, slot FROM starting_items "
std::string query = StringFormat(
"SELECT itemid, item_charges, slot FROM starting_items "
"WHERE (race = %i or race = 0) AND (class = %i or class = 0) AND "
"(deityid = %i or deityid = 0) AND (zoneid = %i or zoneid = 0) AND "
"gm <= %i ORDER BY id",
si_race, si_class, si_deity, si_current_zone, admin_level);
"gm <= %i %s ORDER BY id",
si_race,
si_class,
si_deity,
si_current_zone,
admin_level,
ContentFilterCriteria::apply().c_str()
);
auto results = QueryDatabase(query);
if (!results.Success())
if (!results.Success()) {
return false;
}
for (auto row = results.begin(); row != results.end(); ++row) {
@ -1996,7 +2006,11 @@ void SharedDatabase::GetLootTableInfo(uint32 &loot_table_count, uint32 &max_loot
loot_table_count = 0;
max_loot_table = 0;
loot_table_entries = 0;
const std::string query = "SELECT COUNT(*), MAX(id), (SELECT COUNT(*) FROM loottable_entries) FROM loottable";
const std::string query =
fmt::format(
"SELECT COUNT(*), MAX(id), (SELECT COUNT(*) FROM loottable_entries) FROM loottable WHERE TRUE {}",
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
@ -2017,7 +2031,11 @@ void SharedDatabase::GetLootDropInfo(uint32 &loot_drop_count, uint32 &max_loot_d
max_loot_drop = 0;
loot_drop_entries = 0;
const std::string query = "SELECT COUNT(*), MAX(id), (SELECT COUNT(*) FROM lootdrop_entries) FROM lootdrop";
const std::string query = fmt::format(
"SELECT COUNT(*), MAX(id), (SELECT COUNT(*) FROM lootdrop_entries) FROM lootdrop WHERE TRUE {}",
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
@ -2039,10 +2057,28 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
uint8 loot_table[sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128)];
LootTable_Struct *lt = reinterpret_cast<LootTable_Struct*>(loot_table);
const std::string query = "SELECT loottable.id, loottable.mincash, loottable.maxcash, loottable.avgcoin, "
"loottable_entries.lootdrop_id, loottable_entries.multiplier, loottable_entries.droplimit, "
"loottable_entries.mindrop, loottable_entries.probability FROM loottable LEFT JOIN loottable_entries "
"ON loottable.id = loottable_entries.loottable_id ORDER BY id";
const std::string query = fmt::format(
SQL(
SELECT
loottable.id,
loottable.mincash,
loottable.maxcash,
loottable.avgcoin,
loottable_entries.lootdrop_id,
loottable_entries.multiplier,
loottable_entries.droplimit,
loottable_entries.mindrop,
loottable_entries.probability
FROM
loottable
LEFT JOIN loottable_entries ON loottable.id = loottable_entries.loottable_id
WHERE TRUE {}
ORDER BY
id
),
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
@ -2053,9 +2089,13 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
for (auto row = results.begin(); row != results.end(); ++row) {
uint32 id = static_cast<uint32>(atoul(row[0]));
if(id != current_id) {
if(current_id != 0)
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
if (id != current_id) {
if (current_id != 0) {
hash.insert(
current_id,
loot_table,
(sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
}
memset(loot_table, 0, sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128));
current_entry = 0;
@ -2065,11 +2105,13 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
lt->avgcoin = static_cast<uint32>(atoul(row[3]));
}
if(current_entry > 128)
if (current_entry > 128) {
continue;
}
if(!row[4])
if (!row[4]) {
continue;
}
lt->Entries[current_entry].lootdrop_id = static_cast<uint32>(atoul(row[4]));
lt->Entries[current_entry].multiplier = static_cast<uint8>(atoi(row[5]));
@ -2081,8 +2123,13 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
++current_entry;
}
if(current_id != 0)
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
if (current_id != 0) {
hash.insert(
current_id,
loot_table,
(sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries))
);
}
}
@ -2092,10 +2139,28 @@ void SharedDatabase::LoadLootDrops(void *data, uint32 size) {
uint8 loot_drop[sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * 1260)];
LootDrop_Struct *ld = reinterpret_cast<LootDrop_Struct*>(loot_drop);
const std::string query = "SELECT lootdrop.id, lootdrop_entries.item_id, lootdrop_entries.item_charges, "
"lootdrop_entries.equip_item, lootdrop_entries.chance, lootdrop_entries.minlevel, "
"lootdrop_entries.maxlevel, lootdrop_entries.multiplier FROM lootdrop JOIN lootdrop_entries "
"ON lootdrop.id = lootdrop_entries.lootdrop_id ORDER BY lootdrop_id";
const std::string query = fmt::format(
SQL(
SELECT
lootdrop.id,
lootdrop_entries.item_id,
lootdrop_entries.item_charges,
lootdrop_entries.equip_item,
lootdrop_entries.chance,
lootdrop_entries.minlevel,
lootdrop_entries.maxlevel,
lootdrop_entries.multiplier
FROM
lootdrop
JOIN lootdrop_entries ON lootdrop.id = lootdrop_entries.lootdrop_id
WHERE
TRUE {}
ORDER BY
lootdrop_id
),
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;

View File

@ -33,8 +33,10 @@
#include "skill_caps.h"
#include "spells.h"
#include "base_data.h"
#include "../common/content/world_content_service.h"
EQEmuLogSys LogSys;
WorldContentService content_service;
#ifdef _WINDOWS
#include <direct.h>
@ -139,6 +141,39 @@ int main(int argc, char **argv)
}
}
/**
* Rules: TODO: Remove later
*/
{
std::string tmp;
if (database.GetVariable("RuleSet", tmp)) {
LogInfo("Loading rule set [{}]", tmp.c_str());
if (!RuleManager::Instance()->LoadRules(&database, tmp.c_str(), false)) {
LogError("Failed to load ruleset [{}], falling back to defaults", tmp.c_str());
}
}
else {
if (!RuleManager::Instance()->LoadRules(&database, "default", false)) {
LogInfo("No rule set configured, using default rules");
}
else {
LogInfo("Loaded default rule set 'default'");
}
}
EQEmu::InitializeDynamicLookups();
LogInfo("Initialized dynamic dictionary entries");
}
content_service.SetCurrentExpansion(RuleI(Expansion, CurrentExpansion));
LogInfo(
"Current expansion is [{}] ({})",
content_service.GetCurrentExpansion(),
Expansion::ExpansionName[content_service.GetCurrentExpansion()]
);
std::string hotfix_name = "";
bool load_all = true;

View File

@ -59,6 +59,7 @@ namespace WorldserverCommandHandler {
function_map["database:schema"] = &WorldserverCommandHandler::DatabaseGetSchema;
function_map["database:dump"] = &WorldserverCommandHandler::DatabaseDump;
function_map["test:test"] = &WorldserverCommandHandler::TestCommand;
function_map["test:expansion"] = &WorldserverCommandHandler::ExpansionTestCommand;
function_map["test:repository"] = &WorldserverCommandHandler::TestRepository;
function_map["test:repository2"] = &WorldserverCommandHandler::TestRepository2;
@ -293,6 +294,22 @@ namespace WorldserverCommandHandler {
return;
}
}
/**
* @param argc
* @param argv
* @param cmd
* @param description
*/
void ExpansionTestCommand(int argc, char **argv, argh::parser &cmd, std::string &description)
{
description = "Expansion test command";
if (cmd[{"-h", "--help"}]) {
return;
}
if (!RuleManager::Instance()->LoadRules(&database, "default", false)) {
LogInfo("No rule set configured, using default rules");
}
@ -310,7 +327,7 @@ namespace WorldserverCommandHandler {
"Current expansion is [{}] ({}) is Velious Enabled [{}] Criteria [{}]",
content_service.GetCurrentExpansion(),
Expansion::ExpansionName[content_service.GetCurrentExpansion()],
content_service.IsTheShardsOfVeliousEnabled() ? "true" : "false",
content_service.IsTheScarsOfVeliousEnabled() ? "true" : "false",
ContentFilterCriteria::apply()
);
}

View File

@ -32,6 +32,7 @@ namespace WorldserverCommandHandler {
void DatabaseGetSchema(int argc, char **argv, argh::parser &cmd, std::string &description);
void DatabaseDump(int argc, char **argv, argh::parser &cmd, std::string &description);
void TestCommand(int argc, char **argv, argh::parser &cmd, std::string &description);
void ExpansionTestCommand(int argc, char **argv, argh::parser &cmd, std::string &description);
void TestRepository(int argc, char **argv, argh::parser &cmd, std::string &description);
void TestRepository2(int argc, char **argv, argh::parser &cmd, std::string &description);
};

View File

@ -25,6 +25,7 @@
#include <cstdlib>
#include <vector>
#include "sof_char_create_data.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
WorldDatabase database;
WorldDatabase content_db;
@ -197,10 +198,11 @@ void WorldDatabase::GetCharSelectInfo(uint32 account_id, EQApplicationPacket **o
if (has_home == 0 || has_bind == 0) {
character_list_query = StringFormat(
"SELECT `zone_id`, `bind_id`, `x`, `y`, `z` FROM `start_zones` WHERE `player_class` = %i AND `player_deity` = %i AND `player_race` = %i",
"SELECT `zone_id`, `bind_id`, `x`, `y`, `z` FROM `start_zones` WHERE `player_class` = %i AND `player_deity` = %i AND `player_race` = %i %s",
p_character_select_entry_struct->Class,
p_character_select_entry_struct->Deity,
p_character_select_entry_struct->Race
p_character_select_entry_struct->Race,
ContentFilterCriteria::apply().c_str()
);
auto results_bind = content_db.QueryDatabase(character_list_query);
for (auto row_d = results_bind.begin(); row_d != results_bind.end(); ++row_d) {
@ -423,11 +425,12 @@ bool WorldDatabase::GetStartZone(
// see if we have an entry for start_zone. We can support both titanium & SOF+ by having two entries per class/race/deity combo with different zone_ids
std::string query = StringFormat(
"SELECT x, y, z, heading, start_zone, bind_id, bind_x, bind_y, bind_z FROM start_zones WHERE zone_id = %i "
"AND player_class = %i AND player_deity = %i AND player_race = %i",
"AND player_class = %i AND player_deity = %i AND player_race = %i %s",
p_char_create_struct->start_zone,
p_char_create_struct->class_,
p_char_create_struct->deity,
p_char_create_struct->race
p_char_create_struct->race,
ContentFilterCriteria::apply().c_str()
);
auto results = QueryDatabase(query);

View File

@ -61,6 +61,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "worldserver.h"
#include "zone.h"
#include "mob_movement_manager.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
#ifdef BOTS
#include "bot.h"
@ -11828,6 +11829,7 @@ void Client::Handle_OP_RecipesFavorite(const EQApplicationPacket *app)
if (first) //no favorites....
return;
// TODO: Clean this up
const std::string query = StringFormat(
SQL (
SELECT
@ -11849,6 +11851,7 @@ void Client::Handle_OP_RecipesFavorite(const EQApplicationPacket *app)
)
OR (tr.must_learn & 0x3 = 0)
)
%s
GROUP BY
tr.id
HAVING
@ -11861,10 +11864,12 @@ void Client::Handle_OP_RecipesFavorite(const EQApplicationPacket *app)
)
) > 0
AND SUM(tre.componentcount) <= %u
LIMIT
100
),
favoriteIDs.c_str(),
ContentFilterCriteria::apply().c_str(),
containers.c_str(),
combineObjectSlots
);
@ -11924,6 +11929,7 @@ void Client::Handle_OP_RecipesSearch(const EQApplicationPacket *app)
}
//arbitrary limit of 200 recipes, makes sense to me.
// TODO: Clean this up
std::string query = fmt::format(
SQL(
SELECT
@ -11931,27 +11937,10 @@ void Client::Handle_OP_RecipesSearch(const EQApplicationPacket *app)
tr.name,
tr.trivial,
SUM(tre.componentcount),
crl.madecount,
tr.tradeskill
FROM
tradeskill_recipe
AS tr
LEFT
JOIN
tradeskill_recipe_entries
AS
tre
ON
tr.id = tre.recipe_id
LEFT JOIN(
SELECT
recipe_id,
madecount
FROM
char_recipe_list
WHERE
char_id = {}
) AS crl ON tr.id = crl.recipe_id
tradeskill_recipe AS tr
LEFT JOIN tradeskill_recipe_entries AS tre ON tr.id = tre.recipe_id
WHERE
{} tr.trivial >= {}
AND tr.trivial <= {}
@ -11960,10 +11949,10 @@ void Client::Handle_OP_RecipesSearch(const EQApplicationPacket *app)
AND (
(
tr.must_learn & 0x3 <> 0
AND crl.madecount IS NOT NULL
)
OR (tr.must_learn & 0x3 = 0)
)
{}
GROUP BY
tr.id
HAVING
@ -11976,13 +11965,14 @@ void Client::Handle_OP_RecipesSearch(const EQApplicationPacket *app)
)
) > 0
AND SUM(tre.componentcount) <= {}
LIMIT
200
),
CharacterID(),
search_clause,
p_recipes_search_struct->mintrivial,
p_recipes_search_struct->maxtrivial,
ContentFilterCriteria::apply(),
containers_where_clause,
combine_object_slots
);
@ -12447,9 +12437,14 @@ void Client::Handle_OP_SetStartCity(const EQApplicationPacket *app)
uint32 zoneid = 0;
uint32 startCity = (uint32)strtol((const char*)app->pBuffer, nullptr, 10);
std::string query = StringFormat("SELECT zone_id, bind_id, x, y, z FROM start_zones "
"WHERE player_class=%i AND player_deity=%i AND player_race=%i",
m_pp.class_, m_pp.deity, m_pp.race);
std::string query = StringFormat(
"SELECT zone_id, bind_id, x, y, z FROM start_zones "
"WHERE player_class=%i AND player_deity=%i AND player_race=%i %s",
m_pp.class_,
m_pp.deity,
m_pp.race,
ContentFilterCriteria::apply().c_str()
);
auto results = content_db.QueryDatabase(query);
if (!results.Success()) {
LogError("No valid start zones found for /setstartcity");

View File

@ -28,6 +28,7 @@
#include "string_ids.h"
#include "worldserver.h"
#include "zonedb.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
#include <iostream>
#include <string.h>
@ -716,10 +717,12 @@ bool ZoneDatabase::LoadDoors(int32 door_count, Door *into, const char *zone_name
" WHERE "
" zone = '%s' "
" AND ( version = % u OR version = - 1 ) "
" %s "
" ORDER BY "
" doorid ASC ",
zone_name,
version
version,
ContentFilterCriteria::apply().c_str()
);
auto results = QueryDatabase(query);
if (!results.Success()) {

View File

@ -30,6 +30,7 @@
#include "titles.h"
#include "water_map.h"
#include "zonedb.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
#include <iostream>
@ -54,9 +55,25 @@ uint32 ZoneDatabase::GetZoneForage(uint32 ZoneID, uint8 skill) {
}
uint32 chancepool = 0;
std::string query = StringFormat("SELECT itemid, chance FROM "
"forage WHERE zoneid = '%i' and level <= '%i' "
"LIMIT %i", ZoneID, skill, FORAGE_ITEM_LIMIT);
std::string query = fmt::format(
SQL(
SELECT
itemid,
chance
FROM
forage
WHERE
zoneid = '{}'
and level <= '{}'
{}
LIMIT
{}
),
ZoneID,
skill,
ContentFilterCriteria::apply(),
FORAGE_ITEM_LIMIT
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return 0;
@ -109,9 +126,24 @@ uint32 ZoneDatabase::GetZoneFishing(uint32 ZoneID, uint8 skill, uint32 &npc_id,
chance[c]=0;
}
std::string query = StringFormat("SELECT itemid, chance, npc_id, npc_chance "
"FROM fishing WHERE (zoneid = '%i' || zoneid = 0) AND skill_level <= '%i'",
ZoneID, skill);
std::string query = fmt::format(
SQL(
SELECT
itemid,
chance,
npc_id,
npc_chance
FROM
fishing
WHERE
(zoneid = '{}' || zoneid = 0)
AND skill_level <= '{}'
{}
),
ZoneID,
skill,
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return 0;

View File

@ -27,6 +27,7 @@
#include "npc.h"
#include "zonedb.h"
#include "global_loot_manager.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
#include <iostream>
#include <stdlib.h>
@ -463,12 +464,35 @@ void NPC::CheckGlobalLootTables()
void ZoneDatabase::LoadGlobalLoot()
{
auto query = StringFormat("SELECT id, loottable_id, description, min_level, max_level, rare, raid, race, "
"class, bodytype, zone, hot_zone FROM global_loot WHERE enabled = 1");
auto query = fmt::format(
SQL
(
SELECT
id,
loottable_id,
description,
min_level,
max_level,
rare,
raid,
race,
class,
bodytype,
zone,
hot_zone
FROM
global_loot
WHERE
enabled = 1
{}
),
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success() || results.RowCount() == 0)
if (!results.Success() || results.RowCount() == 0) {
return;
}
// we might need this, lets not keep doing it in a loop
auto zoneid = std::to_string(zone->GetZoneID());
@ -478,27 +502,32 @@ void ZoneDatabase::LoadGlobalLoot()
auto zones = SplitString(row[10], '|');
auto it = std::find(zones.begin(), zones.end(), zoneid);
if (it == zones.end()) // not in here, skip
if (it == zones.end()) { // not in here, skip
continue;
}
}
GlobalLootEntry e(atoi(row[0]), atoi(row[1]), row[2] ? row[2] : "");
auto min_level = atoi(row[3]);
if (min_level)
if (min_level) {
e.AddRule(GlobalLoot::RuleTypes::LevelMin, min_level);
}
auto max_level = atoi(row[4]);
if (max_level)
if (max_level) {
e.AddRule(GlobalLoot::RuleTypes::LevelMax, max_level);
}
// null is not used
if (row[5])
if (row[5]) {
e.AddRule(GlobalLoot::RuleTypes::Rare, atoi(row[5]));
}
// null is not used
if (row[6])
if (row[6]) {
e.AddRule(GlobalLoot::RuleTypes::Raid, atoi(row[6]));
}
if (row[7]) {
auto races = SplitString(row[7], '|');
@ -522,8 +551,9 @@ void ZoneDatabase::LoadGlobalLoot()
}
// null is not used
if (row[11])
if (row[11]) {
e.AddRule(GlobalLoot::RuleTypes::HotZone, atoi(row[11]));
}
zone->AddGlobalLootEntry(e);
}

View File

@ -90,6 +90,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#else
#include <pthread.h>
#include "../common/unix.h"
#include "../common/content/world_content_service.h"
#endif
volatile bool RunLoops = true;
@ -107,6 +110,7 @@ TaskManager *taskmanager = 0;
NpcScaleManager *npc_scale_manager;
QuestParserCollection *parse = 0;
EQEmuLogSys LogSys;
WorldContentService content_service;
const SPDat_Spell_Struct* spells;
int32 SPDAT_RECORDS = -1;
const ZoneConfig *Config;
@ -392,6 +396,14 @@ int main(int argc, char** argv) {
LogInfo("Initialized dynamic dictionary entries");
}
content_service.SetCurrentExpansion(RuleI(Expansion, CurrentExpansion));
LogInfo(
"Current expansion is [{}] ({})",
content_service.GetCurrentExpansion(),
Expansion::ExpansionName[content_service.GetCurrentExpansion()]
);
#ifdef BOTS
LogInfo("Loading bot commands");
int botretval = bot_command_init();

View File

@ -26,6 +26,7 @@
#include "quest_parser_collection.h"
#include "zonedb.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
#include <iostream>
@ -698,12 +699,18 @@ void ZoneDatabase::UpdateObject(uint32 id, uint32 type, uint32 icon, const Objec
//
Ground_Spawns* ZoneDatabase::LoadGroundSpawns(uint32 zone_id, int16 version, Ground_Spawns* gs) {
std::string query = StringFormat("SELECT max_x, max_y, max_z, "
std::string query = StringFormat(
"SELECT max_x, max_y, max_z, "
"min_x, min_y, heading, name, "
"item, max_allowed, respawn_timer "
"FROM ground_spawns "
"WHERE zoneid = %i AND (version = %u OR version = -1) "
"LIMIT 50", zone_id, version);
"WHERE zoneid = %i AND (version = %u OR version = -1) %s "
"LIMIT 50",
zone_id,
version,
ContentFilterCriteria::apply().c_str()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return gs;

View File

@ -24,6 +24,7 @@
#include "spawngroup.h"
#include "zone.h"
#include "zonedb.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
extern EntityList entity_list;
extern Zone *zone;
@ -209,9 +210,11 @@ bool ZoneDatabase::LoadSpawnGroups(const char *zone_name, uint16 version, SpawnG
spawn2.spawngroupID = spawngroup.ID
AND
spawn2.version = {} and zone = '{}'
{}
),
version,
zone_name
zone_name,
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);

View File

@ -310,6 +310,7 @@
#define WHOALL_NO_RESULTS 5029 //There are no players in EverQuest that match those who filters.
#define TELL_QUEUED_MESSAGE 5045 //You told %1 '%T2. %3'
#define TOLD_NOT_ONLINE 5046 //%1 is not online at this time.
#define ZONING_NO_EXPANSION 5052 //The zone that you are attempting to enter is part of an expansion that you do not yet own. You may need to return to the Login screen and enter an account key for that expansion. If you have received this message in error, please /petition or send an email to EQAccounts@soe.sony.com
#define PETITION_NO_DELETE 5053 //You do not have a petition in the queue.
#define PETITION_DELETED 5054 //Your petition was successfully deleted.
#define ALREADY_IN_RAID 5060 //%1 is already in a raid.

View File

@ -24,6 +24,7 @@
#include "entity.h"
#include "mob.h"
#include "trap.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
/*
@ -399,9 +400,14 @@ void EntityList::ClearTrapPointers()
bool ZoneDatabase::LoadTraps(const char* zonename, int16 version) {
std::string query = StringFormat("SELECT id, x, y, z, effect, effectvalue, effectvalue2, skill, "
std::string query = StringFormat(
"SELECT id, x, y, z, effect, effectvalue, effectvalue2, skill, "
"maxzdiff, radius, chance, message, respawn_time, respawn_var, level, "
"`group`, triggered_number, despawn_when_triggered, undetectable FROM traps WHERE zone='%s' AND version=%u", zonename, version);
"`group`, triggered_number, despawn_when_triggered, undetectable FROM traps WHERE zone='%s' AND version=%u %s",
zonename,
version,
ContentFilterCriteria::apply().c_str()
);
auto results = QueryDatabase(query);
if (!results.Success()) {

View File

@ -56,6 +56,7 @@
#include "npc_scale_manager.h"
#include "../common/data_verification.h"
#include "zone_reload.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
#include <time.h>
#include <ctime>
@ -170,11 +171,14 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
//this really loads the objects into entity_list
bool Zone::LoadZoneObjects()
{
std::string query =
StringFormat("SELECT id, zoneid, xpos, ypos, zpos, heading, itemid, charges, objectname, type, icon, "
std::string query = StringFormat(
"SELECT id, zoneid, xpos, ypos, zpos, heading, itemid, charges, objectname, type, icon, "
"unknown08, unknown10, unknown20, unknown24, unknown76, size, tilt_x, tilt_y, display_name "
"FROM object WHERE zoneid = %i AND (version = %u OR version = -1)",
zoneid, instanceversion);
"FROM object WHERE zoneid = %i AND (version = %u OR version = -1) %s",
zoneid,
instanceversion,
ContentFilterCriteria::apply().c_str()
);
auto results = content_db.QueryDatabase(query);
if (!results.Success()) {
LogError("Error Loading Objects from DB: [{}]",
@ -498,14 +502,35 @@ void Zone::LoadTempMerchantData()
void Zone::LoadNewMerchantData(uint32 merchantid) {
std::list<MerchantList> merlist;
std::string query = StringFormat("SELECT item, slot, faction_required, level_required, alt_currency_cost, "
"classes_required, probability FROM merchantlist WHERE merchantid=%d ORDER BY slot", merchantid);
std::string query = fmt::format(
SQL(
SELECT
item,
slot,
faction_required,
level_required,
alt_currency_cost,
classes_required,
probability
FROM
merchantlist
WHERE
merchantid = {}
{}
ORDER BY
slot
),
merchantid,
ContentFilterCriteria::apply()
);
auto results = content_db.QueryDatabase(query);
if (!results.Success()) {
return;
}
for(auto row = results.begin(); row != results.end(); ++row) {
for (auto row = results.begin(); row != results.end(); ++row) {
MerchantList ml;
ml.id = merchantid;
ml.item = atoul(row[0]);
@ -523,48 +548,65 @@ void Zone::LoadNewMerchantData(uint32 merchantid) {
void Zone::GetMerchantDataForZoneLoad() {
LogInfo("Loading Merchant Lists");
std::string query = StringFormat(
"SELECT "
"DISTINCT ml.merchantid, "
"ml.slot, "
"ml.item, "
"ml.faction_required, "
"ml.level_required, "
"ml.alt_currency_cost, "
"ml.classes_required, "
"ml.probability "
"FROM "
"merchantlist AS ml, "
"npc_types AS nt, "
"spawnentry AS se, "
"spawn2 AS s2 "
"WHERE nt.merchant_id = ml.merchantid AND nt.id = se.npcid "
"AND se.spawngroupid = s2.spawngroupid AND s2.zone = '%s' AND s2.version = %i "
"ORDER BY ml.slot ", GetShortName(), GetInstanceVersion());
std::string query = fmt::format(
SQL (
SELECT
DISTINCT merchantlist.merchantid,
merchantlist.slot,
merchantlist.item,
merchantlist.faction_required,
merchantlist.level_required,
merchantlist.alt_currency_cost,
merchantlist.classes_required,
merchantlist.probability
FROM
merchantlist,
npc_types,
spawnentry,
spawn2
WHERE
npc_types.merchant_id = merchantlist.merchantid
AND npc_types.id = spawnentry.npcid
AND spawnentry.spawngroupid = spawn2.spawngroupid
AND spawn2.zone = '{}'
AND spawn2.version = {}
{}
ORDER BY
merchantlist.slot
),
GetShortName(),
GetInstanceVersion(),
ContentFilterCriteria::apply("merchantlist")
);
auto results = content_db.QueryDatabase(query);
std::map<uint32, std::list<MerchantList> >::iterator cur;
uint32 npcid = 0;
std::map<uint32, std::list<MerchantList> >::iterator merchant_list;
uint32 npc_id = 0;
if (results.RowCount() == 0) {
LogDebug("No Merchant Data found for [{}]", GetShortName());
return;
}
for (auto row = results.begin(); row != results.end(); ++row) {
MerchantList ml;
ml.id = atoul(row[0]);
if (npcid != ml.id) {
cur = merchanttable.find(ml.id);
if (cur == merchanttable.end()) {
MerchantList merchant_list_entry{};
merchant_list_entry.id = atoul(row[0]);
if (npc_id != merchant_list_entry.id) {
merchant_list = merchanttable.find(merchant_list_entry.id);
if (merchant_list == merchanttable.end()) {
std::list<MerchantList> empty;
merchanttable[ml.id] = empty;
cur = merchanttable.find(ml.id);
}
npcid = ml.id;
merchanttable[merchant_list_entry.id] = empty;
merchant_list = merchanttable.find(merchant_list_entry.id);
}
auto iter = cur->second.begin();
npc_id = merchant_list_entry.id;
}
auto iter = merchant_list->second.begin();
bool found = false;
while (iter != cur->second.end()) {
if ((*iter).item == ml.id) {
while (iter != merchant_list->second.end()) {
if ((*iter).item == merchant_list_entry.id) {
found = true;
break;
}
@ -575,14 +617,15 @@ void Zone::GetMerchantDataForZoneLoad() {
continue;
}
ml.slot = atoul(row[1]);
ml.item = atoul(row[2]);
ml.faction_required = atoul(row[3]);
ml.level_required = atoul(row[4]);
ml.alt_currency_cost = atoul(row[5]);
ml.classes_required = atoul(row[6]);
ml.probability = atoul(row[7]);
cur->second.push_back(ml);
merchant_list_entry.slot = atoul(row[1]);
merchant_list_entry.item = atoul(row[2]);
merchant_list_entry.faction_required = atoul(row[3]);
merchant_list_entry.level_required = atoul(row[4]);
merchant_list_entry.alt_currency_cost = atoul(row[5]);
merchant_list_entry.classes_required = atoul(row[6]);
merchant_list_entry.probability = atoul(row[7]);
merchant_list->second.push_back(merchant_list_entry);
}
}
@ -1798,16 +1841,22 @@ ZonePoint* Zone::GetClosestZonePointWithoutZone(float x, float y, float z, Clien
return closest_zp;
}
bool ZoneDatabase::LoadStaticZonePoints(LinkedList<ZonePoint*>* zone_point_list, const char* zonename, uint32 version)
bool ZoneDatabase::LoadStaticZonePoints(LinkedList<ZonePoint *> *zone_point_list, const char *zonename, uint32 version)
{
zone_point_list->Clear();
zone->numzonepoints = 0;
std::string query = StringFormat("SELECT x, y, z, target_x, target_y, "
std::string query = StringFormat(
"SELECT x, y, z, target_x, target_y, "
"target_z, target_zone_id, heading, target_heading, "
"number, target_instance, client_version_mask "
"FROM zone_points WHERE zone='%s' AND (version=%i OR version=-1) "
"FROM zone_points WHERE zone='%s' AND (version=%i OR version=-1) %s"
"ORDER BY number",
zonename, version);
zonename,
version,
ContentFilterCriteria::apply().c_str()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return false;

View File

@ -12,6 +12,7 @@
#include "zone.h"
#include "zonedb.h"
#include "aura.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
#include <ctime>
#include <iostream>
@ -165,8 +166,11 @@ bool ZoneDatabase::GetZoneCFG(
"fast_regen_endurance, " // 59
"npc_max_aggro_dist, " // 60
"max_movement_update_range " // 61
"FROM zone WHERE zoneidnumber = %i AND version = %i",
zoneid, instance_id);
"FROM zone WHERE zoneidnumber = %i AND version = %i %s",
zoneid,
instance_id,
ContentFilterCriteria::apply().c_str()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
strcpy(*map_filename, "default");

View File

@ -35,6 +35,9 @@ extern QueryServ* QServ;
extern WorldServer worldserver;
extern Zone* zone;
#include "../common/repositories/zone_repository.h"
#include "../common/content/world_content_service.h"
void Client::Handle_OP_ZoneChange(const EQApplicationPacket *app) {
#ifdef BOTS
@ -284,6 +287,29 @@ void Client::Handle_OP_ZoneChange(const EQApplicationPacket *app) {
//TODO: ADVENTURE ENTRANCE CHECK
/**
* Expansion check
*/
auto zones = ZoneRepository::GetWhere(
fmt::format(
"expansion <= {} AND short_name = '{}'",
(content_service.GetCurrentExpansion() + 1),
target_zone_name
)
);
LogInfo(
"Checking zone request [{}] for expansion [{}] ({}) success [{}]",
target_zone_name,
(content_service.GetCurrentExpansion() + 1),
Expansion::ExpansionName[content_service.GetCurrentExpansion()],
!zones.empty() ? "true" : "false"
);
if (zones.empty()) {
myerror = ZONE_ERROR_NOEXPANSION;
}
if(myerror == 1) {
//we have successfully zoned
DoZoneSuccess(zc, target_zone_id, target_instance_id, dest_x, dest_y, dest_z, dest_h, ignorerestrictions);