From bce3d0eb4c00017c26ea7ec2b291274a4ad3d9c1 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 15 Jan 2018 05:55:12 +0200 Subject: [PATCH 1/5] [Client] Use more descriptive message for version mismatch --- apps/openmw/mwmp/Networking.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index ae0eb5eda..b4714a922 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -300,8 +300,8 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector } case ID_INVALID_PASSWORD: { - errmsg = "Connection failed.\n" - "The client or server is outdated."; + errmsg = "Version mismatch!\nYour client is on version " TES3MP_VERSION "\n" + "Please make sure the server is on the same version."; queue = false; break; } From f746958afa0bd3cb135bd354fffdbc41be6bba80 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 15 Jan 2018 06:28:05 +0200 Subject: [PATCH 2/5] [Client] Send enchantmentCharge for items added or removed in containers --- apps/openmw/mwgui/container.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 31848c62d..82fcde95c 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -127,6 +127,7 @@ namespace MWGui containerItem.refId =itemPtr.getCellRef().getRefId(); containerItem.count = itemPtr.getRefData().getCount(); containerItem.charge = itemPtr.getCellRef().getCharge(); + containerItem.enchantmentCharge = itemPtr.getCellRef().getEnchantmentCharge(); containerItem.actionCount = count; worldObject.containerItems.push_back(containerItem); @@ -175,6 +176,7 @@ namespace MWGui containerItem.count = mDragAndDrop->mDraggedCount; containerItem.charge = itemPtr.getCellRef().getCharge(); + containerItem.enchantmentCharge = itemPtr.getCellRef().getEnchantmentCharge(); worldObject.containerItems.push_back(containerItem); worldEvent->addObject(worldObject); From 9935f56d461edd26ab11ef2aa92d8d07bdfd9310 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 17 Jan 2018 08:09:57 +0200 Subject: [PATCH 3/5] [General] Use doubles instead of ints for enchantmentCharge Additionally, include enchantmentCharges for items in PlayerEquipment packets. --- apps/openmw-mp/Script/Functions/Actors.cpp | 4 ++-- apps/openmw-mp/Script/Functions/Actors.hpp | 4 ++-- apps/openmw-mp/Script/Functions/Items.cpp | 8 ++++---- apps/openmw-mp/Script/Functions/Items.hpp | 8 ++++---- apps/openmw-mp/Script/Functions/World.cpp | 8 ++++---- apps/openmw-mp/Script/Functions/World.hpp | 8 ++++---- components/openmw-mp/Base/BaseEvent.hpp | 4 ++-- components/openmw-mp/Base/BaseStructs.hpp | 2 +- .../openmw-mp/Packets/Player/PacketPlayerEquipment.cpp | 2 ++ 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index 1f50cbf55..c195f4b4b 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -163,7 +163,7 @@ int ActorFunctions::GetActorEquipmentItemCharge(unsigned int i, unsigned short s return readActorList->baseActors.at(i).equipedItems[slot].charge; } -int ActorFunctions::GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept +double ActorFunctions::GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept { return readActorList->baseActors.at(i).equipedItems[slot].enchantmentCharge; } @@ -267,7 +267,7 @@ void ActorFunctions::SetActorFatigueModified(double value) noexcept tempActor.creatureStats.mDynamic[2].mMod = value; } -void ActorFunctions::EquipActorItem(unsigned short slot, const char *refId, unsigned int count, int charge, int enchantmentCharge) noexcept +void ActorFunctions::EquipActorItem(unsigned short slot, const char *refId, unsigned int count, int charge, double enchantmentCharge) noexcept { tempActor.equipedItems[slot].refId = refId; tempActor.equipedItems[slot].count = count; diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index c1ae6bce2..d3dbc8200 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -308,7 +308,7 @@ public: * \param slot The slot of the equipment item. * \return The enchantment charge. */ - static int GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept; + static double GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept; /** * \brief Check whether there is any positional data for the actor at a certain index in @@ -492,7 +492,7 @@ public: * \param enchantmentCharge The enchantment charge of the item. * \return void */ - static void EquipActorItem(unsigned short slot, const char* refId, unsigned int count, int charge, int enchantmentCharge = -1) noexcept; + static void EquipActorItem(unsigned short slot, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept; /** * \brief Unequip the item in a certain slot of the equipment of the temporary actor stored diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index 7ff6fc8e7..1bc35a829 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -35,7 +35,7 @@ unsigned int ItemFunctions::GetInventoryChangesSize(unsigned short pid) noexcept return player->inventoryChanges.count; } -void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *refId, unsigned int count, int charge, int enchantmentCharge) noexcept +void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *refId, unsigned int count, int charge, double enchantmentCharge) noexcept { Player *player; GET_PLAYER(pid, player,); @@ -54,7 +54,7 @@ void ItemFunctions::UnequipItem(unsigned short pid, unsigned short slot) noexcep ItemFunctions::EquipItem(pid, slot, "", 0, -1, -1); } -void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, int enchantmentCharge) noexcept +void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, double enchantmentCharge) noexcept { Player *player; GET_PLAYER(pid, player, ); @@ -117,7 +117,7 @@ int ItemFunctions::GetEquipmentItemCharge(unsigned short pid, unsigned short slo return player->equipedItems[slot].charge; } -int ItemFunctions::GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept +double ItemFunctions::GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept { Player *player; GET_PLAYER(pid, player, 0); @@ -152,7 +152,7 @@ int ItemFunctions::GetInventoryItemCharge(unsigned short pid, unsigned int i) no return player->inventoryChanges.items.at(i).charge; } -int ItemFunctions::GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept +double ItemFunctions::GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept { Player *player; GET_PLAYER(pid, player, 0); diff --git a/apps/openmw-mp/Script/Functions/Items.hpp b/apps/openmw-mp/Script/Functions/Items.hpp index 9350be896..b19c396b3 100644 --- a/apps/openmw-mp/Script/Functions/Items.hpp +++ b/apps/openmw-mp/Script/Functions/Items.hpp @@ -41,10 +41,10 @@ public: static int GetEquipmentSize() noexcept; static unsigned int GetInventoryChangesSize(unsigned short pid) noexcept; - static void EquipItem(unsigned short pid, unsigned short slot, const char* refId, unsigned int count, int charge, int enchantmentCharge = -1) noexcept; + static void EquipItem(unsigned short pid, unsigned short slot, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept; static void UnequipItem(unsigned short pid, unsigned short slot) noexcept; - static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, int enchantmentCharge = -1) noexcept; + static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept; static void RemoveItem(unsigned short pid, const char* refId, unsigned short count) noexcept; static bool HasItemEquipped(unsigned short pid, const char* refId); @@ -52,12 +52,12 @@ public: static const char *GetEquipmentItemRefId(unsigned short pid, unsigned short slot) noexcept; static int GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept; static int GetEquipmentItemCharge(unsigned short pid, unsigned short slot) noexcept; - static int GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept; + static double GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept; static const char *GetInventoryItemRefId(unsigned short pid, unsigned int i) noexcept; static int GetInventoryItemCount(unsigned short pid, unsigned int i) noexcept; static int GetInventoryItemCharge(unsigned short pid, unsigned int i) noexcept; - static int GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept; + static double GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept; static void SendEquipment(unsigned short pid) noexcept; static void SendInventoryChanges(unsigned short pid, bool toOthers = false) noexcept; diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index 871582051..4423d1d05 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -69,7 +69,7 @@ int WorldFunctions::GetObjectCharge(unsigned int i) noexcept return readEvent->worldObjects.at(i).charge; } -int WorldFunctions::GetObjectEnchantmentCharge(unsigned int i) noexcept +double WorldFunctions::GetObjectEnchantmentCharge(unsigned int i) noexcept { return readEvent->worldObjects.at(i).enchantmentCharge; } @@ -152,7 +152,7 @@ int WorldFunctions::GetContainerItemCharge(unsigned int objectIndex, unsigned in .containerItems.at(itemIndex).charge; } -int WorldFunctions::GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept +double WorldFunctions::GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept { return readEvent->worldObjects.at(objectIndex) .containerItems.at(itemIndex).enchantmentCharge; @@ -204,7 +204,7 @@ void WorldFunctions::SetObjectCharge(int charge) noexcept tempWorldObject.charge = charge; } -void WorldFunctions::SetObjectEnchantmentCharge(int enchantmentCharge) noexcept +void WorldFunctions::SetObjectEnchantmentCharge(double enchantmentCharge) noexcept { tempWorldObject.enchantmentCharge = enchantmentCharge; } @@ -282,7 +282,7 @@ void WorldFunctions::SetContainerItemCharge(int charge) noexcept tempContainerItem.charge = charge; } -void WorldFunctions::SetContainerItemEnchantmentCharge(int enchantmentCharge) noexcept +void WorldFunctions::SetContainerItemEnchantmentCharge(double enchantmentCharge) noexcept { tempContainerItem.enchantmentCharge = enchantmentCharge; } diff --git a/apps/openmw-mp/Script/Functions/World.hpp b/apps/openmw-mp/Script/Functions/World.hpp index 485d3a365..7667254a5 100644 --- a/apps/openmw-mp/Script/Functions/World.hpp +++ b/apps/openmw-mp/Script/Functions/World.hpp @@ -158,7 +158,7 @@ public: * \param i The index of the object. * \return The enchantment charge. */ - static int GetObjectEnchantmentCharge(unsigned int i) noexcept; + static double GetObjectEnchantmentCharge(unsigned int i) noexcept; /** * \brief Get the gold value of the object at a certain index in the read event's object @@ -307,7 +307,7 @@ public: * \param itemIndex The index of the container item. * \return The enchantment charge. */ - static int GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept; + static double GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept; /** * \brief Get the action count of the container item at a certain itemIndex in the container @@ -414,7 +414,7 @@ public: * \param charge The enchantment charge. * \return void */ - static void SetObjectEnchantmentCharge(int enchantmentCharge) noexcept; + static void SetObjectEnchantmentCharge(double enchantmentCharge) noexcept; /** * \brief Set the gold value of the temporary world object stored on the server. @@ -542,7 +542,7 @@ public: * \param charge The enchantment charge. * \return void */ - static void SetContainerItemEnchantmentCharge(int enchantmentCharge) noexcept; + static void SetContainerItemEnchantmentCharge(double enchantmentCharge) noexcept; /** * \brief Add a copy of the server's temporary world object to the server's temporary event. diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index f7718412c..081f189c0 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -12,7 +12,7 @@ namespace mwmp std::string refId; int count; int charge; - int enchantmentCharge; + double enchantmentCharge; int actionCount; @@ -29,7 +29,7 @@ namespace mwmp int mpNum; int count; int charge; - int enchantmentCharge; + double enchantmentCharge; int goldValue; ESM::Position position; diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index b915a903c..798323c91 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -12,7 +12,7 @@ namespace mwmp std::string refId; int count; int charge; - int enchantmentCharge; + double enchantmentCharge; inline bool operator==(const Item& rhs) { diff --git a/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp b/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp index 07fcfe8e4..4b54c006c 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp @@ -5,6 +5,7 @@ #include "PacketPlayerEquipment.hpp" #include + using namespace mwmp; PacketPlayerEquipment::PacketPlayerEquipment(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) @@ -21,5 +22,6 @@ void PacketPlayerEquipment::Packet(RakNet::BitStream *bs, bool send) RW(player->equipedItems[i].refId, send, 1); RW(player->equipedItems[i].count, send); RW(player->equipedItems[i].charge, send); + RW(player->equipedItems[i].enchantmentCharge, send); } } From 28f47c4f8119bf5b0044f442857d463cd9540214 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 17 Jan 2018 08:10:24 +0200 Subject: [PATCH 4/5] [General] Update version to 0.6.2-hotfixed --- components/openmw-mp/Version.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/openmw-mp/Version.hpp b/components/openmw-mp/Version.hpp index 09cd8ab43..708e204cb 100644 --- a/components/openmw-mp/Version.hpp +++ b/components/openmw-mp/Version.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_VERSION_HPP #define OPENMW_VERSION_HPP -#define TES3MP_VERSION "0.6.2" +#define TES3MP_VERSION "0.6.2-hotfixed" #define TES3MP_PROTO_VERSION 7 #define TES3MP_DEFAULT_PASSW "SuperPassword" From 5894ffae7d0c1abf0bbdb418c17dc9d62c88f1c2 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 17 Jan 2018 11:01:31 +0200 Subject: [PATCH 5/5] [Client] Ignore dynamic object placements or spawns in packets --- apps/openmw/mwgui/alchemywindow.cpp | 2 +- apps/openmw/mwmp/WorldEvent.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index 500115f83..5557e7b0d 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -97,7 +97,7 @@ namespace MWGui Include a messagebox notifying players that player-made potions are not synced yet */ - MWBase::Environment::get().getWindowManager()->messageBox("Player-made potions are not synchronized in multiplayer yet and they will not show up for other players."); + MWBase::Environment::get().getWindowManager()->messageBox("Player-made potions are not synchronized in multiplayer yet and they will not show up for the server or other players."); /* End of tes3mp addition */ diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index 07e3f4534..3ba14ef2b 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -83,6 +83,9 @@ void WorldEvent::editContainers(MWWorld::CellStore* cellStore) MWWorld::Ptr ownerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); for (const auto &containerItem : worldObject.containerItems) { + if (containerItem.refId.find("$dynamic") != string::npos) + continue; + if (action == BaseEvent::ADD || action == BaseEvent::SET) { // Create a ManualRef to be able to set item charge @@ -160,6 +163,10 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore) LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i, count: %i, charge: %i, enchantmentCharge: %i", worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.mpNum, worldObject.count, worldObject.charge, worldObject.enchantmentCharge); + // Ignore generic dynamic refIds because they could be anything on other clients + if (worldObject.refId.find("$dynamic") != string::npos) + continue; + MWWorld::Ptr ptrFound = cellStore->searchExact(0, worldObject.mpNum); // Only create this object if it doesn't already exist @@ -195,6 +202,10 @@ void WorldEvent::spawnObjects(MWWorld::CellStore* cellStore) LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i", worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.mpNum); + // Ignore generic dynamic refIds because they could be anything on other clients + if (worldObject.refId.find("$dynamic") != string::npos) + continue; + MWWorld::Ptr ptrFound = cellStore->searchExact(0, worldObject.mpNum); // Only create this object if it doesn't already exist @@ -599,6 +610,12 @@ void WorldEvent::playVideo() void WorldEvent::addObjectPlace(const MWWorld::Ptr& ptr) { + if (ptr.getCellRef().getRefId().find("$dynamic") != string::npos) + { + MWBase::Environment::get().getWindowManager()->messageBox("You're trying to place a custom item, but those are not synchronized in multiplayer yet."); + return; + } + cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -624,6 +641,12 @@ void WorldEvent::addObjectPlace(const MWWorld::Ptr& ptr) void WorldEvent::addObjectSpawn(const MWWorld::Ptr& ptr) { + if (ptr.getCellRef().getRefId().find("$dynamic") != string::npos) + { + MWBase::Environment::get().getWindowManager()->messageBox("You're trying to spawn a custom object, but those are not synchronized in multiplayer yet."); + return; + } + cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -821,6 +844,9 @@ void WorldEvent::addScriptGlobalShort(std::string varName, int shortVal) void WorldEvent::sendObjectPlace() { + if (worldObjects.size() == 0) + return; + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_PLACE about %s", cell.getDescription().c_str()); for (const auto &worldObject : worldObjects) @@ -832,6 +858,9 @@ void WorldEvent::sendObjectPlace() void WorldEvent::sendObjectSpawn() { + if (worldObjects.size() == 0) + return; + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_SPAWN about %s", cell.getDescription().c_str()); for (const auto &worldObject : worldObjects)