openmw-tes3coop/components/openmw-mp/Packets/Player/PacketPlayerAttribute.cpp
David Cernat b0965f094a [General] Rework PlayerAttribute packets so they are of minimal size
Previously, whenever a single attribute value changed for a player, that player then sent a PlayerAttribute packet with all values for all 8 attributes.

This did not cause anywhere as much packet spam as PlayerSkill used to, but there was no good reason not to fix it as well.
2017-11-24 14:28:05 +02:00

35 lines
964 B
C++

#include "PacketPlayerAttribute.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp;
PacketPlayerAttribute::PacketPlayerAttribute(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)
{
packetID = ID_PLAYER_ATTRIBUTE;
}
void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
if (send)
player->attributeChanges.count = (unsigned int)(player->attributeChanges.attributeIndexes.size());
else
player->attributeChanges.attributeIndexes.clear();
RW(player->attributeChanges.count, send);
for (unsigned int i = 0; i < player->attributeChanges.count; i++)
{
int attributeId;
if (send)
attributeId = player->attributeChanges.attributeIndexes.at(i);
RW(attributeId, send);
RW(player->creatureStats.mAttributes[attributeId], send);
RW(player->npcStats.mSkillIncrease[attributeId], send);
}
}