diff options
author | SmallJoker <mk939@ymail.com> | 2021-03-07 10:04:07 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2021-04-05 16:01:15 +0200 |
commit | 41beb74ef7eab2a2c634cd2c23671807443788aa (patch) | |
tree | 4b7c6135a8090cae422a8ccb53c864a5af7566ec /src/server | |
parent | 67be50b706b0d1364b42ff1fd3d461d0794cd268 (diff) | |
download | minetest-41beb74ef7eab2a2c634cd2c23671807443788aa.tar.gz minetest-41beb74ef7eab2a2c634cd2c23671807443788aa.tar.bz2 minetest-41beb74ef7eab2a2c634cd2c23671807443788aa.zip |
Protect per-player detached inventory actions
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/serverinventorymgr.cpp | 12 | ||||
-rw-r--r-- | src/server/serverinventorymgr.h | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/server/serverinventorymgr.cpp b/src/server/serverinventorymgr.cpp index 555e01ec6..2a80c9bbe 100644 --- a/src/server/serverinventorymgr.cpp +++ b/src/server/serverinventorymgr.cpp @@ -168,6 +168,18 @@ bool ServerInventoryManager::removeDetachedInventory(const std::string &name) return true; } +bool ServerInventoryManager::checkDetachedInventoryAccess( + const InventoryLocation &loc, const std::string &player) const +{ + SANITY_CHECK(loc.type == InventoryLocation::DETACHED); + + const auto &inv_it = m_detached_inventories.find(loc.name); + if (inv_it == m_detached_inventories.end()) + return false; + + return inv_it->second.owner.empty() || inv_it->second.owner == player; +} + void ServerInventoryManager::sendDetachedInventories(const std::string &peer_name, bool incremental, std::function<void(const std::string &, Inventory *)> apply_cb) diff --git a/src/server/serverinventorymgr.h b/src/server/serverinventorymgr.h index ccf6d3b2e..0e4b72415 100644 --- a/src/server/serverinventorymgr.h +++ b/src/server/serverinventorymgr.h @@ -43,6 +43,7 @@ public: Inventory *createDetachedInventory(const std::string &name, IItemDefManager *idef, const std::string &player = ""); bool removeDetachedInventory(const std::string &name); + bool checkDetachedInventoryAccess(const InventoryLocation &loc, const std::string &player) const; void sendDetachedInventories(const std::string &peer_name, bool incremental, std::function<void(const std::string &, Inventory *)> apply_cb); |