2018-01-09 23:50:54 +01:00
|
|
|
#include "Director.h"
|
2018-02-06 00:01:23 +01:00
|
|
|
|
2022-02-16 05:29:08 +01:00
|
|
|
#include <Territory/InstanceContent.h>
|
|
|
|
|
2022-02-16 09:43:27 +01:00
|
|
|
#include <Network/PacketWrappers/EventLogMessagePacket.h>
|
2018-03-06 22:22:19 +01:00
|
|
|
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
2018-06-23 21:38:04 +02:00
|
|
|
#include <Network/CommonActorControl.h>
|
2023-03-08 09:20:08 +01:00
|
|
|
#include "Network/PacketWrappers/ActorControlPacket.h"
|
|
|
|
#include "Network/PacketWrappers/ActorControlSelfPacket.h"
|
|
|
|
#include "Network/GameConnection.h"
|
|
|
|
#include "Network/Util/PacketUtil.h"
|
2018-02-07 00:00:48 +01:00
|
|
|
|
|
|
|
#include "Actor/Player.h"
|
|
|
|
|
2019-03-31 23:45:03 +02:00
|
|
|
#include <Logging/Logger.h>
|
2018-02-07 00:00:48 +01:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
#include <Service.h>
|
|
|
|
#include "WorldServer.h"
|
|
|
|
#include "Session.h"
|
2023-03-08 09:20:08 +01:00
|
|
|
|
2018-02-07 00:00:48 +01:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire::Common;
|
|
|
|
using namespace Sapphire::Network::Packets;
|
2021-11-27 00:53:57 +01:00
|
|
|
using namespace Sapphire::Network::Packets::WorldPackets::Server;
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire::Network::ActorControl;
|
2018-02-07 00:00:48 +01:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
Sapphire::Event::Director::Director( Sapphire::Event::Director::DirectorType type, uint16_t contentId ) :
|
|
|
|
m_contextId( contentId ),
|
2018-08-29 21:40:59 +02:00
|
|
|
m_type( type ),
|
|
|
|
m_directorId( ( static_cast< uint32_t >( type ) << 16 ) | contentId ),
|
|
|
|
m_sequence( 1 ),
|
2021-11-27 00:53:57 +01:00
|
|
|
m_flags( 0 )
|
2018-02-06 00:01:23 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
memset( m_vars, 0, sizeof( m_vars ) );
|
2018-02-06 00:01:23 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Event::Director::getDirectorId() const
|
2018-02-06 00:01:23 +01:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
return m_directorId;
|
2018-02-06 00:01:23 +01:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
uint16_t Sapphire::Event::Director::getContextId() const
|
2018-02-06 00:01:23 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
return m_contextId;
|
2021-08-16 17:18:29 +09:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint8_t Sapphire::Event::Director::getSequence() const
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
return m_sequence;
|
2018-02-07 00:00:48 +01:00
|
|
|
}
|
|
|
|
|
2022-02-16 09:43:27 +01:00
|
|
|
void Sapphire::Event::Director::sendEventLogMessage( Sapphire::Entity::Player& player, Sapphire::InstanceContent& instance, uint32_t msgId, std::initializer_list< uint32_t > args ) const
|
2022-02-16 05:29:08 +01:00
|
|
|
{
|
2022-02-16 09:43:27 +01:00
|
|
|
FFXIVPacketBasePtr packet = nullptr;
|
|
|
|
|
|
|
|
assert( args.size() <= 32 );
|
|
|
|
|
2022-02-16 05:29:08 +01:00
|
|
|
if( args.size() == 0 )
|
|
|
|
{
|
2022-02-16 09:43:27 +01:00
|
|
|
packet = std::move( std::make_shared< class EventLogMessageHeader >( player, instance.getDirectorId(), msgId ) );
|
2022-02-16 05:29:08 +01:00
|
|
|
}
|
|
|
|
else if( args.size() <= 2 )
|
|
|
|
{
|
2022-02-16 09:43:27 +01:00
|
|
|
packet = std::move( std::make_shared< class EventLogMessage2 >( player, instance.getDirectorId(), msgId, args ) );
|
2022-02-16 05:29:08 +01:00
|
|
|
}
|
|
|
|
else if( args.size() <= 4 )
|
|
|
|
{
|
2022-02-16 09:43:27 +01:00
|
|
|
packet = std::move( std::make_shared< class EventLogMessage4 >( player, instance.getDirectorId(), msgId, args ) );
|
2022-02-16 05:29:08 +01:00
|
|
|
}
|
|
|
|
else if( args.size() <= 8 )
|
|
|
|
{
|
2022-02-16 09:43:27 +01:00
|
|
|
packet = std::move( std::make_shared< class EventLogMessage8 >( player, instance.getDirectorId(), msgId, args ) );
|
2022-02-16 05:29:08 +01:00
|
|
|
}
|
|
|
|
else if( args.size() <= 16 )
|
|
|
|
{
|
2022-02-16 09:43:27 +01:00
|
|
|
packet = std::move( std::make_shared< class EventLogMessage16 >( player, instance.getDirectorId(), msgId, args ) );
|
2022-02-16 05:29:08 +01:00
|
|
|
}
|
|
|
|
else if( args.size() <= 32 )
|
|
|
|
{
|
2022-02-16 09:43:27 +01:00
|
|
|
packet = std::move( std::make_shared< class EventLogMessage32 >( player, instance.getDirectorId(), msgId, args ) );
|
2022-02-16 05:29:08 +01:00
|
|
|
}
|
2022-02-16 09:43:27 +01:00
|
|
|
|
|
|
|
instance.queuePacketForZone( player, packet, true );
|
2022-02-16 05:29:08 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Event::Director::sendDirectorClear( Sapphire::Entity::Player& player ) const
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2023-03-08 09:20:08 +01:00
|
|
|
Network::Util::Packet::sendActorControlSelf( player, DirectorClear, m_directorId );
|
2018-02-07 00:00:48 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Event::Director::sendDirectorVars( Sapphire::Entity::Player& player ) const
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto varPacket = makeZonePacket< FFXIVIpcDirectorVars >( player.getId() );
|
2021-11-27 00:53:57 +01:00
|
|
|
varPacket->data().directorId = getDirectorId();
|
|
|
|
varPacket->data().sequence = getSequence();
|
|
|
|
varPacket->data().flags = getFlags();
|
|
|
|
memcpy( varPacket->data().vars, m_vars, sizeof( m_vars ) );
|
|
|
|
server.queueForPlayer( player.getCharacterId(), varPacket );
|
2018-02-07 00:00:48 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Event::Director::sendDirectorInit( Sapphire::Entity::Player& player ) const
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
Logger::debug( "[{}] directorInit: directorId#{}, contextId#{}", player.getId(), m_directorId, m_contextId );
|
2023-03-08 09:20:08 +01:00
|
|
|
Network::Util::Packet::sendActorControlSelf( player, DirectorInit, m_directorId, m_contextId );
|
2018-02-07 00:00:48 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::Event::Director::DirectorType Sapphire::Event::Director::getType() const
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
return m_type;
|
2018-02-07 00:00:48 +01:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
uint8_t Sapphire::Event::Director::getFlags() const
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
return m_flags;
|
2018-02-07 00:00:48 +01:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Event::Director::setDirectorFlags( uint8_t value )
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
m_flags = value;
|
2018-02-07 00:00:48 +01:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Event::Director::setDirectorSequence( uint8_t value )
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
m_sequence = value;
|
2018-02-07 00:00:48 +01:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Event::Director::setDirectorVar( uint8_t index, uint8_t value )
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
if( index < sizeof( m_vars ) )
|
|
|
|
{
|
|
|
|
m_vars[ index ] = value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Logger::warn( "[{0}] Director::setDirectorVar - out of range index {1} value {2}", m_directorId, index, value );
|
2018-02-07 00:00:48 +01:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
uint8_t Sapphire::Event::Director::getDirectorVar( uint8_t index )
|
2018-02-07 00:00:48 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
if( index < sizeof( m_vars ) )
|
|
|
|
{
|
|
|
|
return m_vars[ index ];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Logger::warn( "[{0}] Director::getDirectorVar - out of range index {1}", m_directorId, index );
|
2018-02-28 22:25:11 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
return 0;
|
2018-02-28 22:25:11 +11:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Event::Director::setDirectorVar( uint8_t index, uint8_t valueLeft, uint8_t valueRight )
|
2018-02-28 22:25:11 +11:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
setDirectorVar( index, ( valueRight & 0x0F ) + ( valueLeft << 4 ) );
|
2018-02-28 22:25:11 +11:00
|
|
|
}
|
2019-04-17 00:10:32 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
uint8_t Sapphire::Event::Director::getDirectorVar( uint8_t index, bool shiftLeft )
|
2019-04-17 00:10:32 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
return getDirectorVar( index ) & ( shiftLeft ? 0xF0 : 0x0F );
|
2019-04-17 00:10:32 +02:00
|
|
|
}
|
2022-02-15 00:06:16 +01:00
|
|
|
|
|
|
|
void Sapphire::Event::Director::setCustomVar( uint32_t index, uint64_t value )
|
|
|
|
{
|
|
|
|
m_customVarMap[ index ] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Sapphire::Event::Director::getCustomVar( uint32_t index )
|
|
|
|
{
|
|
|
|
auto it = m_customVarMap.find( index );
|
|
|
|
if( it != m_customVarMap.end() )
|
|
|
|
return it->second;
|
|
|
|
return 0;
|
|
|
|
}
|