From 134dd06d483fe163cf529f9e3078d6bb6d210110 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 31 Aug 2017 08:35:46 +0300 Subject: [PATCH] [Client] Only add valid inventory & equipment items to LocalPlayer Also add related debug information. --- apps/openmw/mwmp/LocalPlayer.cpp | 29 +++++++++++++++---- .../player/ProcessorPlayerEquipment.hpp | 2 ++ .../player/ProcessorPlayerInventory.hpp | 2 ++ .../player/ProcessorPlayerSpellbook.hpp | 2 ++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index f71c43e50..c5bfbd09b 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -636,9 +636,16 @@ void LocalPlayer::addItems() for (const auto &item : inventoryChanges.items) { - MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer); - if (item.charge != -1) - itemPtr.getCellRef().setCharge(item.charge); + try + { + MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer); + if (item.charge != -1) + itemPtr.getCellRef().setCharge(item.charge); + } + catch (std::exception&) + { + LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid inventory item %s", item.refId.c_str()); + } } } @@ -651,6 +658,8 @@ void LocalPlayer::addSpells() // Only add spells that are ensured to exist if (MWBase::Environment::get().getWorld()->getStore().get().search(spell.mId)) ptrSpells.add(spell.mId); + else + LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid spell %s", spell.mId.c_str()); } void LocalPlayer::addJournalItems() @@ -891,11 +900,19 @@ void LocalPlayer::setEquipment() return Misc::StringUtils::ciEqual(a.getCellRef().getRefId(), currentItem.refId); }); - if (it == ptrInventory.end()) // if not exists add item + if (it == ptrInventory.end()) // If the item is not in our inventory, add it { auto equipped = equipedItems[slot]; - auto addIter = ptrInventory.ContainerStore::add(equipped.refId.c_str(), equipped.count, ptrPlayer); - ptrInventory.equip(slot, addIter, ptrPlayer); + + try + { + auto addIter = ptrInventory.ContainerStore::add(equipped.refId.c_str(), equipped.count, ptrPlayer); + ptrInventory.equip(slot, addIter, ptrPlayer); + } + catch (std::exception&) + { + LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid equipment item %s", equipped.refId.c_str()); + } } else ptrInventory.equip(slot, it, ptrPlayer); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerEquipment.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerEquipment.hpp index 5a0fd5b69..aff7a3c86 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerEquipment.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerEquipment.hpp @@ -22,6 +22,8 @@ namespace mwmp { if (isLocal()) { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_EQUIPMENT about LocalPlayer from server"); + if (isRequest()) static_cast(player)->updateEquipment(true); else diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp index f4a32f64a..9595f01c4 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp @@ -21,6 +21,8 @@ namespace mwmp { if (!isLocal()) return; + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_INVENTORY about LocalPlayer from server"); + if (isRequest()) static_cast(player)->updateInventory(true); else diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp index 2a9ac3131..b4c70f925 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp @@ -22,6 +22,8 @@ namespace mwmp { if (!isLocal()) return; + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_SPELLBOOK about LocalPlayer from server"); + if (isRequest()) static_cast(player)->sendSpellbook(); else