aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLejo <Lejo_1@web.de>2020-09-04 20:50:33 +0200
committerGitHub <noreply@github.com>2020-09-04 20:50:33 +0200
commit6dcc9e63318f815a3de8c9db2ee7b845066e0135 (patch)
tree9a5745eabc484810fc204d59555287f52eb3ae85
parent9faeca329039f33f7e2af99eb021cea5b18beceb (diff)
downloadminetest-6dcc9e63318f815a3de8c9db2ee7b845066e0135.tar.gz
minetest-6dcc9e63318f815a3de8c9db2ee7b845066e0135.tar.bz2
minetest-6dcc9e63318f815a3de8c9db2ee7b845066e0135.zip
Prevent interacting with items out of the hotbar (#10359)
-rw-r--r--src/network/serverpackethandler.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index d133b4ff9..fe70d376e 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -636,7 +636,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
return;
from_inv_is_current_player = true;
}
-
+
bool to_inv_is_current_player = false;
if (ma->to_inv.type == InventoryLocation::PLAYER) {
if (ma->to_inv.name != player->getName())
@@ -869,6 +869,15 @@ void Server::handleCommand_PlayerItem(NetworkPacket* pkt)
*pkt >> item;
+ if (item >= player->getHotbarItemcount()) {
+ actionstream << "Player: " << player->getName()
+ << " tried to access item=" << item
+ << " out of hotbar_itemcount="
+ << player->getHotbarItemcount()
+ << "; ignoring." << std::endl;
+ return;
+ }
+
playersao->getPlayer()->setWieldIndex(item);
}
@@ -984,6 +993,16 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
v3f player_pos = playersao->getLastGoodPosition();
// Update wielded item
+
+ if (item_i >= player->getHotbarItemcount()) {
+ actionstream << "Player: " << player->getName()
+ << " tried to access item=" << item_i
+ << " out of hotbar_itemcount="
+ << player->getHotbarItemcount()
+ << "; ignoring." << std::endl;
+ return;
+ }
+
playersao->getPlayer()->setWieldIndex(item_i);
// Get pointed to object (NULL if not POINTEDTYPE_OBJECT)