Skip to content

Commit

Permalink
pass RemotePlayer to SendInventory
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Jan 28, 2024
1 parent 64156be commit 5de31f9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/network/serverpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
return;
}

playersao->getPlayer()->setWieldIndex(item_i);
player->setWieldIndex(item_i);

// Get pointed to object (NULL if not POINTEDTYPE_OBJECT)
ServerActiveObject *pointed_object = NULL;
Expand Down Expand Up @@ -1161,7 +1161,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
// Get player's wielded item
// See also: Game::handleDigging
ItemStack selected_item, hand_item;
playersao->getPlayer()->getWieldedItem(&selected_item, &hand_item);
player->getWieldedItem(&selected_item, &hand_item);

// Get diggability and expected digging time
DigParams params = getDigParams(m_nodedef->get(n).groups,
Expand Down Expand Up @@ -1253,7 +1253,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
// Do stuff
if (m_script->item_OnSecondaryUse(selected_item, playersao, pointed)) {
if (selected_item.has_value() && playersao->setWieldedItem(*selected_item))
SendInventory(playersao, true);
SendInventory(player, true);
}

pointed_object->rightClick(playersao);
Expand All @@ -1262,7 +1262,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)

// Apply returned ItemStack
if (selected_item.has_value() && playersao->setWieldedItem(*selected_item))
SendInventory(playersao, true);
SendInventory(player, true);
}

if (pointed.type != POINTEDTHING_NODE)
Expand Down Expand Up @@ -1296,7 +1296,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
if (m_script->item_OnUse(selected_item, playersao, pointed)) {
// Apply returned ItemStack
if (selected_item.has_value() && playersao->setWieldedItem(*selected_item))
SendInventory(playersao, true);
SendInventory(player, true);
}

return;
Expand All @@ -1315,7 +1315,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
if (m_script->item_OnSecondaryUse(selected_item, playersao, pointed)) {
// Apply returned ItemStack
if (selected_item.has_value() && playersao->setWieldedItem(*selected_item))
SendInventory(playersao, true);
SendInventory(player, true);
}

return;
Expand Down
2 changes: 1 addition & 1 deletion src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ int ObjectRef::l_set_wielded_item(lua_State *L)

bool success = sao->setWieldedItem(item);
if (success && sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
getServer(L)->SendInventory((PlayerSAO *)sao, true);
getServer(L)->SendInventory(((PlayerSAO *)sao)->getPlayer(), true);
}
lua_pushboolean(L, success);
return 1;
Expand Down
12 changes: 5 additions & 7 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ PlayerSAO* Server::StageTwoClientInit(session_t peer_id)
SendPlayerInventoryFormspec(peer_id);

// Send inventory
SendInventory(playersao, false);
SendInventory(player, false);

// Send HP
SendPlayerHP(playersao, false);
Expand Down Expand Up @@ -1458,10 +1458,8 @@ void Server::SendNodeDef(session_t peer_id,
Non-static send methods
*/

void Server::SendInventory(PlayerSAO *sao, bool incremental)
void Server::SendInventory(RemotePlayer *player, bool incremental)
{
RemotePlayer *player = sao->getPlayer();

// Do not send new format to old clients
incremental &= player->protocol_version >= 38;

Expand All @@ -1471,11 +1469,11 @@ void Server::SendInventory(PlayerSAO *sao, bool incremental)
Serialize it
*/

NetworkPacket pkt(TOCLIENT_INVENTORY, 0, sao->getPeerID());
NetworkPacket pkt(TOCLIENT_INVENTORY, 0, player->getPeerId());

std::ostringstream os(std::ios::binary);
sao->getInventory()->serialize(os, incremental);
sao->getInventory()->setModified(false);
player->inventory.serialize(os, incremental);
player->inventory.setModified(false);
player->setModified(true);

const std::string &s = os.str();
Expand Down
2 changes: 1 addition & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
void HandlePlayerHPChange(PlayerSAO *sao, const PlayerHPChangeReason &reason);
void SendPlayerHP(PlayerSAO *sao, bool effect);
void SendPlayerBreath(PlayerSAO *sao);
void SendInventory(PlayerSAO *playerSAO, bool incremental);
void SendInventory(RemotePlayer *player, bool incremental);
void SendMovePlayer(PlayerSAO *sao);
void SendMovePlayerRel(session_t peer_id, const v3f &added_pos);
void SendPlayerSpeed(session_t peer_id, const v3f &added_vel);
Expand Down
5 changes: 2 additions & 3 deletions src/serverenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1640,12 +1640,11 @@ void ServerEnvironment::step(float dtime)

// Send outdated player inventories
for (RemotePlayer *player : m_players) {
PlayerSAO *sao = player->getPlayerSAO();
if (!sao || sao->isGone())
if (player->getPeerId() == PEER_ID_INEXISTENT)
continue;

if (player->inventory.checkModified())
m_server->SendInventory(sao, true);
m_server->SendInventory(player, true);
}

// Send outdated detached inventories
Expand Down

0 comments on commit 5de31f9

Please sign in to comment.