1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 09:45:32 +00:00

[General] Fix information exchange for players sharing a cell

Previously, two players entering the same cell only sent and received their latest changes for dynamic stats, attributes, skills and equipment when they started sharing that cell.
This commit is contained in:
David Cernat 2018-04-26 21:56:14 +03:00
parent 7db74509e0
commit 66d5109509
7 changed files with 114 additions and 53 deletions

View file

@ -30,10 +30,14 @@ namespace mwmp
{ {
LOG_APPEND(Log::LOG_INFO, "- Moved to %s", player.cell.getDescription().c_str()); LOG_APPEND(Log::LOG_INFO, "- Moved to %s", player.cell.getDescription().c_str());
player.exchangeFullInfo = true;
player.forEachLoaded([this](Player *pl, Player *other) { player.forEachLoaded([this](Player *pl, Player *other) {
LOG_APPEND(Log::LOG_INFO, "- Started information exchange with %s", other->npc.mName.c_str()); LOG_APPEND(Log::LOG_INFO, "- Started information exchange with %s", other->npc.mName.c_str());
other->exchangeFullInfo = true;
playerController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(other); playerController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(other);
playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(other); playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(other);
playerController->GetPacket(ID_PLAYER_POSITION)->setPlayer(other); playerController->GetPacket(ID_PLAYER_POSITION)->setPlayer(other);
@ -64,6 +68,8 @@ namespace mwmp
playerController->GetPacket(ID_PLAYER_ANIM_FLAGS)->Send(other->guid); playerController->GetPacket(ID_PLAYER_ANIM_FLAGS)->Send(other->guid);
playerController->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(other->guid); playerController->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(other->guid);
other->exchangeFullInfo = false;
LOG_APPEND(Log::LOG_INFO, "- Finished information exchange with %s", other->npc.mName.c_str()); LOG_APPEND(Log::LOG_INFO, "- Finished information exchange with %s", other->npc.mName.c_str());
}); });
@ -75,6 +81,8 @@ namespace mwmp
Script::Call<Script::CallbackIdentity("OnPlayerCellChange")>(player.getId()); Script::Call<Script::CallbackIdentity("OnPlayerCellChange")>(player.getId());
LOG_APPEND(Log::LOG_INFO, "- Finished processing ID_PLAYER_CELL_CHANGE", player.cell.getDescription().c_str()); LOG_APPEND(Log::LOG_INFO, "- Finished processing ID_PLAYER_CELL_CHANGE", player.cell.getDescription().c_str());
player.exchangeFullInfo = false;
} }
else else
LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead", player.npc.mName.c_str()); LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead", player.npc.mName.c_str());

View file

@ -227,6 +227,7 @@ namespace mwmp
spellbookChanges.action = 0; spellbookChanges.action = 0;
spellbookChanges.count = 0; spellbookChanges.count = 0;
exchangeFullInfo = false;
displayCreatureName = false; displayCreatureName = false;
resetStats = false; resetStats = false;
enforcedLogLevel = -1; enforcedLogLevel = -1;
@ -259,6 +260,8 @@ namespace mwmp
// with the items themselves being stored in equipmentItems // with the items themselves being stored in equipmentItems
std::vector<int> equipmentIndexChanges; std::vector<int> equipmentIndexChanges;
bool exchangeFullInfo;
InventoryChanges inventoryChanges; InventoryChanges inventoryChanges;
SpellbookChanges spellbookChanges; SpellbookChanges spellbookChanges;
QuickKeyChanges quickKeyChanges; QuickKeyChanges quickKeyChanges;

View file

@ -13,23 +13,34 @@ void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
uint32_t count; RW(player->exchangeFullInfo, send);
if (send)
count = static_cast<uint32_t>(player->attributeIndexChanges.size());
RW(count, send); if (player->exchangeFullInfo)
if (!send)
{ {
player->attributeIndexChanges.clear(); RW(player->creatureStats.mAttributes, send);
player->attributeIndexChanges.resize(count); RW(player->npcStats.mSkillIncrease, send);
} }
else
for (auto &&attributeIndex : player->attributeIndexChanges)
{ {
RW(attributeIndex, send); uint32_t count;
RW(player->creatureStats.mAttributes[attributeIndex], send); if (send)
RW(player->npcStats.mSkillIncrease[attributeIndex], send); count = static_cast<uint32_t>(player->attributeIndexChanges.size());
RW(count, send);
if (!send)
{
player->attributeIndexChanges.clear();
player->attributeIndexChanges.resize(count);
}
for (auto &&attributeIndex : player->attributeIndexChanges)
{
RW(attributeIndex, send);
RW(player->creatureStats.mAttributes[attributeIndex], send);
RW(player->npcStats.mSkillIncrease[attributeIndex], send);
}
} }
} }

