Don't send an InventoryAction at each setInventoryModified, we only need one SendInventory per inventory modification

Client doesn't like to receive multiples SendInventory for one action, this can trigger glitches on clients (sometimes due to incorrect UDP packet ordering due to UDP protocol)

This fix issue #2544
master
Loic Blot 2015-03-24 09:36:54 +01:00
parent 9fbc3a8ca3
commit 7851c4f7a2
5 changed files with 15 additions and 10 deletions

View File

@ -455,9 +455,9 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
}
}
mgr->setInventoryModified(from_inv);
mgr->setInventoryModified(from_inv, false);
if(inv_from != inv_to)
mgr->setInventoryModified(to_inv);
mgr->setInventoryModified(to_inv, false);
}
void IMoveAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
@ -597,7 +597,7 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
if(item2.count != actually_dropped_count)
errorstream<<"Could not take dropped count of items"<<std::endl;
mgr->setInventoryModified(from_inv);
mgr->setInventoryModified(from_inv, false);
}
}

View File

@ -112,7 +112,7 @@ public:
// Get an inventory (server and client)
virtual Inventory* getInventory(const InventoryLocation &loc){return NULL;}
// Set modified (will be saved and sent over network; only on server)
virtual void setInventoryModified(const InventoryLocation &loc){}
virtual void setInventoryModified(const InventoryLocation &loc, bool playerSend = true){}
// Send inventory action to server (only on client)
virtual void inventoryAction(InventoryAction *a){}
};

View File

@ -952,8 +952,8 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
ma->from_inv.applyCurrentPlayer(player->getName());
ma->to_inv.applyCurrentPlayer(player->getName());
setInventoryModified(ma->from_inv);
setInventoryModified(ma->to_inv);
setInventoryModified(ma->from_inv, false);
setInventoryModified(ma->to_inv, false);
bool from_inv_is_current_player =
(ma->from_inv.type == InventoryLocation::PLAYER) &&
@ -1006,7 +1006,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
da->from_inv.applyCurrentPlayer(player->getName());
setInventoryModified(da->from_inv);
setInventoryModified(da->from_inv, false);
/*
Disable dropping items out of craftpreview
@ -1033,7 +1033,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
ca->craft_inv.applyCurrentPlayer(player->getName());
setInventoryModified(ca->craft_inv);
setInventoryModified(ca->craft_inv, false);
//bool craft_inv_is_current_player =
// (ca->craft_inv.type == InventoryLocation::PLAYER) &&
@ -1052,6 +1052,8 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
a->apply(this, playersao, this);
// Eat the action
delete a;
SendInventory(playersao);
}
void Server::handleCommand_ChatMessage(NetworkPacket* pkt)

View File

@ -1290,13 +1290,16 @@ Inventory* Server::getInventory(const InventoryLocation &loc)
}
return NULL;
}
void Server::setInventoryModified(const InventoryLocation &loc)
void Server::setInventoryModified(const InventoryLocation &loc, bool playerSend)
{
switch(loc.type){
case InventoryLocation::UNDEFINED:
break;
case InventoryLocation::PLAYER:
{
if (!playerSend)
return;
Player *player = m_env->getPlayer(loc.name.c_str());
if(!player)
return;

View File

@ -237,7 +237,7 @@ public:
Shall be called with the environment and the connection locked.
*/
Inventory* getInventory(const InventoryLocation &loc);
void setInventoryModified(const InventoryLocation &loc);
void setInventoryModified(const InventoryLocation &loc, bool playerSend = true);
// Connection must be locked when called
std::wstring getStatusString();