diff --git a/apps/openmw-mp/CellController.cpp b/apps/openmw-mp/CellController.cpp index 48330c53e..6f1b96838 100644 --- a/apps/openmw-mp/CellController.cpp +++ b/apps/openmw-mp/CellController.cpp @@ -86,8 +86,15 @@ Cell *CellController::addCell(ESM::Cell cellData) auto it = find_if(cells.begin(), cells.end(), [cellData](const Cell *c) { // Currently we cannot compare because plugin lists can be loaded in different order //return c->cell.sRecordId == cellData.sRecordId; - return c->cell.isExterior() ? (c->cell.mData.mX == cellData.mData.mX && c->cell.mData.mY == cellData.mData.mY) : - (c->cell.mName == cellData.mName); + if (c->cell.isExterior() && cellData.isExterior()) + { + if (c->cell.mData.mX == cellData.mData.mX && c->cell.mData.mY == cellData.mData.mY) + return true; + } + else if (c->cell.mName == cellData.mName) + return true; + + return false; }); Cell *cell; diff --git a/apps/openmw/mwmp/GUI/GUIChat.cpp b/apps/openmw/mwmp/GUI/GUIChat.cpp index 8ded6456a..7e464ce47 100644 --- a/apps/openmw/mwmp/GUI/GUIChat.cpp +++ b/apps/openmw/mwmp/GUI/GUIChat.cpp @@ -123,7 +123,7 @@ namespace mwmp else { mHistory->addText(color + msg); - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, msg.c_str()); + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", msg.c_str()); } } diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 1e72c1a9d..497981884 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -639,9 +639,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,33 +658,38 @@ void LocalPlayer::addSpells() MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells(); for (const auto &spell : spellbookChanges.spells) - { - if(spell.mId.find("$dynamic") != string::npos) - { - //custom spell - MWBase::Environment::get().getWorld()->createRecord(spell); - ptrSpells.add(&spell); - }else{ + // 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() { for (const auto &journalItem : journalChanges.journalItems) { + MWWorld::Ptr ptrFound; + if (journalItem.type == JournalItem::ENTRY) { - MWWorld::Ptr ptrFound = MWBase::Environment::get().getWorld()->searchPtr(journalItem.actorRefId, false); + ptrFound = MWBase::Environment::get().getWorld()->searchPtr(journalItem.actorRefId, false); if (!ptrFound) ptrFound = getPlayerPtr(); + } - MWBase::Environment::get().getJournal()->addEntry(journalItem.quest, journalItem.index, ptrFound); + try + { + if (journalItem.type == JournalItem::ENTRY) + MWBase::Environment::get().getJournal()->addEntry(journalItem.quest, journalItem.index, ptrFound); + else + MWBase::Environment::get().getJournal()->setJournalIndex(journalItem.quest, journalItem.index); + } + catch (std::exception&) + { + LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid journal quest %s", journalItem.quest.c_str()); } - else - MWBase::Environment::get().getJournal()->setJournalIndex(journalItem.quest, journalItem.index); } } @@ -903,11 +915,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/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 5e10478c9..38dd17245 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -328,7 +328,7 @@ void Networking::preInit(std::vector &content, Files::Collections & if (col.doesExist(*it)) { PacketPreInit::HashList hashList; - unsigned crc32 = Utils::crc32checksum(col.getPath(*it).string()); + unsigned crc32 = Utils::crc32Checksum(col.getPath(*it).string()); hashList.push_back(crc32); checksums.push_back(make_pair(*it, hashList)); 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/ProcessorPlayerJournal.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerJournal.hpp index ee104cc85..93c982b62 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerJournal.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerJournal.hpp @@ -15,6 +15,8 @@ namespace mwmp virtual void Do(PlayerPacket &packet, BasePlayer *player) { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_JOURNAL from server"); + if (isRequest()) { // Entire journal cannot currently be requested from players 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 diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index f947d7134..fa221154a 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -526,6 +526,10 @@ namespace MWWorld */ Ptr CellStore::searchExact (unsigned int refNumIndex, unsigned int mpNum) { + // Ensure that all objects searched for have a valid reference number + if (refNumIndex == 0 && mpNum == 0) + return 0; + SearchExactVisitor searchVisitor; searchVisitor.mRefNumIndexToFind = refNumIndex; searchVisitor.mMpNumToFind = mpNum; diff --git a/components/openmw-mp/Packets/BasePacket.hpp b/components/openmw-mp/Packets/BasePacket.hpp index b51ce0695..8dd964a03 100644 --- a/components/openmw-mp/Packets/BasePacket.hpp +++ b/components/openmw-mp/Packets/BasePacket.hpp @@ -80,7 +80,7 @@ namespace mwmp { if (write) { - RakNet::RakString rstr(str.c_str()); + RakNet::RakString rstr("%s", str.c_str()); if (compress) rstr.SerializeCompressed(bs); else diff --git a/components/openmw-mp/Utils.cpp b/components/openmw-mp/Utils.cpp index bd8e25d32..14a194268 100644 --- a/components/openmw-mp/Utils.cpp +++ b/components/openmw-mp/Utils.cpp @@ -54,7 +54,7 @@ void Utils::timestamp() } // http://stackoverflow.com/questions/1637587/c-libcurl-console-progress-bar -int Utils::progress_func(double TotalToDownload, double NowDownloaded) +int Utils::progressFunc(double TotalToDownload, double NowDownloaded) { // how wide you want the progress meter to be int totaldotz=40; @@ -79,7 +79,7 @@ int Utils::progress_func(double TotalToDownload, double NowDownloaded) return 1; } -bool Utils::DoubleCompare(double a, double b, double epsilon) +bool Utils::compareDoubles(double a, double b, double epsilon) { return fabs(a - b) < epsilon; } @@ -91,7 +91,7 @@ std::string Utils::toString(int num) return stream.str(); } -string Utils::str_replace(const string& source, const char* find, const char* replace) +string Utils::replaceString(const string& source, const char* find, const char* replace) { unsigned int find_len = strlen(find); unsigned int replace_len = strlen(replace); @@ -108,7 +108,7 @@ string Utils::str_replace(const string& source, const char* find, const char* re return dest; } -string& Utils::RemoveExtension(string& file) +string& Utils::removeExtension(string& file) { size_t pos = file.find_last_of('.'); @@ -118,7 +118,7 @@ string& Utils::RemoveExtension(string& file) return file; } -long int Utils::FileLength(const char* file) +long int Utils::getFileLength(const char* file) { FILE* _file = fopen(file, "rb"); @@ -132,7 +132,7 @@ long int Utils::FileLength(const char* file) return size; } -unsigned int ::Utils::crc32checksum(const std::string &file) +unsigned int ::Utils::crc32Checksum(const std::string &file) { boost::crc_32_type crc32; boost::filesystem::ifstream ifs(file, std::ios_base::binary); diff --git a/components/openmw-mp/Utils.hpp b/components/openmw-mp/Utils.hpp index 78bf99c8a..00cbd8cab 100644 --- a/components/openmw-mp/Utils.hpp +++ b/components/openmw-mp/Utils.hpp @@ -22,19 +22,19 @@ namespace Utils void timestamp(); - int progress_func(double TotalToDownload, double NowDownloaded); + int progressFunc(double TotalToDownload, double NowDownloaded); - bool DoubleCompare(double a, double b, double epsilon); + bool compareDoubles(double a, double b, double epsilon); - std::string str_replace(const std::string &source, const char *find, const char *replace); + std::string replaceString(const std::string &source, const char *find, const char *replace); std::string toString(int num); - std::string &RemoveExtension(std::string &file); + std::string &removeExtension(std::string &file); - long int FileLength(const char *file); + long int getFileLength(const char *file); - unsigned int crc32checksum(const std::string &file); + unsigned int crc32Checksum(const std::string &file); void printWithWidth(std::ostringstream &sstr, std::string str, size_t width);