1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 19:19:56 +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());
player.exchangeFullInfo = true;
player.forEachLoaded([this](Player *pl, Player *other) {
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_ATTRIBUTE)->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_SHAPESHIFT)->Send(other->guid);
other->exchangeFullInfo = false;
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());
LOG_APPEND(Log::LOG_INFO, "- Finished processing ID_PLAYER_CELL_CHANGE", player.cell.getDescription().c_str());
player.exchangeFullInfo = false;
}
else
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.count = 0;
exchangeFullInfo = false;
displayCreatureName = false;
resetStats = false;
enforcedLogLevel = -1;
@ -259,6 +260,8 @@ namespace mwmp
// with the items themselves being stored in equipmentItems
std::vector<int> equipmentIndexChanges;
bool exchangeFullInfo;
InventoryChanges inventoryChanges;
SpellbookChanges spellbookChanges;
QuickKeyChanges quickKeyChanges;

View file

@ -13,23 +13,34 @@ void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
count = static_cast<uint32_t>(player->attributeIndexChanges.size());
RW(player->exchangeFullInfo, send);
RW(count, send);
if (!send)
if (player->exchangeFullInfo)
{
player->attributeIndexChanges.clear();
player->attributeIndexChanges.resize(count);
RW(player->creatureStats.mAttributes, send);
RW(player->npcStats.mSkillIncrease, send);
}
for (auto &&attributeIndex : player->attributeIndexChanges)
else
{
RW(attributeIndex, send);
uint32_t count;
RW(player->creatureStats.mAttributes[attributeIndex], send);
RW(player->npcStats.mSkillIncrease[attributeIndex], send);
if (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 <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp;
@ -12,25 +13,42 @@ void PacketPlayerEquipment::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
count = static_cast<uint32_t>(player->equipmentIndexChanges.size());
RW(player->exchangeFullInfo, send);
RW(count, send);
if (!send)
if (player->exchangeFullInfo)
{
player->equipmentIndexChanges.clear();
player->equipmentIndexChanges.resize(count);
for (auto &&equipmentItem : player->equipmentItems)
{
ExchangeItemInformation(equipmentItem, send);
}
}
for (auto &&equipmentIndex : player->equipmentIndexChanges)
else
{
RW(equipmentIndex, send);
uint32_t count;
if (send)
count = static_cast<uint32_t>(player->equipmentIndexChanges.size());
RW(player->equipmentItems[equipmentIndex].refId, send);
RW(player->equipmentItems[equipmentIndex].count, send);
RW(player->equipmentItems[equipmentIndex].charge, send);
RW(player->equipmentItems[equipmentIndex].enchantmentCharge, send);
RW(count, send);
if (!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);
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);
uint32_t count;
RW(player->exchangeFullInfo, send);
if (send)
count = static_cast<uint32_t>(player->skillIndexChanges.size());
RW(count, send);
if (!send)
if (player->exchangeFullInfo)
{
player->skillIndexChanges.clear();
player->skillIndexChanges.resize(count);
RW(player->npcStats.mSkills, send);
}
for (auto &&skillId : player->skillIndexChanges)
else
{
RW(skillId, send);
RW(player->npcStats.mSkills[skillId], send);
uint32_t count;
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 <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp;
@ -12,22 +13,32 @@ void PacketPlayerStatsDynamic::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
count = static_cast<uint32_t>(player->statsDynamicIndexChanges.size());
RW(player->exchangeFullInfo, send);
RW(count, send);
if (!send)
if (player->exchangeFullInfo)
{
player->statsDynamicIndexChanges.clear();
player->statsDynamicIndexChanges.resize(count);
RW(player->creatureStats.mDynamic, send);
}
for (auto &&statsDynamicIndex : player->statsDynamicIndexChanges)
else
{
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);
}
}
}