}
}
- mgr->setInventoryModified(from_inv, false);
+ mgr->setInventoryModified(from_inv);
if (inv_from != inv_to)
- mgr->setInventoryModified(to_inv, false);
+ mgr->setInventoryModified(to_inv);
}
void IMoveAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
if (item2.count != actually_dropped_count)
errorstream<<"Could not take dropped count of items"<<std::endl;
- mgr->setInventoryModified(from_inv, false);
+ mgr->setInventoryModified(from_inv);
}
}
sendMediaAnnouncement(pkt->getPeerId(), lang);
// Send detached inventories
- sendDetachedInventories(pkt->getPeerId());
+ sendDetachedInventories(pkt->getPeerId(), false);
// Send time of day
u16 time = m_env->getTimeOfDay();
ma->from_inv.applyCurrentPlayer(player->getName());
ma->to_inv.applyCurrentPlayer(player->getName());
- setInventoryModified(ma->from_inv, false);
- if (ma->from_inv != ma->to_inv) {
- setInventoryModified(ma->to_inv, false);
- }
+ setInventoryModified(ma->from_inv);
+ if (ma->from_inv != ma->to_inv)
+ setInventoryModified(ma->to_inv);
bool from_inv_is_current_player =
(ma->from_inv.type == InventoryLocation::PLAYER) &&
da->from_inv.applyCurrentPlayer(player->getName());
- setInventoryModified(da->from_inv, false);
+ setInventoryModified(da->from_inv);
/*
Disable dropping items out of craftpreview
ca->craft_inv.applyCurrentPlayer(player->getName());
- setInventoryModified(ca->craft_inv, false);
+ setInventoryModified(ca->craft_inv);
//bool craft_inv_is_current_player =
// (ca->craft_inv.type == InventoryLocation::PLAYER) &&
a->apply(this, playersao, this);
// Eat the action
delete a;
-
- SendInventory(playersao, true);
}
void Server::handleCommand_ChatMessage(NetworkPacket* pkt)
return NULL;
}
-void Server::setInventoryModified(const InventoryLocation &loc, bool playerSend)
+void Server::setInventoryModified(const InventoryLocation &loc)
{
switch(loc.type){
case InventoryLocation::UNDEFINED:
return;
player->setModified(true);
-
- if (!playerSend)
- return;
-
- PlayerSAO *playersao = player->getPlayerSAO();
- if(!playersao)
- return;
-
- SendInventory(playersao, true);
+ // Updates are sent in ServerEnvironment::step()
}
break;
case InventoryLocation::NODEMETA:
break;
case InventoryLocation::DETACHED:
{
- sendDetachedInventory(loc.name,PEER_ID_INEXISTENT);
+ // Updates are sent in ServerEnvironment::step()
}
break;
default:
Send(&pkt);
}
-void Server::sendDetachedInventories(session_t peer_id)
+void Server::sendDetachedInventories(session_t peer_id, bool incremental)
{
for (const auto &detached_inventory : m_detached_inventories) {
const std::string &name = detached_inventory.first;
- //Inventory *inv = i->second;
+ if (incremental) {
+ Inventory *inv = detached_inventory.second;
+ if (!inv || !inv->checkModified())
+ continue;
+ }
+
sendDetachedInventory(name, peer_id);
}
}
Shall be called with the environment and the connection locked.
*/
Inventory* getInventory(const InventoryLocation &loc);
- void setInventoryModified(const InventoryLocation &loc, bool playerSend = true);
+ void setInventoryModified(const InventoryLocation &loc);
// Connection must be locked when called
std::wstring getStatusString();
void SendMovePlayer(session_t peer_id);
void SendPlayerSpeed(session_t peer_id, const v3f &added_vel);
+ void sendDetachedInventories(session_t peer_id, bool incremental);
+
virtual bool registerModStorage(ModMetadata *storage);
virtual void unregisterModStorage(const std::string &name);
const std::vector<std::string> &tosend);
void sendDetachedInventory(const std::string &name, session_t peer_id);
- void sendDetachedInventories(session_t peer_id);
// Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all)
void SendAddParticleSpawner(session_t peer_id, u16 protocol_version,
++i;
}
}
+
+ // Send outdated player inventories
+ for (RemotePlayer *player : m_players) {
+ if (player->getPeerId() == PEER_ID_INEXISTENT)
+ continue;
+
+ PlayerSAO *sao = player->getPlayerSAO();
+ if (sao && player->inventory.checkModified())
+ m_server->SendInventory(sao, true);
+ }
+
+ // Send outdated detached inventories
+ m_server->sendDetachedInventories(PEER_ID_INEXISTENT, true);
}
u32 ServerEnvironment::addParticleSpawner(float exptime)