Skip to content

Commit 6dcc9e6

Browse files
authoredSep 4, 2020
Prevent interacting with items out of the hotbar (#10359)
1 parent 9faeca3 commit 6dcc9e6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed
 

‎src/network/serverpackethandler.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
636636
return;
637637
from_inv_is_current_player = true;
638638
}
639-
639+
640640
bool to_inv_is_current_player = false;
641641
if (ma->to_inv.type == InventoryLocation::PLAYER) {
642642
if (ma->to_inv.name != player->getName())
@@ -869,6 +869,15 @@ void Server::handleCommand_PlayerItem(NetworkPacket* pkt)
869869

870870
*pkt >> item;
871871

872+
if (item >= player->getHotbarItemcount()) {
873+
actionstream << "Player: " << player->getName()
874+
<< " tried to access item=" << item
875+
<< " out of hotbar_itemcount="
876+
<< player->getHotbarItemcount()
877+
<< "; ignoring." << std::endl;
878+
return;
879+
}
880+
872881
playersao->getPlayer()->setWieldIndex(item);
873882
}
874883

@@ -984,6 +993,16 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
984993
v3f player_pos = playersao->getLastGoodPosition();
985994

986995
// Update wielded item
996+
997+
if (item_i >= player->getHotbarItemcount()) {
998+
actionstream << "Player: " << player->getName()
999+
<< " tried to access item=" << item_i
1000+
<< " out of hotbar_itemcount="
1001+
<< player->getHotbarItemcount()
1002+
<< "; ignoring." << std::endl;
1003+
return;
1004+
}
1005+
9871006
playersao->getPlayer()->setWieldIndex(item_i);
9881007

9891008
// Get pointed to object (NULL if not POINTEDTYPE_OBJECT)

0 commit comments

Comments
 (0)