From e406c1d5f570d7ab1a9a7587da56cc7866aed8aa Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Sun, 17 Sep 2023 19:41:41 -0400 Subject: [PATCH] antihacks: Protect per-player detached inventory actions * backported https://github.com/minetest/minetest/pull/10341 Unfortunately also requires invhack mods to implement workarounds, but they seem to already be doing this. --- src/network/serverpackethandler.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index fc64c142e..4d14aa175 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -935,13 +935,19 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) setInventoryModified(ma->from_inv, false); setInventoryModified(ma->to_inv, false); - bool from_inv_is_current_player = - (ma->from_inv.type == InventoryLocation::PLAYER) && - (ma->from_inv.name == player->getName()); + bool from_inv_is_current_player = false; + if (ma->from_inv.type == InventoryLocation::PLAYER) { + if (ma->from_inv.name != player->getName()) + return; + from_inv_is_current_player = true; + } - bool to_inv_is_current_player = - (ma->to_inv.type == InventoryLocation::PLAYER) && - (ma->to_inv.name == player->getName()); + bool to_inv_is_current_player = false; + if (ma->to_inv.type == InventoryLocation::PLAYER) { + if (ma->to_inv.name != player->getName()) + return; + to_inv_is_current_player = true; + } InventoryLocation *remote = from_inv_is_current_player ? &ma->to_inv : &ma->from_inv;