File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -626,14 +626,18 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
626
626
627
627
const bool player_has_interact = checkPriv (player->getName (), " interact" );
628
628
629
- auto check_inv_access = [player, player_has_interact] (
629
+ auto check_inv_access = [player, player_has_interact, this ] (
630
630
const InventoryLocation &loc) -> bool {
631
631
if (loc.type == InventoryLocation::CURRENT_PLAYER)
632
632
return false ; // Only used internally on the client, never sent
633
633
if (loc.type == InventoryLocation::PLAYER) {
634
634
// Allow access to own inventory in all cases
635
635
return loc.name == player->getName ();
636
636
}
637
+ if (loc.type == InventoryLocation::DETACHED) {
638
+ if (!getInventoryMgr ()->checkDetachedInventoryAccess (loc, player->getName ()))
639
+ return false ;
640
+ }
637
641
638
642
if (!player_has_interact) {
639
643
infostream << " Cannot modify foreign inventory: "
Original file line number Diff line number Diff line change @@ -168,6 +168,18 @@ bool ServerInventoryManager::removeDetachedInventory(const std::string &name)
168
168
return true ;
169
169
}
170
170
171
+ bool ServerInventoryManager::checkDetachedInventoryAccess (
172
+ const InventoryLocation &loc, const std::string &player) const
173
+ {
174
+ SANITY_CHECK (loc.type == InventoryLocation::DETACHED);
175
+
176
+ const auto &inv_it = m_detached_inventories.find (loc.name );
177
+ if (inv_it == m_detached_inventories.end ())
178
+ return false ;
179
+
180
+ return inv_it->second .owner .empty () || inv_it->second .owner == player;
181
+ }
182
+
171
183
void ServerInventoryManager::sendDetachedInventories (const std::string &peer_name,
172
184
bool incremental,
173
185
std::function<void (const std::string &, Inventory *)> apply_cb)
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ class ServerInventoryManager : public InventoryManager
43
43
Inventory *createDetachedInventory (const std::string &name, IItemDefManager *idef,
44
44
const std::string &player = " " );
45
45
bool removeDetachedInventory (const std::string &name);
46
+ bool checkDetachedInventoryAccess (const InventoryLocation &loc, const std::string &player) const ;
46
47
47
48
void sendDetachedInventories (const std::string &peer_name, bool incremental,
48
49
std::function<void (const std::string &, Inventory *)> apply_cb);
You can’t perform that action at this time.
0 commit comments