Decouple temporary merchant list call [skip ci]

This commit is contained in:
Akkadius 2020-03-30 21:32:59 -05:00
parent 43716332aa
commit 79dbddd56e
7 changed files with 115 additions and 73 deletions

View File

@ -472,21 +472,16 @@ void Database::AssignRaidToInstance(uint32 raid_id, uint32 instance_id)
} }
void Database::BuryCorpsesInInstance(uint16 instance_id) { void Database::BuryCorpsesInInstance(uint16 instance_id) {
std::string query = StringFormat( QueryDatabase(
"UPDATE `character_corpses` " fmt::format(
"SET `is_buried` = 1, " "UPDATE character_corpses SET is_buried = 1, instance_id = 0 WHERE instance_id = {}",
"`instance_id` = 0 "
"WHERE "
"`instance_id` = %u ",
instance_id instance_id
)
); );
auto results = QueryDatabase(query);
} }
void Database::DeleteInstance(uint16 instance_id) void Database::DeleteInstance(uint16 instance_id)
{ {
// TODO: BOUNDARY REWRITE
std::string query = StringFormat("DELETE FROM instance_list WHERE id=%u", instance_id); std::string query = StringFormat("DELETE FROM instance_list WHERE id=%u", instance_id);
QueryDatabase(query); QueryDatabase(query);

View File

@ -115,6 +115,7 @@ namespace Logs {
Flee, Flee,
Aura, Aura,
HotReload, HotReload,
Merchants,
MaxCategoryID /* Don't Remove this */ MaxCategoryID /* Don't Remove this */
}; };
@ -189,6 +190,7 @@ namespace Logs {
"Flee", "Flee",
"Aura", "Aura",
"HotReload", "HotReload",
"Merchants",
}; };
} }

View File

@ -571,6 +571,16 @@
OutF(LogSys, Logs::Detail, Logs::HotReload, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\ OutF(LogSys, Logs::Detail, Logs::HotReload, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0) } while (0)
#define LogMerchants(message, ...) do {\
if (LogSys.log_settings[Logs::Merchants].is_category_enabled == 1)\
OutF(LogSys, Logs::General, Logs::Merchants, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define LogMerchantsDetail(message, ...) do {\
if (LogSys.log_settings[Logs::Merchants].is_category_enabled == 1)\
OutF(LogSys, Logs::Detail, Logs::Merchants, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define Log(debug_level, log_category, message, ...) do {\ #define Log(debug_level, log_category, message, ...) do {\
if (LogSys.log_settings[log_category].is_category_enabled == 1)\ if (LogSys.log_settings[log_category].is_category_enabled == 1)\
LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\ LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
@ -910,6 +920,12 @@
#define LogHotReloadDetail(message, ...) do {\ #define LogHotReloadDetail(message, ...) do {\
} while (0) } while (0)
#define LogMerchants(message, ...) do {\
} while (0)
#define LogMerchantsDetail(message, ...) do {\
} while (0)
#define Log(debug_level, log_category, message, ...) do {\ #define Log(debug_level, log_category, message, ...) do {\
} while (0) } while (0)

View File

