1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 23:27:45 +00:00
sapphire/src/servers/sapphire_zone/Network/PacketWrappers/PlayerStateFlagsPacket.h

59 lines
1.2 KiB
C
Raw Normal View History

2017-08-08 13:53:47 +02:00
#ifndef _PLAYERSTATE_H
#define _PLAYERSTATE_H
2018-03-06 22:22:19 +01:00
#include <Network/GamePacketNew.h>
#include "Actor/Player.h"
#include "Forwards.h"
2017-08-08 13:53:47 +02:00
namespace Core {
namespace Network {
namespace Packets {
namespace Server {
/**
* @brief Packet sent to set a players state, this impacts which actions he can perform.
2017-08-08 13:53:47 +02:00
*/
class PlayerStateFlagsPacket :
public ZoneChannelPacket< FFXIVIpcPlayerStateFlags >
2017-08-08 13:53:47 +02:00
{
public:
PlayerStateFlagsPacket( Entity::Player& player ) :
ZoneChannelPacket< FFXIVIpcPlayerStateFlags >( player.getId(), player.getId() )
{
initialize( player.getStateFlags() );
}
2017-08-08 13:53:47 +02:00
PlayerStateFlagsPacket( Entity::Player& player, std::vector< Common::PlayerStateFlag > flags ) :
ZoneChannelPacket< FFXIVIpcPlayerStateFlags >( player.getId(), player.getId() )
{
uint8_t newFlags[12];
memset( newFlags, 0, 12 );
2017-08-08 13:53:47 +02:00
for( auto& flag : flags )
{
int32_t iFlag = static_cast< uint32_t >( flag );
uint8_t index = iFlag / 8;
uint8_t bitIndex = iFlag % 8;
2017-08-08 13:53:47 +02:00
uint8_t value = 1 << bitIndex;
2017-08-08 13:53:47 +02:00
newFlags[ index ] |= value;
}
2017-08-08 13:53:47 +02:00
initialize( newFlags );
}
2017-08-08 13:53:47 +02:00
private:
void initialize( const uint8_t* flags )
{
memcpy( m_data.flags, flags, 12 );
};
2017-08-08 13:53:47 +02:00
};
}
}
}
}
#endif /*_PLAYERSTATE_H*/