mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-20 18:55:28 +00:00
fix(inventory): the ridden object and the mount item can't be deleted, as the client
LWOInventoryComponent_Common::CanRemoveFromInventory (0x00ce0d20) refuses the possessed object (GetPossessedObject) and the mount item (GetMountInventoryID) before the operator bypass and the deletion restrictions. The server let a player delete the mount they were riding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2405,6 +2405,10 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool InventoryComponent::CanDelete(const Item& item) const {
|
bool InventoryComponent::CanDelete(const Item& item) const {
|
||||||
|
// The object being ridden and the mount item are never deleted, not even by operators
|
||||||
|
const auto* const possessor = m_Parent->GetComponent<PossessorComponent>();
|
||||||
|
if (possessor && (possessor->GetPossessable() == item.GetId() || possessor->GetMountItemID() == item.GetId())) return false;
|
||||||
|
|
||||||
if (m_Parent->GetGMLevel() == eGameMasterLevel::OPERATOR) return true;
|
if (m_Parent->GetGMLevel() == eGameMasterLevel::OPERATOR) return true;
|
||||||
|
|
||||||
const auto row = static_cast<int32_t>(item.GetInfo().delResIndex);
|
const auto row = static_cast<int32_t>(item.GetInfo().delResIndex);
|
||||||
|
|||||||
@@ -478,7 +478,8 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the player may delete this item: its ItemComponent's DeletionRestrictions row, as the client checks it
|
* Whether the player may delete this item: its ItemComponent's DeletionRestrictions row, as the client checks it
|
||||||
* (LWOInventoryComponent_Common::CanRemoveFromInventory @ 00ce0d20 in 1.10.64). Operators may delete anything.
|
* (LWOInventoryComponent_Common::CanRemoveFromInventory @ 00ce0d20 in 1.10.64). The possessed object and the mount
|
||||||
|
* item are never deleted; otherwise operators may delete anything.
|
||||||
*/
|
*/
|
||||||
bool CanDelete(const Item& item) const;
|
bool CanDelete(const Item& item) const;
|
||||||
void OnMoveItemInInventory(const GameMessages::MoveItemInInventory& msg);
|
void OnMoveItemInInventory(const GameMessages::MoveItemInInventory& msg);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "InventoryComponent.h"
|
#include "InventoryComponent.h"
|
||||||
#include "Item.h"
|
#include "Item.h"
|
||||||
|
#include "PossessorComponent.h"
|
||||||
#include "eGameMasterLevel.h"
|
#include "eGameMasterLevel.h"
|
||||||
#include "eReplicaComponentType.h"
|
#include "eReplicaComponentType.h"
|
||||||
|
|
||||||
@@ -123,3 +124,18 @@ TEST_F(DeletionRestrictionTests, AnyAndAllOfOtherRows) {
|
|||||||
EXPECT_TRUE(inventory->CanDelete(*any));
|
EXPECT_TRUE(inventory->CanDelete(*any));
|
||||||
EXPECT_FALSE(inventory->CanDelete(*all));
|
EXPECT_FALSE(inventory->CanDelete(*all));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DeletionRestrictionTests, ThePossessedObjectAndTheMountItemAreNeverDeleted) {
|
||||||
|
auto* const ridden = Give(1000);
|
||||||
|
auto* const mount = Give(1000);
|
||||||
|
auto* const other = Give(1000);
|
||||||
|
auto* const possessor = entity->AddComponent<PossessorComponent>(-1);
|
||||||
|
possessor->SetPossessable(ridden->GetId());
|
||||||
|
possessor->SetMountItemID(mount->GetId());
|
||||||
|
entity->SetGMLevel(eGameMasterLevel::OPERATOR);
|
||||||
|
|
||||||
|
EXPECT_FALSE(inventory->CanDelete(*ridden));
|
||||||
|
EXPECT_FALSE(inventory->CanDelete(*mount));
|
||||||
|
EXPECT_TRUE(inventory->CanDelete(*other));
|
||||||
|
possessor->SetPossessable(LWOOBJID_EMPTY); // nothing to dismount when the entity goes
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user