mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-17 09:15:28 +00:00
fix: check a trade offer against the items the player holds
A trade used the LOT and the count from the offer as the player sent it. The offer is now resolved when it arrives and again when the trade completes: the LOT comes from the held item, the count stops at the held count, and an offer that names an unknown item, the same item twice or a count of 0 is refused. The other player only receives an item that was taken from the offering player. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include "ePermissionMap.h"
|
||||
#include "Game.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "InventoryComponent.h"
|
||||
#include "Item.h"
|
||||
#include "Logger.h"
|
||||
#include "TradingManager.h"
|
||||
#include "User.h"
|
||||
@@ -233,8 +235,23 @@ namespace GameMessages {
|
||||
|
||||
if (trade == nullptr) return;
|
||||
|
||||
const auto* const inventoryComponent = entity.GetComponent<InventoryComponent>();
|
||||
if (!inventoryComponent) return;
|
||||
|
||||
// The LOT and the count the trade works with come from the items the player holds
|
||||
const auto resolvedItems = Trade::ResolveOffer(items, [inventoryComponent](const LWOOBJID itemId) -> std::optional<HeldTradeItem> {
|
||||
const auto* const item = inventoryComponent->FindItemById(itemId);
|
||||
if (!item) return std::nullopt;
|
||||
return HeldTradeItem{ item->GetLot(), item->GetCount() };
|
||||
});
|
||||
|
||||
if (!resolvedItems) {
|
||||
LOG("Trade update from (%llu) does not match the items they hold, ignoring it", entity.GetObjectID());
|
||||
return;
|
||||
}
|
||||
|
||||
trade->SetCoins(entity.GetObjectID(), i64Currency);
|
||||
trade->SetItems(entity.GetObjectID(), items);
|
||||
trade->SetItems(entity.GetObjectID(), *resolvedItems);
|
||||
trade->SendUpdateToOther(entity.GetObjectID());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user