From 7892fed6d9e88d0fdcfe2f859bc6ed464d0741b3 Mon Sep 17 00:00:00 2001 From: Daerath Date: Sun, 21 Jan 2018 10:17:31 -0500 Subject: [PATCH 1/3] * Combine container size is checked before displaying favorite recipes or when searching for a recipe. This fixes an issue where you could combine any recipe in a 2 slot container or in any container smaller than the number of required components. * World containers that do not have ID values default to size 10 based as all world containers that are not transmitting ID values appear to have 10 slots. --- zone/client_packet.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index d336f7f0d..57bd89465 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -11690,10 +11690,15 @@ void Client::Handle_OP_RecipesFavorite(const EQApplicationPacket *app) // make where clause segment for container(s) std::string containers; - if (tsf->some_id == 0) + uint32 combineObjectSlots; + if (tsf->some_id == 0) { containers += StringFormat(" = %u ", tsf->object_type); // world combiner so no item number - else + combineObjectSlots = 10; + } + else { containers += StringFormat(" in (%u, %u) ", tsf->object_type, tsf->some_id); // container in inventory + combineObjectSlots = database.GetItem(tsf->some_id)->BagSlots; + } std::string favoriteIDs; //gotta be big enough for 500 IDs bool first = true; @@ -11725,8 +11730,8 @@ void Client::Handle_OP_RecipesFavorite(const EQApplicationPacket *app) "((tr.must_learn & 0x3 <> 0 AND crl.madecount IS NOT NULL) " "OR (tr.must_learn & 0x3 = 0)) " "GROUP BY tr.id " - "HAVING sum(if(tre.item_id %s AND tre.iscontainer > 0,1,0)) > 0 " - "LIMIT 100 ", CharacterID(), favoriteIDs.c_str(), containers.c_str()); + "HAVING sum(if(tre.item_id %s AND tre.iscontainer > 0,1,0)) > 0 AND SUM(tre.componentcount) <= %u " + "LIMIT 100 ", CharacterID(), favoriteIDs.c_str(), containers.c_str(), combineObjectSlots); TradeskillSearchResults(query, tsf->object_type, tsf->some_id); return; @@ -11748,13 +11753,16 @@ void Client::Handle_OP_RecipesSearch(const EQApplicationPacket *app) // make where clause segment for container(s) char containers[30]; + uint32 combineObjectSlots; if (rss->some_id == 0) { // world combiner so no item number snprintf(containers, 29, "= %u", rss->object_type); + combineObjectSlots = 10; } else { // container in inventory snprintf(containers, 29, "in (%u,%u)", rss->object_type, rss->some_id); + combineObjectSlots = database.GetItem(rss->some_id)->BagSlots; } std::string searchClause; @@ -11779,10 +11787,10 @@ void Client::Handle_OP_RecipesSearch(const EQApplicationPacket *app) "AND crl.madecount IS NOT NULL) " "OR (tr.must_learn & 0x3 = 0)) " "GROUP BY tr.id " - "HAVING sum(if(tre.item_id %s AND tre.iscontainer > 0,1,0)) > 0 " + "HAVING sum(if(tre.item_id %s AND tre.iscontainer > 0,1,0)) > 0 AND SUM(tre.componentcount) <= %u " "LIMIT 200 ", CharacterID(), searchClause.c_str(), - rss->mintrivial, rss->maxtrivial, containers); + rss->mintrivial, rss->maxtrivial, containers, combineObjectSlots); TradeskillSearchResults(query, rss->object_type, rss->some_id); return; } From 518a5e8ab1dfaa2510b6386b5e51e1f3da6e0803 Mon Sep 17 00:00:00 2001 From: Daerath Date: Sun, 21 Jan 2018 15:49:15 -0500 Subject: [PATCH 2/3] * Added test for null output of GetItem and log & return if the item cannot be found. --- zone/client_packet.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 57bd89465..3ee4d0038 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -11697,7 +11697,14 @@ void Client::Handle_OP_RecipesFavorite(const EQApplicationPacket *app) } else { containers += StringFormat(" in (%u, %u) ", tsf->object_type, tsf->some_id); // container in inventory - combineObjectSlots = database.GetItem(tsf->some_id)->BagSlots; + auto item = database.GetItem(tsf->some_id); + if (!item) + { + Log(Logs::General, Logs::Error, "Invalid container ID: %d. GetItem returned null.\n", tsf->some_id); + return; + } + + combineObjectSlots = item->BagSlots; } std::string favoriteIDs; //gotta be big enough for 500 IDs @@ -11762,7 +11769,14 @@ void Client::Handle_OP_RecipesSearch(const EQApplicationPacket *app) else { // container in inventory snprintf(containers, 29, "in (%u,%u)", rss->object_type, rss->some_id); - combineObjectSlots = database.GetItem(rss->some_id)->BagSlots; + auto item = database.GetItem(rss->some_id); + if (!item) + { + Log(Logs::General, Logs::Error, "Invalid container ID: %d. GetItem returned null.\n", rss->some_id); + return; + } + + combineObjectSlots = item->BagSlots; } std::string searchClause; From fbe456ed4563bce4e5ef1156a229d84fb62d5fcd Mon Sep 17 00:00:00 2001 From: Daerath Date: Sun, 21 Jan 2018 17:28:27 -0500 Subject: [PATCH 3/3] * If GetItem returns null when searching for a container item, we now default bagslots to 10 instead of aborting. --- zone/client_packet.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 3ee4d0038..53fa8a27d 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -11700,11 +11700,13 @@ void Client::Handle_OP_RecipesFavorite(const EQApplicationPacket *app) auto item = database.GetItem(tsf->some_id); if (!item) { - Log(Logs::General, Logs::Error, "Invalid container ID: %d. GetItem returned null.\n", tsf->some_id); - return; + Log(Logs::General, Logs::Error, "Invalid container ID: %d. GetItem returned null. Defaulting to BagSlots = 10.\n", tsf->some_id); + combineObjectSlots = 10; + } + else + { + combineObjectSlots = item->BagSlots; } - - combineObjectSlots = item->BagSlots; } std::string favoriteIDs; //gotta be big enough for 500 IDs @@ -11772,11 +11774,13 @@ void Client::Handle_OP_RecipesSearch(const EQApplicationPacket *app) auto item = database.GetItem(rss->some_id); if (!item) { - Log(Logs::General, Logs::Error, "Invalid container ID: %d. GetItem returned null.\n", rss->some_id); - return; + Log(Logs::General, Logs::Error, "Invalid container ID: %d. GetItem returned null. Defaulting to BagSlots = 10.\n", rss->some_id); + combineObjectSlots = 10; + } + else + { + combineObjectSlots = item->BagSlots; } - - combineObjectSlots = item->BagSlots; } std::string searchClause;