mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-03 01:06:36 +00:00
Merge branch 'master' into bot-rewrite
This commit is contained in:
+1
-2
@@ -352,7 +352,6 @@ public:
|
||||
const char *message9 = nullptr);
|
||||
void Tell_StringID(uint32 string_id, const char *who, const char *message);
|
||||
void SendColoredText(uint32 color, std::string message);
|
||||
void SendBazaarResults(uint32 trader_id, uint32 in_class, uint32 in_race, uint32 item_stat, uint32 item_slot, uint32 item_type, char item_name[64], uint32 min_price, uint32 max_price);
|
||||
void SendTraderItem(uint32 item_id,uint16 quantity, TraderRepository::Trader &trader);
|
||||
void DoBazaarSearch(BazaarSearchCriteria_Struct search_criteria);
|
||||
uint16 FindTraderItem(int32 SerialNumber,uint16 Quantity);
|
||||
@@ -1188,7 +1187,7 @@ public:
|
||||
void Escape(); //keep or quest function
|
||||
void DisenchantSummonedBags(bool client_update = true);
|
||||
void RemoveNoRent(bool client_update = true);
|
||||
void RemoveDuplicateLore(bool client_update = true);
|
||||
void RemoveDuplicateLore();
|
||||
void MoveSlotNotAllowed(bool client_update = true);
|
||||
virtual bool RangedAttack(Mob* other, bool CanDoubleAttack = false);
|
||||
virtual void ThrowingAttack(Mob* other, bool CanDoubleAttack = false);
|
||||
|
||||
+11
-6
@@ -3260,11 +3260,11 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
|
||||
if (!new_aug) { // Shouldn't get the OP code without the augment on the user's cursor, but maybe it's h4x.
|
||||
LogError("AugmentItem OpCode with 'Insert' or 'Swap' action received, but no augment on client's cursor");
|
||||
Message(Chat::Red, "Error: No augment found on cursor for inserting.");
|
||||
return;
|
||||
break;
|
||||
} else {
|
||||
if (!RuleB(Inventory, AllowMultipleOfSameAugment) && tobe_auged->ContainsAugmentByID(new_aug->GetID())) {
|
||||
Message(Chat::Red, "Error: Cannot put multiple of the same augment in an item.");
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -3348,7 +3348,7 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
|
||||
in_augment->augment_index
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
item_one_to_push = tobe_auged->Clone();
|
||||
@@ -3420,7 +3420,7 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
|
||||
}
|
||||
} else {
|
||||
Message(Chat::Red, "Error: Could not find augmentation to remove at index %i. Aborting.", in_augment->augment_index);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
old_aug = tobe_auged->RemoveAugment(in_augment->augment_index);
|
||||
@@ -3453,7 +3453,7 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
|
||||
if (!PutItemInInventory(EQ::invslot::slotCursor, *item_two_to_push, true)) {
|
||||
LogError("Problem returning augment to player's cursor after safe removal");
|
||||
Message(Chat::Yellow, "Error: Failed to return augment after removal from item!");
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -3498,7 +3498,7 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
|
||||
in_augment->augment_index
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
tobe_auged->DeleteAugment(in_augment->augment_index);
|
||||
@@ -3519,6 +3519,7 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
|
||||
if (material != EQ::textures::materialInvalid) {
|
||||
SendWearChange(material);
|
||||
}
|
||||
|
||||
break;
|
||||
default: // Unknown
|
||||
LogInventory(
|
||||
@@ -3532,9 +3533,12 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
|
||||
);
|
||||
break;
|
||||
}
|
||||
safe_delete(item_one_to_push);
|
||||
safe_delete(item_two_to_push);
|
||||
} else {
|
||||
Object::HandleAugmentation(this, in_augment, m_tradeskill_object); // Delegate to tradeskill object to perform combine
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10896,6 +10900,7 @@ void Client::Handle_OP_MoveMultipleItems(const EQApplicationPacket *app)
|
||||
InterrogateInventory(this, true, false, true, error);
|
||||
}
|
||||
}
|
||||
safe_delete(mi);
|
||||
}
|
||||
// This is the swap.
|
||||
// Client behavior is just to move stacks without combining them
|
||||
|
||||
@@ -770,7 +770,7 @@ void Client::BulkSendInventoryItems()
|
||||
RemoveNoRent(false);
|
||||
}
|
||||
|
||||
RemoveDuplicateLore(false);
|
||||
RemoveDuplicateLore();
|
||||
MoveSlotNotAllowed(false);
|
||||
|
||||
EQ::OutBuffer ob;
|
||||
|
||||
+116
-27
@@ -1,12 +1,15 @@
|
||||
#include "data_bucket.h"
|
||||
#include "entity.h"
|
||||
#include "zonedb.h"
|
||||
#include "mob.h"
|
||||
#include "worldserver.h"
|
||||
#include <ctime>
|
||||
#include <cctype>
|
||||
#include "../common/json/json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
extern WorldServer worldserver;
|
||||
const std::string NESTED_KEY_DELIMITER = ".";
|
||||
|
||||
std::vector<DataBucketsRepository::DataBuckets> g_data_bucket_cache = {};
|
||||
|
||||
@@ -25,8 +28,13 @@ void DataBucket::SetData(const std::string &bucket_key, const std::string &bucke
|
||||
DataBucket::SetData(k);
|
||||
}
|
||||
|
||||
void DataBucket::SetData(const DataBucketKey &k)
|
||||
void DataBucket::SetData(const DataBucketKey &k_)
|
||||
{
|
||||
DataBucketKey k = k_; // copy the key so we can modify it
|
||||
if (k.key.find(NESTED_KEY_DELIMITER) != std::string::npos) {
|
||||
k.key = Strings::Split(k.key, NESTED_KEY_DELIMITER).front();
|
||||
}
|
||||
|
||||
auto b = DataBucketsRepository::NewEntity();
|
||||
auto r = GetData(k, true);
|
||||
// if we have an entry, use it
|
||||
@@ -60,9 +68,48 @@ void DataBucket::SetData(const DataBucketKey &k)
|
||||
|
||||
b.expires = expires_time_unix;
|
||||
b.value = k.value;
|
||||
b.key_ = k.key;
|
||||
|
||||
// Check for nested keys (keys with dots)
|
||||
if (k_.key.find(NESTED_KEY_DELIMITER) != std::string::npos) {
|
||||
// Retrieve existing JSON or create a new one
|
||||
std::string existing_value = r.id > 0 ? r.value : "{}";
|
||||
json json_value = json::object();
|
||||
|
||||
try {
|
||||
json_value = json::parse(existing_value);
|
||||
} catch (json::parse_error &e) {
|
||||
LogError("Failed to parse JSON for key [{}]: {}", k_.key, e.what());
|
||||
json_value = json::object(); // Reset to an empty object on error
|
||||
}
|
||||
|
||||
// Recursively merge new key-value pair into the JSON object
|
||||
auto nested_keys = Strings::Split(k_.key, NESTED_KEY_DELIMITER);
|
||||
json *current = &json_value;
|
||||
|
||||
for (size_t i = 0; i < nested_keys.size(); ++i) {
|
||||
const std::string &key_part = nested_keys[i];
|
||||
if (i == nested_keys.size() - 1) {
|
||||
// Set the value at the final key
|
||||
(*current)[key_part] = k_.value;
|
||||
} else {
|
||||
// Traverse or create nested objects
|
||||
if (!current->contains(key_part)) {
|
||||
(*current)[key_part] = json::object();
|
||||
} else if (!(*current)[key_part].is_object()) {
|
||||
// If key exists but is not an object, reset to object to avoid conflicts
|
||||
(*current)[key_part] = json::object();
|
||||
}
|
||||
current = &(*current)[key_part];
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize JSON back to string
|
||||
b.value = json_value.dump();
|
||||
b.key_ = nested_keys.front(); // Use the top-level key
|
||||
}
|
||||
|
||||
if (bucket_id) {
|
||||
|
||||
// update the cache if it exists
|
||||
if (CanCache(k)) {
|
||||
for (auto &e: g_data_bucket_cache) {
|
||||
@@ -76,7 +123,6 @@ void DataBucket::SetData(const DataBucketKey &k)
|
||||
DataBucketsRepository::UpdateOne(database, b);
|
||||
}
|
||||
else {
|
||||
b.key_ = k.key;
|
||||
b = DataBucketsRepository::InsertOne(database, b);
|
||||
|
||||
// add to cache if it doesn't exist
|
||||
@@ -92,12 +138,56 @@ std::string DataBucket::GetData(const std::string &bucket_key)
|
||||
return GetData(DataBucketKey{.key = bucket_key}).value;
|
||||
}
|
||||
|
||||
DataBucketsRepository::DataBuckets DataBucket::ExtractNestedValue(
|
||||
const DataBucketsRepository::DataBuckets &bucket,
|
||||
const std::string &full_key)
|
||||
{
|
||||
auto nested_keys = Strings::Split(full_key, NESTED_KEY_DELIMITER);
|
||||
json json_value;
|
||||
|
||||
try {
|
||||
json_value = json::parse(bucket.value); // Parse the JSON
|
||||
} catch (json::parse_error &ex) {
|
||||
LogError("Failed to parse JSON for key [{}]: {}", bucket.key_, ex.what());
|
||||
return DataBucketsRepository::NewEntity(); // Return empty entity on parse error
|
||||
}
|
||||
|
||||
// Start from the top-level key (e.g., "progression")
|
||||
json *current = &json_value;
|
||||
|
||||
// Traverse the JSON structure
|
||||
for (const auto &key_part: nested_keys) {
|
||||
LogDataBuckets("Looking for key part [{}] in JSON", key_part);
|
||||
|
||||
if (!current->contains(key_part)) {
|
||||
LogDataBuckets("Key part [{}] not found in JSON for [{}]", key_part, full_key);
|
||||
return DataBucketsRepository::NewEntity();
|
||||
}
|
||||
|
||||
current = &(*current)[key_part];
|
||||
}
|
||||
|
||||
// Create a new entity with the extracted value
|
||||
DataBucketsRepository::DataBuckets result = bucket; // Copy the original bucket
|
||||
result.value = current->is_string() ? current->get<std::string>() : current->dump();
|
||||
return result;
|
||||
}
|
||||
|
||||
// GetData fetches bucket data from the database or cache if it exists
|
||||
// if the bucket doesn't exist, it will be added to the cache as a miss
|
||||
// if ignore_misses_cache is true, the bucket will not be added to the cache as a miss
|
||||
// the only place we should be ignoring the misses cache is on the initial read during SetData
|
||||
DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k, bool ignore_misses_cache)
|
||||
DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k_, bool ignore_misses_cache)
|
||||
{
|
||||
DataBucketKey k = k_; // Copy the key so we can modify it
|
||||
|
||||
bool is_nested_key = k.key.find(NESTED_KEY_DELIMITER) != std::string::npos;
|
||||
|
||||
// Extract the top-level key for nested keys
|
||||
if (is_nested_key) {
|
||||
k.key = Strings::Split(k.key, NESTED_KEY_DELIMITER).front();
|
||||
}
|
||||
|
||||
LogDataBuckets(
|
||||
"Getting bucket key [{}] bot_id [{}] account_id [{}] character_id [{}] npc_id [{}]",
|
||||
k.key,
|
||||
@@ -109,9 +199,9 @@ DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k, b
|
||||
|
||||
bool can_cache = CanCache(k);
|
||||
|
||||
// check the cache first if we can cache
|
||||
// Attempt to retrieve the value from the cache
|
||||
if (can_cache) {
|
||||
for (const auto &e: g_data_bucket_cache) {
|
||||
for (const auto &e : g_data_bucket_cache) {
|
||||
if (CheckBucketMatch(e, k)) {
|
||||
if (e.expires > 0 && e.expires < std::time(nullptr)) {
|
||||
LogDataBuckets("Attempted to read expired key [{}] removing from cache", e.key_);
|
||||
@@ -119,37 +209,32 @@ DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k, b
|
||||
return DataBucketsRepository::NewEntity();
|
||||
}
|
||||
|
||||
// this is a bucket miss, return empty entity
|
||||
// we still cache bucket misses, so we don't have to hit the database
|
||||
if (e.id == 0) {
|
||||
return DataBucketsRepository::NewEntity();
|
||||
LogDataBuckets("Returning key [{}] value [{}] from cache", e.key_, e.value);
|
||||
|
||||
if (is_nested_key) {
|
||||
return ExtractNestedValue(e, k_.key);
|
||||
}
|
||||
|
||||
LogDataBuckets("Returning key [{}] value [{}] from cache", e.key_, e.value);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch the value from the database
|
||||
auto r = DataBucketsRepository::GetWhere(
|
||||
database,
|
||||
fmt::format(
|
||||
"{} `key` = '{}' LIMIT 1",
|
||||
" {} `key` = '{}' LIMIT 1",
|
||||
DataBucket::GetScopedDbFilters(k),
|
||||
k.key
|
||||
)
|
||||
);
|
||||
|
||||
if (r.empty()) {
|
||||
|
||||
// if we're ignoring the misses cache, don't add to the cache
|
||||
// the only place this is ignored is during the initial read of SetData
|
||||
bool add_to_misses_cache = !ignore_misses_cache && can_cache;
|
||||
if (add_to_misses_cache) {
|
||||
// Handle cache misses
|
||||
if (!ignore_misses_cache && can_cache) {
|
||||
size_t size_before = g_data_bucket_cache.size();
|
||||
|
||||
// cache bucket misses, so we don't have to hit the database
|
||||
// when scripts try to read a bucket that doesn't exist
|
||||
g_data_bucket_cache.emplace_back(
|
||||
DataBucketsRepository::DataBuckets{
|
||||
.id = 0,
|
||||
@@ -175,22 +260,21 @@ DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k, b
|
||||
);
|
||||
}
|
||||
|
||||
return {};
|
||||
return DataBucketsRepository::NewEntity();
|
||||
}
|
||||
|
||||
auto bucket = r.front();
|
||||
|
||||
// if the entry has expired, delete it
|
||||
if (bucket.expires > 0 && bucket.expires < (long long) std::time(nullptr)) {
|
||||
// If the entry has expired, delete it
|
||||
if (bucket.expires > 0 && bucket.expires < static_cast<long long>(std::time(nullptr))) {
|
||||
DeleteData(k);
|
||||
return {};
|
||||
return DataBucketsRepository::NewEntity();
|
||||
}
|
||||
|
||||
// add to cache if it doesn't exist
|
||||
// Add the value to the cache if it doesn't exist
|
||||
if (can_cache) {
|
||||
bool has_cache = false;
|
||||
|
||||
for (auto &e: g_data_bucket_cache) {
|
||||
for (const auto &e : g_data_bucket_cache) {
|
||||
if (e.id == bucket.id) {
|
||||
has_cache = true;
|
||||
break;
|
||||
@@ -202,6 +286,11 @@ DataBucketsRepository::DataBuckets DataBucket::GetData(const DataBucketKey &k, b
|
||||
}
|
||||
}
|
||||
|
||||
// Handle nested key extraction
|
||||
if (is_nested_key) {
|
||||
return ExtractNestedValue(bucket, k_.key);
|
||||
}
|
||||
|
||||
return bucket;
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -45,9 +45,9 @@ public:
|
||||
static bool GetDataBuckets(Mob *mob);
|
||||
|
||||
// scoped bucket methods
|
||||
static void SetData(const DataBucketKey &k);
|
||||
static void SetData(const DataBucketKey &k_);
|
||||
static bool DeleteData(const DataBucketKey &k);
|
||||
static DataBucketsRepository::DataBuckets GetData(const DataBucketKey &k, bool ignore_misses_cache = false);
|
||||
static DataBucketsRepository::DataBuckets GetData(const DataBucketKey &k_, bool ignore_misses_cache = false);
|
||||
static std::string GetDataExpires(const DataBucketKey &k);
|
||||
static std::string GetDataRemaining(const DataBucketKey &k);
|
||||
static std::string GetScopedDbFilters(const DataBucketKey &k);
|
||||
@@ -63,6 +63,8 @@ public:
|
||||
static void ClearCache();
|
||||
static void DeleteFromCache(uint64 id, DataBucketLoadType::Type type);
|
||||
static bool CanCache(const DataBucketKey &key);
|
||||
static DataBucketsRepository::DataBuckets
|
||||
ExtractNestedValue(const DataBucketsRepository::DataBuckets &bucket, const std::string &full_key);
|
||||
};
|
||||
|
||||
#endif //EQEMU_DATABUCKET_H
|
||||
|
||||
+1
-1
@@ -612,7 +612,7 @@ void Doors::HandleClick(Client *sender, uint8 trigger)
|
||||
}
|
||||
}
|
||||
|
||||
if (GetOpenType() == 40 && GetZone(GetDoorZone(),0)) {
|
||||
if (GetOpenType() == 40 && sender->GetZoneID() == Zones::CORATHUS) {
|
||||
sender->SendEvolveXPTransferWindow();
|
||||
}
|
||||
}
|
||||
|
||||
+58
-85
@@ -2979,107 +2979,72 @@ void Client::RemoveNoRent(bool client_update)
|
||||
}
|
||||
|
||||
// Two new methods to alleviate perpetual login desyncs
|
||||
void Client::RemoveDuplicateLore(bool client_update)
|
||||
void Client::RemoveDuplicateLore()
|
||||
{
|
||||
for (auto slot_id = EQ::invslot::EQUIPMENT_BEGIN; slot_id <= EQ::invslot::EQUIPMENT_END; ++slot_id) {
|
||||
if ((((uint64)1 << slot_id) & GetInv().GetLookup()->PossessionsBitmask) == 0)
|
||||
for (auto slot_id : GetInventorySlots()) {
|
||||
if ((((uint64) 1 << slot_id) & GetInv().GetLookup()->PossessionsBitmask) == 0) {
|
||||
continue;
|
||||
|
||||
auto inst = m_inv.PopItem(slot_id);
|
||||
if (inst == nullptr) { continue; }
|
||||
if(CheckLoreConflict(inst->GetItem())) {
|
||||
LogInventory("Lore Duplication Error: Deleting [{}] from slot [{}]", inst->GetItem()->Name, slot_id);
|
||||
database.SaveInventory(character_id, nullptr, slot_id);
|
||||
}
|
||||
else {
|
||||
m_inv.PutItem(slot_id, *inst);
|
||||
}
|
||||
safe_delete(inst);
|
||||
}
|
||||
|
||||
for (auto slot_id = EQ::invslot::GENERAL_BEGIN; slot_id <= EQ::invslot::GENERAL_END; ++slot_id) {
|
||||
if ((((uint64)1 << slot_id) & GetInv().GetLookup()->PossessionsBitmask) == 0)
|
||||
// ignore shared bank slots
|
||||
if (slot_id >= EQ::invslot::SHARED_BANK_BEGIN && slot_id <= EQ::invslot::SHARED_BANK_END) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (slot_id >= EQ::invbag::SHARED_BANK_BAGS_BEGIN && slot_id <= EQ::invbag::SHARED_BANK_BAGS_END) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// slot gets handled in a queue
|
||||
if (slot_id == EQ::invslot::slotCursor) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// temporarily move the item off of the slot
|
||||
auto inst = m_inv.PopItem(slot_id);
|
||||
if (inst == nullptr) { continue; }
|
||||
if (!inst) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CheckLoreConflict(inst->GetItem())) {
|
||||
LogInventory("Lore Duplication Error: Deleting [{}] from slot [{}]", inst->GetItem()->Name, slot_id);
|
||||
LogError(
|
||||
"Lore Duplication Error | Deleting [{}] ({}) from slot [{}] client [{}]",
|
||||
inst->GetItem()->Name,
|
||||
inst->GetItem()->ID,
|
||||
slot_id,
|
||||
GetCleanName()
|
||||
);
|
||||
database.SaveInventory(character_id, nullptr, slot_id);
|
||||
safe_delete(inst);
|
||||
}
|
||||
else {
|
||||
m_inv.PutItem(slot_id, *inst);
|
||||
}
|
||||
safe_delete(inst);
|
||||
|
||||
// if no lore conflict, put the item back in the slot
|
||||
m_inv.PushItem(slot_id, inst);
|
||||
}
|
||||
|
||||
for (auto slot_id = EQ::invbag::GENERAL_BAGS_BEGIN; slot_id <= EQ::invbag::CURSOR_BAG_END; ++slot_id) {
|
||||
auto temp_slot = EQ::invslot::GENERAL_BEGIN + ((slot_id - EQ::invbag::GENERAL_BAGS_BEGIN) / EQ::invbag::SLOT_COUNT);
|
||||
if ((((uint64)1 << temp_slot) & GetInv().GetLookup()->PossessionsBitmask) == 0)
|
||||
continue;
|
||||
|
||||
auto inst = m_inv.PopItem(slot_id);
|
||||
if (inst == nullptr) { continue; }
|
||||
if(CheckLoreConflict(inst->GetItem())) {
|
||||
LogInventory("Lore Duplication Error: Deleting [{}] from slot [{}]", inst->GetItem()->Name, slot_id);
|
||||
database.SaveInventory(character_id, nullptr, slot_id);
|
||||
}
|
||||
else {
|
||||
m_inv.PutItem(slot_id, *inst);
|
||||
}
|
||||
safe_delete(inst);
|
||||
}
|
||||
|
||||
for (auto slot_id = EQ::invslot::BANK_BEGIN; slot_id <= EQ::invslot::BANK_END; ++slot_id) {
|
||||
if ((slot_id - EQ::invslot::BANK_BEGIN) >= GetInv().GetLookup()->InventoryTypeSize.Bank)
|
||||
continue;
|
||||
|
||||
auto inst = m_inv.PopItem(slot_id);
|
||||
if (inst == nullptr) { continue; }
|
||||
if(CheckLoreConflict(inst->GetItem())) {
|
||||
LogInventory("Lore Duplication Error: Deleting [{}] from slot [{}]", inst->GetItem()->Name, slot_id);
|
||||
database.SaveInventory(character_id, nullptr, slot_id);
|
||||
}
|
||||
else {
|
||||
m_inv.PutItem(slot_id, *inst);
|
||||
}
|
||||
safe_delete(inst);
|
||||
}
|
||||
|
||||
for (auto slot_id = EQ::invbag::BANK_BAGS_BEGIN; slot_id <= EQ::invbag::BANK_BAGS_END; ++slot_id) {
|
||||
auto temp_slot = (slot_id - EQ::invbag::BANK_BAGS_BEGIN) / EQ::invbag::SLOT_COUNT;
|
||||
if (temp_slot >= GetInv().GetLookup()->InventoryTypeSize.Bank)
|
||||
continue;
|
||||
|
||||
auto inst = m_inv.PopItem(slot_id);
|
||||
if (inst == nullptr) { continue; }
|
||||
if(CheckLoreConflict(inst->GetItem())) {
|
||||
LogInventory("Lore Duplication Error: Deleting [{}] from slot [{}]", inst->GetItem()->Name, slot_id);
|
||||
database.SaveInventory(character_id, nullptr, slot_id);
|
||||
}
|
||||
else {
|
||||
m_inv.PutItem(slot_id, *inst);
|
||||
}
|
||||
safe_delete(inst);
|
||||
}
|
||||
|
||||
// Shared Bank and Shared Bank Containers are not checked due to their allowing duplicate lore items
|
||||
|
||||
if (!m_inv.CursorEmpty()) {
|
||||
std::list<EQ::ItemInstance*> local_1;
|
||||
std::list<EQ::ItemInstance*> local_2;
|
||||
|
||||
while (!m_inv.CursorEmpty()) {
|
||||
auto inst = m_inv.PopItem(EQ::invslot::slotCursor);
|
||||
if (inst == nullptr) { continue; }
|
||||
if (!inst) {
|
||||
continue;
|
||||
}
|
||||
local_1.push_back(inst);
|
||||
}
|
||||
|
||||
for (auto iter = local_1.begin(); iter != local_1.end(); ++iter) {
|
||||
auto inst = *iter;
|
||||
if (inst == nullptr) { continue; }
|
||||
for (auto inst: local_1) {
|
||||
if (!inst) {
|
||||
continue;
|
||||
}
|
||||
if (CheckLoreConflict(inst->GetItem())) {
|
||||
LogInventory("Lore Duplication Error: Deleting [{}] from `Limbo`", inst->GetItem()->Name);
|
||||
LogError(
|
||||
"Lore Duplication Error | Deleting [{}] ({}) from `Limbo` client [{}]",
|
||||
inst->GetItem()->Name,
|
||||
inst->GetItem()->ID,
|
||||
GetCleanName()
|
||||
);
|
||||
safe_delete(inst);
|
||||
}
|
||||
else {
|
||||
@@ -3088,17 +3053,25 @@ void Client::RemoveDuplicateLore(bool client_update)
|
||||
}
|
||||
local_1.clear();
|
||||
|
||||
for (auto iter = local_2.begin(); iter != local_2.end(); ++iter) {
|
||||
auto inst = *iter;
|
||||
if (inst == nullptr) { continue; }
|
||||
for (auto inst: local_2) {
|
||||
if (!inst) {
|
||||
continue;
|
||||
}
|
||||
if (!inst->GetItem()->LoreFlag ||
|
||||
((inst->GetItem()->LoreGroup == -1) && (m_inv.HasItem(inst->GetID(), 0, invWhereCursor) == INVALID_INDEX)) ||
|
||||
(inst->GetItem()->LoreGroup && (~inst->GetItem()->LoreGroup) && (m_inv.HasItemByLoreGroup(inst->GetItem()->LoreGroup, invWhereCursor) == INVALID_INDEX))
|
||||
((inst->GetItem()->LoreGroup == -1) &&
|
||||
(m_inv.HasItem(inst->GetID(), 0, invWhereCursor) == INVALID_INDEX)) ||
|
||||
(inst->GetItem()->LoreGroup && (~inst->GetItem()->LoreGroup) &&
|
||||
(m_inv.HasItemByLoreGroup(inst->GetItem()->LoreGroup, invWhereCursor) == INVALID_INDEX))
|
||||
) {
|
||||
m_inv.PushCursor(*inst);
|
||||
}
|
||||
else {
|
||||
LogInventory("Lore Duplication Error: Deleting [{}] from `Limbo`", inst->GetItem()->Name);
|
||||
LogError(
|
||||
"Lore Duplication Error | Deleting [{}] ({}) from `Limbo` client [{}]",
|
||||
inst->GetItem()->Name,
|
||||
inst->GetItem()->ID,
|
||||
GetCleanName()
|
||||
);
|
||||
}
|
||||
safe_delete(inst);
|
||||
}
|
||||
|
||||
+5
-1
@@ -687,6 +687,7 @@ void NPC::RemoveItem(uint32 item_id, uint16 quantity, uint16 slot)
|
||||
LootItem *item = *cur;
|
||||
if (item->item_id == item_id && slot <= 0 && quantity <= 0) {
|
||||
m_loot_items.erase(cur);
|
||||
safe_delete(item);
|
||||
UpdateEquipmentLight();
|
||||
if (UpdateActiveLight()) { SendAppearancePacket(AppearanceType::Light, GetActiveLightType()); }
|
||||
return;
|
||||
@@ -695,7 +696,10 @@ void NPC::RemoveItem(uint32 item_id, uint16 quantity, uint16 slot)
|
||||
if (item->charges <= quantity) {
|
||||
m_loot_items.erase(cur);
|
||||
UpdateEquipmentLight();
|
||||
if (UpdateActiveLight()) { SendAppearancePacket(AppearanceType::Light, GetActiveLightType()); }
|
||||
if (UpdateActiveLight()) {
|
||||
SendAppearancePacket(AppearanceType::Light, GetActiveLightType());
|
||||
}
|
||||
safe_delete(item);
|
||||
}
|
||||
else {
|
||||
item->charges -= quantity;
|
||||
|
||||
+3
-1
@@ -3449,7 +3449,9 @@ std::string QuestManager::varlink(
|
||||
linker.SetLinkType(EQ::saylink::SayLinkItemInst);
|
||||
linker.SetItemInst(item);
|
||||
|
||||
return linker.GenerateLink();
|
||||
auto link = linker.GenerateLink();
|
||||
safe_delete(item);
|
||||
return link;
|
||||
}
|
||||
|
||||
std::string QuestManager::getitemcomment(uint32 item_id) {
|
||||
|
||||
+8
-313
@@ -1800,7 +1800,13 @@ void Client::SendBarterWelcome()
|
||||
|
||||
void Client::DoBazaarSearch(BazaarSearchCriteria_Struct search_criteria)
|
||||
{
|
||||
auto results = Bazaar::GetSearchResults(database, search_criteria, GetZoneID(), GetInstanceID());
|
||||
std::vector<BazaarSearchResultsFromDB_Struct> results = Bazaar::GetSearchResults(
|
||||
database,
|
||||
content_db,
|
||||
search_criteria,
|
||||
GetZoneID(),
|
||||
GetInstanceID()
|
||||
);
|
||||
if (results.empty()) {
|
||||
SendBazaarDone(GetID());
|
||||
return;
|
||||
@@ -1822,317 +1828,6 @@ void Client::DoBazaarSearch(BazaarSearchCriteria_Struct search_criteria)
|
||||
SendBazaarDeliveryCosts();
|
||||
}
|
||||
|
||||
void Client::SendBazaarResults(
|
||||
uint32 trader_id,
|
||||
uint32 in_class,
|
||||
uint32 in_race,
|
||||
uint32 item_stat,
|
||||
uint32 item_slot,
|
||||
uint32 item_type,
|
||||
char item_name[64],
|
||||
uint32 min_price,
|
||||
uint32 max_price
|
||||
)
|
||||
{
|
||||
std::string search_values = " COUNT(item_id), trader.*, items.name ";
|
||||
std::string search_criteria = " WHERE trader.item_id = items.id ";
|
||||
|
||||
if (trader_id > 0) {
|
||||
Client *trader = entity_list.GetClientByID(trader_id);
|
||||
|
||||
if (trader) {
|
||||
search_criteria.append(StringFormat(" AND trader.char_id = %i", trader->CharacterID()));
|
||||
}
|
||||
}
|
||||
|
||||
if (min_price != 0) {
|
||||
search_criteria.append(StringFormat(" AND trader.item_cost >= %i", min_price));
|
||||
}
|
||||
|
||||
if (max_price != 0) {
|
||||
search_criteria.append(StringFormat(" AND trader.item_cost <= %i", max_price));
|
||||
}
|
||||
|
||||
if (strlen(item_name) > 0) {
|
||||
char *safeName = RemoveApostrophes(item_name);
|
||||
search_criteria.append(StringFormat(" AND items.name LIKE '%%%s%%'", safeName));
|
||||
safe_delete_array(safeName);
|
||||
}
|
||||
|
||||
if (in_class != 0xFFFFFFFF) {
|
||||
search_criteria.append(StringFormat(" AND MID(REVERSE(BIN(items.classes)), %i, 1) = 1", in_class));
|
||||
}
|
||||
|
||||
if (in_race != 0xFFFFFFFF) {
|
||||
search_criteria.append(StringFormat(" AND MID(REVERSE(BIN(items.races)), %i, 1) = 1", in_race));
|
||||
}
|
||||
|
||||
if (item_slot != 0xFFFFFFFF) {
|
||||
search_criteria.append(StringFormat(" AND MID(REVERSE(BIN(items.slots)), %i, 1) = 1", item_slot + 1));
|
||||
}
|
||||
|
||||
switch (item_type) {
|
||||
case 0xFFFFFFFF:
|
||||
break;
|
||||
case 0:
|
||||
// 1H Slashing
|
||||
search_criteria.append(" AND items.itemtype = 0 AND damage > 0");
|
||||
break;
|
||||
case 31:
|
||||
search_criteria.append(" AND items.itemclass = 2");
|
||||
break;
|
||||
case 46:
|
||||
search_criteria.append(" AND items.scrolleffect > 0 AND items.scrolleffect < 65000");
|
||||
break;
|
||||
case 47:
|
||||
search_criteria.append(" AND items.worneffect = 998");
|
||||
break;
|
||||
case 48:
|
||||
search_criteria.append(" AND items.worneffect >= 1298 AND items.worneffect <= 1307");
|
||||
break;
|
||||
case 49:
|
||||
search_criteria.append(" AND items.focuseffect > 0");
|
||||
break;
|
||||
|
||||
default:
|
||||
search_criteria.append(StringFormat(" AND items.itemtype = %i", item_type));
|
||||
}
|
||||
|
||||
switch (item_stat) {
|
||||
|
||||
case STAT_AC:
|
||||
search_criteria.append(" AND items.ac > 0");
|
||||
search_values.append(", items.ac");
|
||||
break;
|
||||
|
||||
case STAT_AGI:
|
||||
search_criteria.append(" AND items.aagi > 0");
|
||||
search_values.append(", items.aagi");
|
||||
break;
|
||||
|
||||
case STAT_CHA:
|
||||
search_criteria.append(" AND items.acha > 0");
|
||||
search_values.append(", items.acha");
|
||||
break;
|
||||
|
||||
case STAT_DEX:
|
||||
search_criteria.append(" AND items.adex > 0");
|
||||
search_values.append(", items.adex");
|
||||
break;
|
||||
|
||||
case STAT_INT:
|
||||
search_criteria.append(" AND items.aint > 0");
|
||||
search_values.append(", items.aint");
|
||||
break;
|
||||
|
||||
case STAT_STA:
|
||||
search_criteria.append(" AND items.asta > 0");
|
||||
search_values.append(", items.asta");
|
||||
break;
|
||||
|
||||
case STAT_STR:
|
||||
search_criteria.append(" AND items.astr > 0");
|
||||
search_values.append(", items.astr");
|
||||
break;
|
||||
|
||||
case STAT_WIS:
|
||||
search_criteria.append(" AND items.awis > 0");
|
||||
search_values.append(", items.awis");
|
||||
break;
|
||||
|
||||
case STAT_COLD:
|
||||
search_criteria.append(" AND items.cr > 0");
|
||||
search_values.append(", items.cr");
|
||||
break;
|
||||
|
||||
case STAT_DISEASE:
|
||||
search_criteria.append(" AND items.dr > 0");
|
||||
search_values.append(", items.dr");
|
||||
break;
|
||||
|
||||
case STAT_FIRE:
|
||||
search_criteria.append(" AND items.fr > 0");
|
||||
search_values.append(", items.fr");
|
||||
break;
|
||||
|
||||
case STAT_MAGIC:
|
||||
search_criteria.append(" AND items.mr > 0");
|
||||
search_values.append(", items.mr");
|
||||
break;
|
||||
|
||||
case STAT_POISON:
|
||||
search_criteria.append(" AND items.pr > 0");
|
||||
search_values.append(", items.pr");
|
||||
break;
|
||||
|
||||
case STAT_HP:
|
||||
search_criteria.append(" AND items.hp > 0");
|
||||
search_values.append(", items.hp");
|
||||
break;
|
||||
|
||||
case STAT_MANA:
|
||||
search_criteria.append(" AND items.mana > 0");
|
||||
search_values.append(", items.mana");
|
||||
break;
|
||||
|
||||
case STAT_ENDURANCE:
|
||||
search_criteria.append(" AND items.endur > 0");
|
||||
search_values.append(", items.endur");
|
||||
break;
|
||||
|
||||
case STAT_ATTACK:
|
||||
search_criteria.append(" AND items.attack > 0");
|
||||
search_values.append(", items.attack");
|
||||
break;
|
||||
|
||||
case STAT_HP_REGEN:
|
||||
search_criteria.append(" AND items.regen > 0");
|
||||
search_values.append(", items.regen");
|
||||
break;
|
||||
|
||||
case STAT_MANA_REGEN:
|
||||
search_criteria.append(" AND items.manaregen > 0");
|
||||
search_values.append(", items.manaregen");
|
||||
break;
|
||||
|
||||
case STAT_HASTE:
|
||||
search_criteria.append(" AND items.haste > 0");
|
||||
search_values.append(", items.haste");
|
||||
break;
|
||||
|
||||
case STAT_DAMAGE_SHIELD:
|
||||
search_criteria.append(" AND items.damageshield > 0");
|
||||
search_values.append(", items.damageshield");
|
||||
break;
|
||||
|
||||
default:
|
||||
search_values.append(", 0");
|
||||
break;
|
||||
}
|
||||
|
||||
std::string query = StringFormat(
|
||||
"SELECT %s, SUM(charges), items.stackable "
|
||||
"FROM trader, items %s GROUP BY items.id, charges, char_id LIMIT %i",
|
||||
search_values.c_str(),
|
||||
search_criteria.c_str(),
|
||||
RuleI(Bazaar, MaxSearchResults)
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
|
||||
if (!results.Success()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LogTrading("SRCH: [{}]", query.c_str());
|
||||
|
||||
int Size = 0;
|
||||
uint32 ID = 0;
|
||||
|
||||
if (results.RowCount() == static_cast<unsigned long>(RuleI(Bazaar, MaxSearchResults))) {
|
||||
Message(
|
||||
Chat::Yellow,
|
||||
"Your search reached the limit of %i results. Please narrow your search down by selecting more options.",
|
||||
RuleI(Bazaar, MaxSearchResults));
|
||||
}
|
||||
|
||||
if (results.RowCount() == 0) {
|
||||
auto outapp2 = new EQApplicationPacket(OP_BazaarSearch, sizeof(BazaarReturnDone_Struct));
|
||||
BazaarReturnDone_Struct *brds = (BazaarReturnDone_Struct *) outapp2->pBuffer;
|
||||
brds->TraderID = ID;
|
||||
brds->Type = BazaarSearchDone;
|
||||
brds->Unknown008 = 0xFFFFFFFF;
|
||||
brds->Unknown012 = 0xFFFFFFFF;
|
||||
brds->Unknown016 = 0xFFFFFFFF;
|
||||
QueuePacket(outapp2);
|
||||
safe_delete(outapp2);
|
||||
return;
|
||||
}
|
||||
|
||||
Size = results.RowCount() * sizeof(BazaarSearchResults_Struct);
|
||||
auto buffer = new uchar[Size];
|
||||
uchar *bufptr = buffer;
|
||||
memset(buffer, 0, Size);
|
||||
|
||||
int Action = BazaarSearchResults;
|
||||
uint32 Cost = 0;
|
||||
int32 SerialNumber = 0;
|
||||
char temp_buffer[64] = {0};
|
||||
int Count = 0;
|
||||
uint32 StatValue = 0;
|
||||
|
||||
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);
|
||||
SerialNumber = Strings::ToInt(row[3]);
|
||||
VARSTRUCT_ENCODE_TYPE(int32, bufptr, SerialNumber);
|
||||
Client *Trader2 = entity_list.GetClientByCharID(Strings::ToInt(row[1]));
|
||||
if (Trader2) {
|
||||
ID = Trader2->GetID();
|
||||
VARSTRUCT_ENCODE_TYPE(uint32, bufptr, ID);
|
||||
}
|
||||
else {
|
||||
LogTrading("Unable to find trader: [{}]\n", Strings::ToInt(row[1]));
|
||||
VARSTRUCT_ENCODE_TYPE(uint32, bufptr, 0);
|
||||
}
|
||||
Cost = Strings::ToInt(row[5]);
|
||||
VARSTRUCT_ENCODE_TYPE(uint32, bufptr, Cost);
|
||||
StatValue = Strings::ToInt(row[8]);
|
||||
VARSTRUCT_ENCODE_TYPE(uint32, bufptr, StatValue);
|
||||
bool Stackable = Strings::ToInt(row[10]);
|
||||
if (Stackable) {
|
||||
int Charges = Strings::ToInt(row[9]);
|
||||
sprintf(temp_buffer, "%s(%i)", row[7], Charges);
|
||||
}
|
||||
else {
|
||||
sprintf(temp_buffer, "%s(%i)", row[7], Count);
|
||||
}
|
||||
|
||||
memcpy(bufptr, &temp_buffer, strlen(temp_buffer));
|
||||
|
||||
bufptr += 64;
|
||||
|
||||
// Extra fields for SoD+
|
||||
//
|
||||
if (Trader2) {
|
||||
sprintf(temp_buffer, "%s", Trader2->GetName());
|
||||
}
|
||||
else {
|
||||
sprintf(temp_buffer, "Unknown");
|
||||
}
|
||||
|
||||
memcpy(bufptr, &temp_buffer, strlen(temp_buffer));
|
||||
|
||||
bufptr += 64;
|
||||
|
||||
VARSTRUCT_ENCODE_TYPE(uint32, bufptr, Strings::ToInt(row[1])); // ItemID
|
||||
}
|
||||
|
||||
auto outapp = new EQApplicationPacket(OP_BazaarSearch, Size);
|
||||
|
||||
memcpy(outapp->pBuffer, buffer, Size);
|
||||
|
||||
QueuePacket(outapp);
|
||||
|
||||
safe_delete(outapp);
|
||||
safe_delete_array(buffer);
|
||||
|
||||
auto outapp2 = new EQApplicationPacket(OP_BazaarSearch, sizeof(BazaarReturnDone_Struct));
|
||||
BazaarReturnDone_Struct *brds = (BazaarReturnDone_Struct *) outapp2->pBuffer;
|
||||
|
||||
brds->TraderID = ID;
|
||||
brds->Type = BazaarSearchDone;
|
||||
|
||||
brds->Unknown008 = 0xFFFFFFFF;
|
||||
brds->Unknown012 = 0xFFFFFFFF;
|
||||
brds->Unknown016 = 0xFFFFFFFF;
|
||||
|
||||
QueuePacket(outapp2);
|
||||
|
||||
safe_delete(outapp2);
|
||||
}
|
||||
|
||||
static void UpdateTraderCustomerItemsAdded(
|
||||
uint32 customer_id,
|
||||
std::vector<BaseTraderRepository::Trader> trader_items,
|
||||
@@ -3602,7 +3297,7 @@ void Client::BuyTraderItemOutsideBazaar(TraderBuy_Struct *tbs, const EQApplicati
|
||||
out_data->id = trader_item.id;
|
||||
strn0cpy(out_data->trader_buy_struct.buyer_name, GetCleanName(), sizeof(out_data->trader_buy_struct.buyer_name));
|
||||
|
||||
worldserver.SendPacket(out_server.release());
|
||||
worldserver.SendPacket(out_server.get());
|
||||
}
|
||||
|
||||
void Client::SetBuyerWelcomeMessage(const char *welcome_message)
|
||||
|
||||
Reference in New Issue
Block a user