@ -480,7 +480,7 @@ bool ZoneDatabase::PopulateZoneSpawnListClose(uint32 zoneid, LinkedList<Spawn2*>
zone_name, zone_name,
version version
); );
results = QueryDatabase(query); results = database.QueryDatabase(query);
if (!results.Success()) { if (!results.Success()) {
return false; return false;
@ -547,7 +547,7 @@ bool ZoneDatabase::PopulateZoneSpawnList(uint32 zoneid, LinkedList<Spawn2*> &spa
"WHERE instance_id = %u", "WHERE instance_id = %u",
zone->GetInstanceID() zone->GetInstanceID()
); );
auto results = QueryDatabase(spawn_query); auto results = database.QueryDatabase(spawn_query);
for (auto row = results.begin(); row != results.end(); ++row) { for (auto row = results.begin(); row != results.end(); ++row) {
uint32 start_duration = atoi(row[1]) > 0 ? atoi(row[1]) : 0; uint32 start_duration = atoi(row[1]) > 0 ? atoi(row[1]) : 0;
uint32 end_duration = atoi(row[2]) > 0 ? atoi(row[2]) : 0; uint32 end_duration = atoi(row[2]) > 0 ? atoi(row[2]) : 0;
@ -989,7 +989,7 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
query = StringFormat("SELECT id, value FROM spawn_condition_values " query = StringFormat("SELECT id, value FROM spawn_condition_values "
"WHERE zone = '%s' AND instance_id = %u", "WHERE zone = '%s' AND instance_id = %u",
zone_name, instance_id); zone_name, instance_id);
results = content_db.QueryDatabase(query); results = database.QueryDatabase(query);
if (!results.Success()) { if (!results.Success()) {
spawn_conditions.clear(); spawn_conditions.clear();
return false; return false;

View File

@ -575,7 +575,7 @@ void NPC::AssignWaypoints(int32 grid_id, int start_wp)
Waypoints.clear(); Waypoints.clear();
roamer = false; roamer = false;
auto grid_entry = GridRepository::GetGrid(zone->grids, grid_id); auto grid_entry = GridRepository::GetGrid(zone->zone_grids, grid_id);
if (grid_entry.id == 0) { if (grid_entry.id == 0) {
return; return;
} }
@ -588,7 +588,7 @@ void NPC::AssignWaypoints(int32 grid_id, int start_wp)
roamer = true; roamer = true;
max_wp = 0; // Initialize it; will increment it for each waypoint successfully added to the list max_wp = 0; // Initialize it; will increment it for each waypoint successfully added to the list
for (auto &entry : zone->grid_entries) { for (auto &entry : zone->zone_grid_entries) {
if (entry.gridid == grid_id) { if (entry.gridid == grid_id) {
wplist new_waypoint{}; wplist new_waypoint{};
new_waypoint.index = max_wp; new_waypoint.index = max_wp;

View File

@ -419,48 +419,79 @@ uint32 Zone::GetTempMerchantQuantity(uint32 NPCID, uint32 Slot) {
return 0; return 0;
} }
void Zone::LoadTempMerchantData() { void Zone::LoadTempMerchantData()
{
LogInfo("Loading Temporary Merchant Lists"); LogInfo("Loading Temporary Merchant Lists");
std::string query = StringFormat(
"SELECT " auto results = content_db.QueryDatabase(
"DISTINCT ml.npcid, " fmt::format(
"ml.slot, " SQL(
"ml.charges, " SELECT
"ml.itemid " DISTINCT npc_types.id
"FROM " FROM
"merchantlist_temp ml, " npc_types
"spawnentry se, " JOIN spawnentry ON spawnentry.npcID = npc_types.id
"spawn2 s2 " JOIN spawn2 ON spawn2.spawngroupID = spawnentry.spawngroupID
"WHERE " WHERE
"ml.npcid = se.npcid " spawn2.zone = '{}'
"AND se.spawngroupid = s2.spawngroupid " AND spawn2.version = {}
"AND s2.zone = '%s' AND s2.version = %i " ),
"ORDER BY ml.slot ", GetShortName(), GetInstanceVersion()); GetShortName(),
auto results = content_db.QueryDatabase(query); GetInstanceVersion()
if (!results.Success()) { )
return; );
}
std::map<uint32, std::list<TempMerchantList> >::iterator cur; std::vector<std::string> npc_ids;
uint32 npcid = 0;
for (auto row = results.begin(); row != results.end(); ++row) { for (auto row = results.begin(); row != results.end(); ++row) {
TempMerchantList ml; npc_ids.push_back(row[0]);
ml.npcid = atoul(row[0]); }
if (npcid != ml.npcid){
cur = tmpmerchanttable.find(ml.npcid); results = database.QueryDatabase(
if (cur == tmpmerchanttable.end()) { fmt::format(
SQL(
npcid,
slot,
charges,
itemid
FROM merchantlist_temp
WHERE npcid IN ({})
),
implode(", ", npc_ids)
)
);
std::map<uint32, std::list<TempMerchantList> >::iterator temp_merchant_table_entry;
uint32 npc_id = 0;
for (auto row = results.begin(); row != results.end(); ++row) {
TempMerchantList temp_merchant_list;
temp_merchant_list.npcid = atoul(row[0]);
if (npc_id != temp_merchant_list.npcid) {
temp_merchant_table_entry = tmpmerchanttable.find(temp_merchant_list.npcid);
if (temp_merchant_table_entry == tmpmerchanttable.end()) {
std::list<TempMerchantList> empty; std::list<TempMerchantList> empty;
tmpmerchanttable[ml.npcid] = empty; tmpmerchanttable[temp_merchant_list.npcid] = empty;
cur = tmpmerchanttable.find(ml.npcid); temp_merchant_table_entry = tmpmerchanttable.find(temp_merchant_list.npcid);
} }
npcid = ml.npcid; npc_id = temp_merchant_list.npcid;
} }
ml.slot = atoul(row[1]);
ml.charges = atoul(row[2]); temp_merchant_list.slot = atoul(row[1]);
ml.item = atoul(row[3]); temp_merchant_list.charges = atoul(row[2]);
ml.origslot = ml.slot; temp_merchant_list.item = atoul(row[3]);
cur->second.push_back(ml); temp_merchant_list.origslot = temp_merchant_list.slot;
LogMerchants(
"[LoadTempMerchantData] Loading merchant temp items npc_id [{}] slot [{}] charges [{}] item [{}] origslot [{}]",
npc_id,
temp_merchant_list.slot,
temp_merchant_list.charges,
temp_merchant_list.item,
temp_merchant_list.origslot
);
temp_merchant_table_entry->second.push_back(temp_merchant_list);
} }
pQueuedMerchantsWorkID = 0;
} }
void Zone::LoadNewMerchantData(uint32 merchantid) { void Zone::LoadNewMerchantData(uint32 merchantid) {
@ -807,7 +838,6 @@ Zone::Zone(uint32 in_zoneid, uint32 in_instanceid, const char* in_short_name)
pgraveyard_id = 0; pgraveyard_id = 0;
pgraveyard_zoneid = 0; pgraveyard_zoneid = 0;
pMaxClients = 0; pMaxClients = 0;
pQueuedMerchantsWorkID = 0;
pvpzone = false; pvpzone = false;
if(database.GetServerType() == 1) if(database.GetServerType() == 1)
pvpzone = true; pvpzone = true;
@ -909,14 +939,16 @@ bool Zone::Init(bool iStaticZone) {
SetStaticZone(iStaticZone); SetStaticZone(iStaticZone);
//load the zone config file. //load the zone config file.
if (!LoadZoneCFG(zone->GetShortName(), zone->GetInstanceVersion())) // try loading the zone name... if (!LoadZoneCFG(zone->GetShortName(), zone->GetInstanceVersion())) { // try loading the zone name...
LoadZoneCFG(zone->GetFileName(), zone->GetInstanceVersion()); // if that fails, try the file name, then load defaults LoadZoneCFG(
zone->GetFileName(),
zone->GetInstanceVersion()
);
} // if that fails, try the file name, then load defaults
if(RuleManager::Instance()->GetActiveRulesetID() != default_ruleset) if (RuleManager::Instance()->GetActiveRulesetID() != default_ruleset) {
{
std::string r_name = RuleManager::Instance()->GetRulesetName(&database, default_ruleset); std::string r_name = RuleManager::Instance()->GetRulesetName(&database, default_ruleset);
if(r_name.size() > 0) if (r_name.size() > 0) {
{
RuleManager::Instance()->LoadRules(&database, r_name.c_str(), false); RuleManager::Instance()->LoadRules(&database, r_name.c_str(), false);
} }
} }
@ -980,7 +1012,6 @@ bool Zone::Init(bool iStaticZone) {
LogInfo("Flushing old respawn timers"); LogInfo("Flushing old respawn timers");
database.QueryDatabase("DELETE FROM `respawn_times` WHERE (`start` + `duration`) < UNIX_TIMESTAMP(NOW())"); database.QueryDatabase("DELETE FROM `respawn_times` WHERE (`start` + `duration`) < UNIX_TIMESTAMP(NOW())");
//load up the zone's doors (prints inside)
zone->LoadZoneDoors(zone->GetShortName(), zone->GetInstanceVersion()); zone->LoadZoneDoors(zone->GetShortName(), zone->GetInstanceVersion());
zone->LoadZoneBlockedSpells(zone->GetZoneID()); zone->LoadZoneBlockedSpells(zone->GetZoneID());
@ -2487,6 +2518,6 @@ void Zone::SetQuestHotReloadQueued(bool in_quest_hot_reload_queued)
void Zone::LoadGrids() void Zone::LoadGrids()
{ {
grids = GridRepository::GetZoneGrids(GetZoneID()); zone_grids = GridRepository::GetZoneGrids(GetZoneID());
grid_entries = GridEntriesRepository::GetZoneGridEntries(GetZoneID()); zone_grid_entries = GridEntriesRepository::GetZoneGridEntries(GetZoneID());
} }

View File

@ -205,8 +205,8 @@ public:
std::unordered_map<int, std::unique_ptr<AA::Ability>> aa_abilities; std::unordered_map<int, std::unique_ptr<AA::Ability>> aa_abilities;
std::unordered_map<int, std::unique_ptr<AA::Rank>> aa_ranks; std::unordered_map<int, std::unique_ptr<AA::Rank>> aa_ranks;
std::vector<GridRepository::Grid> grids; std::vector<GridRepository::Grid> zone_grids;
std::vector<GridEntriesRepository::GridEntry> grid_entries; std::vector<GridEntriesRepository::GridEntry> zone_grid_entries;
time_t weather_timer; time_t weather_timer;
Timer spawn2_timer; Timer spawn2_timer;
@ -372,8 +372,6 @@ private:
uint32 pMaxClients; uint32 pMaxClients;
uint32 zoneid; uint32 zoneid;
uint32 m_last_ucss_update; uint32 m_last_ucss_update;
uint32 pQueuedMerchantsWorkID;
uint32 pQueuedTempMerchantsWorkID;
GlobalLootManager m_global_loot; GlobalLootManager m_global_loot;
LinkedList<ZoneClientAuth_Struct *> client_auth_list; LinkedList<ZoneClientAuth_Struct *> client_auth_list;