We always know playerSAO when calling SendInventory. Using it instead of searching...
authorLoic Blot <loic.blot@unix-experience.fr>
Wed, 4 Mar 2015 14:27:53 +0000 (15:27 +0100)
committerLoic Blot <loic.blot@unix-experience.fr>
Wed, 4 Mar 2015 14:28:33 +0000 (15:28 +0100)
src/network/packethandlers/server.cpp
src/script/lua_api/l_object.cpp
src/server.cpp
src/server.h

index 526c17344e57b5803324927e3ac9d3da5f738d63..aeaa2f3f3626fb60358ddc1fa6aca54240ac2226 100644 (file)
@@ -1391,7 +1391,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
 
                        // Apply returned ItemStack
                        if (playersao->setWieldedItem(item)) {
-                               SendInventory(pkt->getPeerId());
+                               SendInventory(playersao);
                        }
                }
 
index 0f3848aace75f2bf22c53e2d962be0040b1d5369..d8cfaf82b2fdea8f808f3ce18a0d2fcf05eaa464 100644 (file)
@@ -356,7 +356,7 @@ int ObjectRef::l_set_wielded_item(lua_State *L)
        ItemStack item = read_item(L, 2, getServer(L));
        bool success = co->setWieldedItem(item);
        if (success && co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
-               getServer(L)->SendInventory(((PlayerSAO*)co)->getPeerID());
+               getServer(L)->SendInventory(((PlayerSAO*)co));
        }
        lua_pushboolean(L, success);
        return 1;
index 625ab223152779482e1a5d4e862ccd75b6d293b9..51b90ce45cff1f940363573e06f8c5a7a600117a 100644 (file)
@@ -1125,7 +1125,7 @@ PlayerSAO* Server::StageTwoClientInit(u16 peer_id)
        SendPlayerInventoryFormspec(peer_id);
 
        // Send inventory
-       SendInventory(peer_id);
+       SendInventory(playersao);
 
        // Send HP
        if(g_settings->getBool("enable_damage"))
@@ -1329,6 +1329,7 @@ Inventory* Server::getInventory(const InventoryLocation &loc)
                break;
        default:
                assert(0);
+               break;
        }
        return NULL;
 }
@@ -1346,7 +1347,7 @@ void Server::setInventoryModified(const InventoryLocation &loc)
                if(!playersao)
                        return;
 
-               SendInventory(playersao->getPeerID());
+               SendInventory(playersao);
        }
                break;
        case InventoryLocation::NODEMETA:
@@ -1367,6 +1368,7 @@ void Server::setInventoryModified(const InventoryLocation &loc)
                break;
        default:
                assert(0);
+               break;
        }
 }
 
@@ -1604,23 +1606,21 @@ void Server::SendNodeDef(u16 peer_id,
        Non-static send methods
 */
 
-void Server::SendInventory(u16 peer_id)
+void Server::SendInventory(PlayerSAO* playerSAO)
 {
        DSTACK(__FUNCTION_NAME);
 
-       PlayerSAO *playersao = getPlayerSAO(peer_id);
-       assert(playersao);
-
-       UpdateCrafting(playersao->getPlayer());
+       UpdateCrafting(playerSAO->getPlayer());
 
        /*
                Serialize it
        */
 
-       NetworkPacket* pkt = new NetworkPacket(TOCLIENT_INVENTORY, 0, peer_id);
+       NetworkPacket* pkt = new NetworkPacket(TOCLIENT_INVENTORY, 0,
+                       playerSAO->getPeerID());
 
        std::ostringstream os;
-       playersao->getInventory()->serialize(os);
+       playerSAO->getInventory()->serialize(os);
 
        std::string s = os.str();
 
index 2fea0db4ccef9c603373a35822bcd58118e7e8e0..784f1e928aeededfe3076806abfc0d494b7f026c 100644 (file)
@@ -374,7 +374,7 @@ public:
 
        void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); }
        void SendPlayerBreath(u16 peer_id);
-       void SendInventory(u16 peer_id);
+       void SendInventory(PlayerSAO* playerSAO);
        void SendMovePlayer(u16 peer_id);
 
        // Bind address