1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-04-01 20:36:42 +00:00

[General] Modernize packet style for PlayerFaction

This commit is contained in:
David Cernat 2019-10-26 11:42:40 +03:00
parent c9f3ee1819
commit cbe58b1c24
3 changed files with 13 additions and 16 deletions

View file

@ -24,7 +24,7 @@ unsigned int FactionFunctions::GetFactionChangesSize(unsigned short pid) noexcep
Player *player; Player *player;
GET_PLAYER(pid, player, 0); GET_PLAYER(pid, player, 0);
return player->factionChanges.count; return player->factionChanges.factions.size();
} }
unsigned char FactionFunctions::GetFactionChangesAction(unsigned short pid) noexcept unsigned char FactionFunctions::GetFactionChangesAction(unsigned short pid) noexcept
@ -40,7 +40,7 @@ const char *FactionFunctions::GetFactionId(unsigned short pid, unsigned int inde
Player *player; Player *player;
GET_PLAYER(pid, player, ""); GET_PLAYER(pid, player, "");
if (index >= player->factionChanges.count) if (index >= player->factionChanges.factions.size())
return "invalid"; return "invalid";
return player->factionChanges.factions.at(index).factionId.c_str(); return player->factionChanges.factions.at(index).factionId.c_str();

View file

@ -91,7 +91,6 @@ namespace mwmp
struct FactionChanges struct FactionChanges
{ {
std::vector<Faction> factions; std::vector<Faction> factions;
unsigned int count;
enum FACTION_ACTION enum FACTION_ACTION
{ {
@ -100,7 +99,7 @@ namespace mwmp
REPUTATION = 2 REPUTATION = 2
}; };
int action; // 0 - Rank, 1 - Expulsion state, 2 - Both int action; // 0 - Rank, 1 - Expulsion state, 2 - Faction reputation
}; };
struct InventoryChanges struct InventoryChanges

View file

@ -15,20 +15,21 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
RW(player->factionChanges.action, send); RW(player->factionChanges.action, send);
uint32_t count;
if (send) if (send)
player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size()); count = static_cast<uint32_t>(player->factionChanges.factions.size());
else
player->factionChanges.factions.clear();
RW(player->factionChanges.count, send); RW(count, send);
for (unsigned int i = 0; i < player->factionChanges.count; i++) if (!send)
{ {
Faction faction; player->factionChanges.factions.clear();
player->factionChanges.factions.resize(count);
if (send) }
faction = player->factionChanges.factions.at(i);
for (auto &&faction : player->factionChanges.factions)
{
RW(faction.factionId, send, true); RW(faction.factionId, send, true);
if (player->factionChanges.action == FactionChanges::RANK) if (player->factionChanges.action == FactionChanges::RANK)
@ -39,8 +40,5 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
if (player->factionChanges.action == FactionChanges::REPUTATION) if (player->factionChanges.action == FactionChanges::REPUTATION)
RW(faction.reputation, send); RW(faction.reputation, send);
if (!send)
player->factionChanges.factions.push_back(faction);
} }
} }