From cbe58b1c24a8346e8b38a310ccf4a679d18d841d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 26 Oct 2019 11:42:40 +0300 Subject: [PATCH] [General] Modernize packet style for PlayerFaction --- apps/openmw-mp/Script/Functions/Factions.cpp | 4 ++-- components/openmw-mp/Base/BasePlayer.hpp | 3 +-- .../Packets/Player/PacketPlayerFaction.cpp | 22 +++++++++---------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Factions.cpp b/apps/openmw-mp/Script/Functions/Factions.cpp index 668b1a786..5816b95a5 100644 --- a/apps/openmw-mp/Script/Functions/Factions.cpp +++ b/apps/openmw-mp/Script/Functions/Factions.cpp @@ -24,7 +24,7 @@ unsigned int FactionFunctions::GetFactionChangesSize(unsigned short pid) noexcep Player *player; GET_PLAYER(pid, player, 0); - return player->factionChanges.count; + return player->factionChanges.factions.size(); } unsigned char FactionFunctions::GetFactionChangesAction(unsigned short pid) noexcept @@ -40,7 +40,7 @@ const char *FactionFunctions::GetFactionId(unsigned short pid, unsigned int inde Player *player; GET_PLAYER(pid, player, ""); - if (index >= player->factionChanges.count) + if (index >= player->factionChanges.factions.size()) return "invalid"; return player->factionChanges.factions.at(index).factionId.c_str(); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 5fd30627e..e3ca16fa0 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -91,7 +91,6 @@ namespace mwmp struct FactionChanges { std::vector factions; - unsigned int count; enum FACTION_ACTION { @@ -100,7 +99,7 @@ namespace mwmp REPUTATION = 2 }; - int action; // 0 - Rank, 1 - Expulsion state, 2 - Both + int action; // 0 - Rank, 1 - Expulsion state, 2 - Faction reputation }; struct InventoryChanges diff --git a/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp b/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp index 9e00013a7..6fb68cdf5 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp @@ -15,20 +15,21 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send) RW(player->factionChanges.action, send); + uint32_t count; + if (send) - player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size()); - else - player->factionChanges.factions.clear(); + count = static_cast(player->factionChanges.factions.size()); - RW(player->factionChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->factionChanges.count; i++) + if (!send) { - Faction faction; - - if (send) - faction = player->factionChanges.factions.at(i); + player->factionChanges.factions.clear(); + player->factionChanges.factions.resize(count); + } + for (auto &&faction : player->factionChanges.factions) + { RW(faction.factionId, send, true); if (player->factionChanges.action == FactionChanges::RANK) @@ -39,8 +40,5 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send) if (player->factionChanges.action == FactionChanges::REPUTATION) RW(faction.reputation, send); - - if (!send) - player->factionChanges.factions.push_back(faction); } }