diff --git a/common/database.cpp b/common/database.cpp index 0acf77cd6..69c86c575 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -77,6 +77,7 @@ #include "zone_store.h" #include "repositories/merchantlist_temp_repository.h" #include "repositories/bot_data_repository.h" +#include "repositories/trader_repository.h" extern Client client; @@ -2104,3 +2105,8 @@ void Database::ClearGuildOnlineStatus() { GuildMembersRepository::ClearOnlineStatus(*this); } + +void Database::ClearTraderDetails() +{ + TraderRepository::Truncate(*this); +} diff --git a/common/database.h b/common/database.h index d4078e815..0e0f488aa 100644 --- a/common/database.h +++ b/common/database.h @@ -244,6 +244,7 @@ public: void PurgeAllDeletedDataBuckets(); void ClearGuildOnlineStatus(); + void ClearTraderDetails(); /* Database Variables */ diff --git a/world/world_boot.cpp b/world/world_boot.cpp index ec3af8b33..695c81f21 100644 --- a/world/world_boot.cpp +++ b/world/world_boot.cpp @@ -289,6 +289,8 @@ bool WorldBoot::DatabaseLoadRoutines(int argc, char **argv) LogInfo("Clearing inventory snapshots"); database.ClearInvSnapshots(); LogInfo("Loading items"); + LogInfo("Clearing trader table details"); + database.ClearTraderDetails(); if (!content_db.LoadItems(hotfix_name)) { LogError("Error: Could not load item data. But ignoring"); diff --git a/zone/trading.cpp b/zone/trading.cpp index 33b9ac31b..114b3c321 100644 --- a/zone/trading.cpp +++ b/zone/trading.cpp @@ -41,7 +41,7 @@ extern QueryServ* QServ; // The maximum amount of a single bazaar/barter transaction expressed in copper. // Equivalent to 2 Million plat -#define MAX_TRANSACTION_VALUE 2000000000 +constexpr auto MAX_TRANSACTION_VALUE = 2000000000; // ########################################## // Trade implementation // ########################################## @@ -1048,12 +1048,12 @@ void Client::TraderStartTrader(const EQApplicationPacket *app) std::vector trader_items{}; //Check inventory for no-trade items - for (auto const &i: inv->serial_number) { - if (i <= 0) { + for (auto i = 0; i < max_items; i++) { + if (inv->items[i] == 0 || inv->serial_number[i] == 0) { continue; } - auto inst = FindTraderItemBySerialNumber(i); + auto inst = FindTraderItemBySerialNumber(inv->serial_number[i]); if (inst) { if (inst->GetItem() && inst->GetItem()->NoDrop == 0) { Message( @@ -1320,7 +1320,7 @@ GetItems_Struct *Client::GetTraderItems() { const EQ::ItemInstance *item = nullptr; int16 slot_id = INVALID_INDEX; - auto gis = new GetItems_Struct; + auto gis = new GetItems_Struct{0}; uint8 ndx = 0; for (int16 i = EQ::invslot::GENERAL_BEGIN; i <= EQ::invslot::GENERAL_END; i++) { @@ -1338,7 +1338,7 @@ GetItems_Struct *Client::GetTraderItems() item = GetInv().GetItem(slot_id); if (item) { - gis->items[ndx] = item->GetItem()->ID; + gis->items[ndx] = item->GetID(); gis->serial_number[ndx] = item->GetSerialNumber(); gis->charges[ndx] = item->GetCharges() == 0 ? 1 : item->GetCharges(); ndx++; @@ -2044,7 +2044,7 @@ void Client::SendBazaarResults( int Count = 0; uint32 StatValue = 0; - for (auto row = results.begin(); row != results.end(); ++row) { + for (auto &row = results.begin(); row != results.end(); ++row) { VARSTRUCT_ENCODE_TYPE(uint32, bufptr, Action); Count = Strings::ToInt(row[0]); VARSTRUCT_ENCODE_TYPE(uint32, bufptr, Count); @@ -2304,7 +2304,7 @@ void Client::SendBuyerResults(char* searchString, uint32 searchID) { uint32 lastCharID = 0; Client *buyer = nullptr; - for (auto row = results.begin(); row != results.end(); ++row) { + for (auto &row = results.begin(); row != results.end(); ++row) { char itemName[64]; uint32 charID = Strings::ToInt(row[0]); @@ -2407,7 +2407,7 @@ void Client::ShowBuyLines(const EQApplicationPacket *app) { if (!results.Success() || results.RowCount() == 0) return; - for (auto row = results.begin(); row != results.end(); ++row) { + for (auto &row = results.begin(); row != results.end(); ++row) { char ItemName[64]; uint32 BuySlot = Strings::ToInt(row[1]); uint32 ItemID = Strings::ToInt(row[2]); @@ -3309,7 +3309,7 @@ void Client::DoBazaarInspect(const BazaarInspect_Struct &in) return; } - auto item = items.front(); + auto &item = items.front(); std::unique_ptr inst( database.CreateItem(