@@ -628,23 +628,34 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
628
628
629
629
auto check_inv_access = [player, player_has_interact, this ] (
630
630
const InventoryLocation &loc) -> bool {
631
- if (loc.type == InventoryLocation::CURRENT_PLAYER)
632
- return false ; // Only used internally on the client, never sent
633
- if (loc.type == InventoryLocation::PLAYER) {
634
- // Allow access to own inventory in all cases
635
- return loc.name == player->getName ();
636
- }
637
- if (loc.type == InventoryLocation::DETACHED) {
638
- if (!getInventoryMgr ()->checkDetachedInventoryAccess (loc, player->getName ()))
639
- return false ;
640
- }
641
631
642
- if (!player_has_interact) {
632
+ // Players without interact may modify their own inventory
633
+ if (!player_has_interact && loc.type != InventoryLocation::PLAYER) {
643
634
infostream << " Cannot modify foreign inventory: "
644
635
<< " No interact privilege" << std::endl;
645
636
return false ;
646
637
}
647
- return true ;
638
+
639
+ switch (loc.type ) {
640
+ case InventoryLocation::CURRENT_PLAYER:
641
+ // Only used internally on the client, never sent
642
+ return false ;
643
+ case InventoryLocation::PLAYER:
644
+ // Allow access to own inventory in all cases
645
+ return loc.name == player->getName ();
646
+ case InventoryLocation::NODEMETA:
647
+ {
648
+ // Check for out-of-range interaction
649
+ v3f node_pos = intToFloat (loc.p , BS);
650
+ v3f player_pos = player->getPlayerSAO ()->getEyePosition ();
651
+ f32 d = player_pos.getDistanceFrom (node_pos);
652
+ return checkInteractDistance (player, d, " inventory" );
653
+ }
654
+ case InventoryLocation::DETACHED:
655
+ return getInventoryMgr ()->checkDetachedInventoryAccess (loc, player->getName ());
656
+ default :
657
+ return false ;
658
+ }
648
659
};
649
660
650
661
/*
@@ -664,18 +675,6 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
664
675
!check_inv_access (ma->to_inv ))
665
676
return ;
666
677
667
- InventoryLocation *remote = ma->from_inv .type == InventoryLocation::PLAYER ?
668
- &ma->to_inv : &ma->from_inv ;
669
-
670
- // Check for out-of-range interaction
671
- if (remote->type == InventoryLocation::NODEMETA) {
672
- v3f node_pos = intToFloat (remote->p , BS);
673
- v3f player_pos = player->getPlayerSAO ()->getEyePosition ();
674
- f32 d = player_pos.getDistanceFrom (node_pos);
675
- if (!checkInteractDistance (player, d, " inventory" ))
676
- return ;
677
- }
678
-
679
678
/*
680
679
Disable moving items out of craftpreview
681
680
*/
0 commit comments