From 15684567cf8dd4b99a1e7200f2751cc03fb8ee56 Mon Sep 17 00:00:00 2001 From: Mitch Freeman <65987027+neckkola@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:28:44 -0400 Subject: [PATCH] [Fix] Add Bazaar BulkSendTrader Limit for RoF2 (#4590) Add Bazaar BulkSendTrader Limit --- common/eq_limits.cpp | 20 ++++++++++++++------ common/eq_limits.h | 7 +++++-- common/patches/rof2_limits.h | 1 + common/patches/titanium_limits.h | 4 ++-- common/repositories/trader_repository.h | 9 ++++++--- zone/trading.cpp | 7 ++++++- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/common/eq_limits.cpp b/common/eq_limits.cpp index 051857681..eda4d6a19 100644 --- a/common/eq_limits.cpp +++ b/common/eq_limits.cpp @@ -47,6 +47,7 @@ static const EQ::constants::LookupEntry constants_static_lookup_entries[EQ::vers ClientUnknown::constants::EXPANSION_BIT, ClientUnknown::constants::EXPANSIONS_MASK, ClientUnknown::INULL, + ClientUnknown::INULL, ClientUnknown::INULL ), /*[ClientVersion::Client62] =*/ @@ -55,6 +56,7 @@ static const EQ::constants::LookupEntry constants_static_lookup_entries[EQ::vers Client62::constants::EXPANSION_BIT, Client62::constants::EXPANSIONS_MASK, Client62::INULL, + Client62::INULL, Client62::INULL ), /*[ClientVersion::Titanium] =*/ @@ -63,7 +65,8 @@ static const EQ::constants::LookupEntry constants_static_lookup_entries[EQ::vers Titanium::constants::EXPANSION_BIT, Titanium::constants::EXPANSIONS_MASK, Titanium::constants::CHARACTER_CREATION_LIMIT, - Titanium::constants::SAY_LINK_BODY_SIZE + Titanium::constants::SAY_LINK_BODY_SIZE, + Titanium::INULL ), /*[ClientVersion::SoF] =*/ EQ::constants::LookupEntry( @@ -71,7 +74,8 @@ static const EQ::constants::LookupEntry constants_static_lookup_entries[EQ::vers SoF::constants::EXPANSION_BIT, SoF::constants::EXPANSIONS_MASK, SoF::constants::CHARACTER_CREATION_LIMIT, - SoF::constants::SAY_LINK_BODY_SIZE + SoF::constants::SAY_LINK_BODY_SIZE, + SoF::INULL ), /*[ClientVersion::SoD] =*/ EQ::constants::LookupEntry( @@ -79,7 +83,8 @@ static const EQ::constants::LookupEntry constants_static_lookup_entries[EQ::vers SoD::constants::EXPANSION_BIT, SoD::constants::EXPANSIONS_MASK, SoD::constants::CHARACTER_CREATION_LIMIT, - SoD::constants::SAY_LINK_BODY_SIZE + SoD::constants::SAY_LINK_BODY_SIZE, + SoD::INULL ), /*[ClientVersion::UF] =*/ EQ::constants::LookupEntry( @@ -87,7 +92,8 @@ static const EQ::constants::LookupEntry constants_static_lookup_entries[EQ::vers UF::constants::EXPANSION_BIT, UF::constants::EXPANSIONS_MASK, UF::constants::CHARACTER_CREATION_LIMIT, - UF::constants::SAY_LINK_BODY_SIZE + UF::constants::SAY_LINK_BODY_SIZE, + UF::INULL ), /*[ClientVersion::RoF] =*/ EQ::constants::LookupEntry( @@ -95,7 +101,8 @@ static const EQ::constants::LookupEntry constants_static_lookup_entries[EQ::vers RoF::constants::EXPANSION_BIT, RoF::constants::EXPANSIONS_MASK, RoF::constants::CHARACTER_CREATION_LIMIT, - RoF::constants::SAY_LINK_BODY_SIZE + RoF::constants::SAY_LINK_BODY_SIZE, + RoF::INULL ), /*[ClientVersion::RoF2] =*/ EQ::constants::LookupEntry( @@ -103,7 +110,8 @@ static const EQ::constants::LookupEntry constants_static_lookup_entries[EQ::vers RoF2::constants::EXPANSION_BIT, RoF2::constants::EXPANSIONS_MASK, RoF2::constants::CHARACTER_CREATION_LIMIT, - RoF2::constants::SAY_LINK_BODY_SIZE + RoF2::constants::SAY_LINK_BODY_SIZE, + RoF2::constants::MAX_BAZAAR_TRADERS ) }; diff --git a/common/eq_limits.h b/common/eq_limits.h index 40b095b15..fed765207 100644 --- a/common/eq_limits.h +++ b/common/eq_limits.h @@ -42,6 +42,7 @@ namespace EQ uint32 ExpansionsMask; int16 CharacterCreationLimit; size_t SayLinkBodySize; + uint32 BazaarTraderLimit; LookupEntry(const LookupEntry *lookup_entry) { } LookupEntry( @@ -49,13 +50,15 @@ namespace EQ uint32 ExpansionBit, uint32 ExpansionsMask, int16 CharacterCreationLimit, - size_t SayLinkBodySize + size_t SayLinkBodySize, + uint32 BazaarTraderLimit ) : Expansion(Expansion), ExpansionBit(ExpansionBit), ExpansionsMask(ExpansionsMask), CharacterCreationLimit(CharacterCreationLimit), - SayLinkBodySize(SayLinkBodySize) + SayLinkBodySize(SayLinkBodySize), + BazaarTraderLimit(BazaarTraderLimit) { } }; diff --git a/common/patches/rof2_limits.h b/common/patches/rof2_limits.h index 7e7774de6..a2fe623e0 100644 --- a/common/patches/rof2_limits.h +++ b/common/patches/rof2_limits.h @@ -272,6 +272,7 @@ namespace RoF2 const size_t SAY_LINK_BODY_SIZE = 56; const uint32 MAX_GUILD_ID = 50000; + const uint32 MAX_BAZAAR_TRADERS = 600; } /*constants*/ diff --git a/common/patches/titanium_limits.h b/common/patches/titanium_limits.h index cdd3171f4..cd7d9e5d8 100644 --- a/common/patches/titanium_limits.h +++ b/common/patches/titanium_limits.h @@ -286,8 +286,8 @@ namespace Titanium const size_t CHARACTER_CREATION_LIMIT = 8; // Hard-coded in client - DO NOT ALTER - const size_t SAY_LINK_BODY_SIZE = 45; - const uint32 MAX_GUILD_ID = 1500; + const size_t SAY_LINK_BODY_SIZE = 45; + const uint32 MAX_GUILD_ID = 1500; } /*constants*/ diff --git a/common/repositories/trader_repository.h b/common/repositories/trader_repository.h index b27363811..2999b738a 100644 --- a/common/repositories/trader_repository.h +++ b/common/repositories/trader_repository.h @@ -40,15 +40,18 @@ public: int32 char_zone_instance_id ); - static BulkTraders_Struct GetDistinctTraders(Database &db) + static BulkTraders_Struct GetDistinctTraders(Database &db, uint32 char_zone_instance_id, uint32 max_results) { BulkTraders_Struct all_entries{}; std::vector distinct_traders; - auto results = db.QueryDatabase( + auto results = db.QueryDatabase(fmt::format( "SELECT DISTINCT(t.char_id), t.char_zone_id, t.char_zone_instance_id, t.char_entity_id, c.name " "FROM trader AS t " - "JOIN character_data AS c ON t.char_id = c.id;" + "JOIN character_data AS c ON t.char_id = c.id " + "ORDER BY t.char_zone_instance_id = {} DESC LIMIT {};", + char_zone_instance_id, + max_results) ); distinct_traders.reserve(results.RowCount()); diff --git a/zone/trading.cpp b/zone/trading.cpp index 4be42c099..785fd2aec 100644 --- a/zone/trading.cpp +++ b/zone/trading.cpp @@ -3219,7 +3219,12 @@ void Client::SendBulkBazaarTraders() return; } - auto results = TraderRepository::GetDistinctTraders(database); + auto results = TraderRepository::GetDistinctTraders( + database, + GetInstanceID(), + EQ::constants::StaticLookup(ClientVersion())->BazaarTraderLimit + ); + auto p_size = 4 + 12 * results.count + results.name_length; auto buffer = std::make_unique(p_size); memset(buffer.get(), 0, p_size);