forked from mirror/openmw-tes3mp
3bd8aa82fe
Whenever an item is added to or removed from the player's ContainerStore, that player sends a PlayerInventory packet with just that addition or removal.
This eliminates all the unnecessary packet spam related to oversized PlayerInventory packets that had existed in one form or another since the initial implementation of inventory sync in 1b259e2d33
Additionally, move booleans from BasePlayer to LocalPlayer when they are only needed on the client, and make the usage of the isReceivingQuickKeys boolean consistent with the new isReceivingInventory boolean by having them both in the processors of their associated packets.
46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
#ifndef OPENMW_PROCESSORPLAYERUPDATEINVENTORY_HPP
|
|
#define OPENMW_PROCESSORPLAYERUPDATEINVENTORY_HPP
|
|
|
|
#include "../PlayerProcessor.hpp"
|
|
|
|
namespace mwmp
|
|
{
|
|
class ProcessorPlayerInventory : public PlayerProcessor
|
|
{
|
|
public:
|
|
ProcessorPlayerInventory()
|
|
{
|
|
BPP_INIT(ID_PLAYER_INVENTORY)
|
|
}
|
|
|
|
virtual void Do(PlayerPacket &packet, BasePlayer *player)
|
|
{
|
|
if (!isLocal()) return;
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_INVENTORY about LocalPlayer from server");
|
|
|
|
if (isRequest())
|
|
static_cast<LocalPlayer*>(player)->updateInventory(true);
|
|
else
|
|
{
|
|
LocalPlayer &localPlayer = static_cast<LocalPlayer&>(*player);
|
|
int inventoryAction = localPlayer.inventoryChanges.action;
|
|
|
|
// Because we send PlayerInventory packets from the same OpenMW methods that we use to set the
|
|
// items received, we need to set a boolean to prevent resending the items set here
|
|
localPlayer.isReceivingInventory = true;
|
|
|
|
if (inventoryAction == InventoryChanges::ADD)
|
|
localPlayer.addItems();
|
|
else if (inventoryAction == InventoryChanges::REMOVE)
|
|
localPlayer.removeItems();
|
|
else // InventoryChanges::SET
|
|
localPlayer.setInventory();
|
|
|
|
localPlayer.isReceivingInventory = false;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif //OPENMW_PROCESSORPLAYERUPDATEINVENTORY_HPP
|