1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-04-01 19:06:42 +00:00

[Client] Avoid PlayerInventory packet spam when creating many potions

This commit is contained in:
David Cernat 2020-02-25 07:45:06 +02:00
parent 31c0f5c976
commit dae805dbc1
3 changed files with 63 additions and 0 deletions

View file

@ -22,6 +22,7 @@
#include <components/openmw-mp/TimedLog.hpp> #include <components/openmw-mp/TimedLog.hpp>
#include "../mwmp/Main.hpp" #include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp" #include "../mwmp/Networking.hpp"
#include "../mwmp/LocalPlayer.hpp"
#include "../mwmp/Worldstate.hpp" #include "../mwmp/Worldstate.hpp"
/* /*
End of tes3mp addition End of tes3mp addition
@ -278,6 +279,16 @@ void MWMechanics::Alchemy::removeIngredients()
{ {
iter->getContainerStore()->remove(*iter, 1, mAlchemist); iter->getContainerStore()->remove(*iter, 1, mAlchemist);
/*
Start of tes3mp addition
Store this item removal for later sending to avoid packet spam
*/
mwmp::Main::get().getLocalPlayer()->storeItemRemoval(iter->getCellRef().getRefId(), 1);
/*
End of tes3mp addition
*/
if (iter->getRefData().getCount()<1) if (iter->getRefData().getCount()<1)
*iter = MWWorld::Ptr(); *iter = MWWorld::Ptr();
} }
@ -524,6 +535,19 @@ MWMechanics::Alchemy::Result MWMechanics::Alchemy::getReadyStatus() const
MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& name, int& count) MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& name, int& count)
{ {
/*
Start of tes3mp addition
Instead of sending an ID_PLAYER_INVENTORY packet for every ingredient removal in
ContainerStore::remove(), as that would get very spammy when many potions are created
at the same time, just avoid sending packets here and store the item removals so they
can be sent in a single packet when all the potions have been created
*/
mwmp::Main::get().getLocalPlayer()->avoidSendingInventoryPackets = true;
/*
End of tes3mp addition
*/
setPotionName(name); setPotionName(name);
Result readyStatus = getReadyStatus(); Result readyStatus = getReadyStatus();
@ -551,8 +575,12 @@ MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& na
Send an ID_RECORD_DYNAMIC packet with the potion we've been creating Send an ID_RECORD_DYNAMIC packet with the potion we've been creating
now that we know its quantity now that we know its quantity
Stop avoiding the sending of ID_PLAYER_INVENTORY packets
*/ */
mwmp::Main::get().getNetworking()->getWorldstate()->sendPotionRecord(&mStoredPotion, brewedCount); mwmp::Main::get().getNetworking()->getWorldstate()->sendPotionRecord(&mStoredPotion, brewedCount);
mwmp::Main::get().getLocalPlayer()->avoidSendingInventoryPackets = false;
mwmp::Main::get().getLocalPlayer()->sendStoredItemRemovals();
/* /*
End of tes3mp addition End of tes3mp addition
*/ */

View file

@ -44,6 +44,8 @@
using namespace mwmp; using namespace mwmp;
using namespace std; using namespace std;
std::map<std::string, int> storedItemRemovals;
LocalPlayer::LocalPlayer() LocalPlayer::LocalPlayer()
{ {
deathTime = time(0); deathTime = time(0);
@ -1453,6 +1455,32 @@ void LocalPlayer::sendItemChange(const std::string& refId, int count, unsigned i
getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->Send();
} }
void LocalPlayer::sendStoredItemRemovals()
{
inventoryChanges.items.clear();
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending stored item removals for LocalPlayer:");
for (auto storedItemRemoval : storedItemRemovals)
{
mwmp::Item item;
item.refId = storedItemRemoval.first;
item.count = storedItemRemoval.second;
item.charge = -1;
item.enchantmentCharge = -1;
item.soul = "";
inventoryChanges.items.push_back(item);
LOG_APPEND(TimedLog::LOG_INFO, "- %s with count %i", item.refId.c_str(), item.count);
}
inventoryChanges.action = mwmp::InventoryChanges::ACTION_TYPE::REMOVE;
getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->Send();
storedItemRemovals.clear();
}
void LocalPlayer::sendSpellbook() void LocalPlayer::sendSpellbook()
{ {
MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWWorld::Ptr ptrPlayer = getPlayerPtr();
@ -1710,6 +1738,11 @@ void LocalPlayer::storeCurrentContainer(const MWWorld::Ptr &container)
currentContainer.mpNum = container.getCellRef().getMpNum(); currentContainer.mpNum = container.getCellRef().getMpNum();
} }
void LocalPlayer::storeItemRemoval(const std::string& refId, int count)
{
storedItemRemovals[refId] = storedItemRemovals[refId] + count;
}
void LocalPlayer::playAnimation() void LocalPlayer::playAnimation()
{ {
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(getPlayerPtr(), MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(getPlayerPtr(),

View file

@ -82,6 +82,7 @@ namespace mwmp
void sendItemChange(const mwmp::Item& item, unsigned int action); void sendItemChange(const mwmp::Item& item, unsigned int action);
void sendItemChange(const MWWorld::Ptr& itemPtr, int count, unsigned int action); void sendItemChange(const MWWorld::Ptr& itemPtr, int count, unsigned int action);
void sendItemChange(const std::string& refId, int count, unsigned int action); void sendItemChange(const std::string& refId, int count, unsigned int action);
void sendStoredItemRemovals();
void sendSpellbook(); void sendSpellbook();
void sendSpellChange(std::string id, unsigned int action); void sendSpellChange(std::string id, unsigned int action);
void sendQuickKey(unsigned short slot, int type, const std::string& itemId = ""); void sendQuickKey(unsigned short slot, int type, const std::string& itemId = "");
@ -103,6 +104,7 @@ namespace mwmp
void storeCellState(const ESM::Cell& cell, int stateType); void storeCellState(const ESM::Cell& cell, int stateType);
void storeCurrentContainer(const MWWorld::Ptr& container); void storeCurrentContainer(const MWWorld::Ptr& container);
void storeItemRemoval(const std::string& refId, int count);
void playAnimation(); void playAnimation();
void playSpeech(); void playSpeech();