View file

@ -1,4 +1,5 @@
#include "PacketPlayerEquipment.hpp" #include "PacketPlayerEquipment.hpp"
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp; using namespace mwmp;
@ -12,25 +13,42 @@ void PacketPlayerEquipment::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
uint32_t count; RW(player->exchangeFullInfo, send);
if (send)
count = static_cast<uint32_t>(player->equipmentIndexChanges.size());
RW(count, send); if (player->exchangeFullInfo)
if (!send)
{ {
player->equipmentIndexChanges.clear(); for (auto &&equipmentItem : player->equipmentItems)
player->equipmentIndexChanges.resize(count); {
ExchangeItemInformation(equipmentItem, send);
}
} }
else
for (auto &&equipmentIndex : player->equipmentIndexChanges)
{ {
RW(equipmentIndex, send); uint32_t count;
if (send)
count = static_cast<uint32_t>(player->equipmentIndexChanges.size());
RW(player->equipmentItems[equipmentIndex].refId, send); RW(count, send);
RW(player->equipmentItems[equipmentIndex].count, send);
RW(player->equipmentItems[equipmentIndex].charge, send); if (!send)
RW(player->equipmentItems[equipmentIndex].enchantmentCharge, send); {
player->equipmentIndexChanges.clear();
player->equipmentIndexChanges.resize(count);
}
for (auto &&equipmentIndex : player->equipmentIndexChanges)
{
RW(equipmentIndex, send);
ExchangeItemInformation(player->equipmentItems[equipmentIndex], send);
}
} }
} }
void PacketPlayerEquipment::ExchangeItemInformation(Item &item, bool send)
{
RW(item.refId, send);
RW(item.count, send);
RW(item.charge, send);
RW(item.enchantmentCharge, send);
}

View file

@ -15,6 +15,7 @@ namespace mwmp
PacketPlayerEquipment(RakNet::RakPeerInterface *peer); PacketPlayerEquipment(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Packet(RakNet::BitStream *bs, bool send);
void ExchangeItemInformation(Item &item, bool send);
}; };
} }

View file

@ -14,22 +14,31 @@ void PacketPlayerSkill::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
uint32_t count; RW(player->exchangeFullInfo, send);
if (send) if (player->exchangeFullInfo)
count = static_cast<uint32_t>(player->skillIndexChanges.size());
RW(count, send);
if (!send)
{ {
player->skillIndexChanges.clear(); RW(player->npcStats.mSkills, send);
player->skillIndexChanges.resize(count);
} }
else
for (auto &&skillId : player->skillIndexChanges)
{ {
RW(skillId, send); uint32_t count;
RW(player->npcStats.mSkills[skillId], send);
if (send)
count = static_cast<uint32_t>(player->skillIndexChanges.size());
RW(count, send);
if (!send)
{
player->skillIndexChanges.clear();
player->skillIndexChanges.resize(count);
}
for (auto &&skillId : player->skillIndexChanges)
{
RW(skillId, send);
RW(player->npcStats.mSkills[skillId], send);
}
} }
} }

View file

@ -1,4 +1,5 @@
#include "PacketPlayerStatsDynamic.hpp" #include "PacketPlayerStatsDynamic.hpp"
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp; using namespace mwmp;
@ -12,22 +13,32 @@ void PacketPlayerStatsDynamic::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
uint32_t count; RW(player->exchangeFullInfo, send);
if (send)
count = static_cast<uint32_t>(player->statsDynamicIndexChanges.size());
RW(count, send); if (player->exchangeFullInfo)
if (!send)
{ {
player->statsDynamicIndexChanges.clear(); RW(player->creatureStats.mDynamic, send);
player->statsDynamicIndexChanges.resize(count);
} }
else
for (auto &&statsDynamicIndex : player->statsDynamicIndexChanges)
{ {
RW(statsDynamicIndex, send); uint32_t count;
RW(player->creatureStats.mDynamic[statsDynamicIndex], send); if (send)
count = static_cast<uint32_t>(player->statsDynamicIndexChanges.size());
RW(count, send);
if (!send)
{
player->statsDynamicIndexChanges.clear();
player->statsDynamicIndexChanges.resize(count);
}
for (auto &&statsDynamicIndex : player->statsDynamicIndexChanges)
{
RW(statsDynamicIndex, send);
RW(player->creatureStats.mDynamic[statsDynamicIndex], send);
}
} }
} }