Skip to content

Commit

Permalink
Prevent interacting with items out of the hotbar (#10359)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lejo1 committed Sep 4, 2020
1 parent 9faeca3 commit 6dcc9e6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/network/serverpackethandler.cpp
Expand Up @@ -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())
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6dcc9e6

Please sign in to comment.