2018-03-06 22:22:19 +01:00
|
|
|
#include <Common.h>
|
|
|
|
#include <Network/CommonNetwork.h>
|
|
|
|
#include <Network/GamePacketNew.h>
|
|
|
|
#include <Logging/Logger.h>
|
|
|
|
#include <Network/PacketContainer.h>
|
|
|
|
#include <Exd/ExdDataGenerated.h>
|
2018-03-02 07:22:25 -03:00
|
|
|
|
2018-12-01 00:27:16 +11:00
|
|
|
#include "Manager/TerritoryMgr.h"
|
|
|
|
#include "Territory/InstanceContent.h"
|
2017-12-08 15:38:25 +01:00
|
|
|
|
|
|
|
#include "Network/GameConnection.h"
|
|
|
|
#include "Network/PacketWrappers/ServerNoticePacket.h"
|
|
|
|
#include "Network/PacketWrappers/PlayerStateFlagsPacket.h"
|
2018-03-02 07:22:25 -03:00
|
|
|
|
|
|
|
#include "Framework.h"
|
|
|
|
#include "Session.h"
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire::Common;
|
|
|
|
using namespace Sapphire::Network::Packets;
|
|
|
|
using namespace Sapphire::Network::Packets::Server;
|
2018-12-01 00:27:16 +11:00
|
|
|
using namespace Sapphire::World::Manager;
|
2017-08-17 00:07:42 +02:00
|
|
|
|
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
void Sapphire::Network::GameConnection::cfDutyInfoRequest( FrameworkPtr pFw,
|
|
|
|
const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
2018-11-29 16:55:48 +01:00
|
|
|
Entity::Player& player )
|
2017-08-17 00:07:42 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto dutyInfoPacket = makeZonePacket< FFXIVIpcCFDutyInfo >( player.getId() );
|
|
|
|
auto penaltyMinutes = player.getCFPenaltyMinutes();
|
|
|
|
if( penaltyMinutes > 255 )
|
|
|
|
{
|
|
|
|
// cap it since it's uint8_t in packets
|
|
|
|
penaltyMinutes = 255;
|
|
|
|
}
|
|
|
|
dutyInfoPacket->data().penaltyTime = penaltyMinutes;
|
|
|
|
queueOutPacket( dutyInfoPacket );
|
|
|
|
|
|
|
|
auto inNeedsPacket = makeZonePacket< FFXIVIpcCFPlayerInNeed >( player.getId() );
|
|
|
|
queueOutPacket( inNeedsPacket );
|
2017-08-17 00:07:42 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
void Sapphire::Network::GameConnection::cfRegisterDuty( FrameworkPtr pFw,
|
|
|
|
const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
|
|
|
Entity::Player& player )
|
2017-08-17 00:07:42 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
Packets::FFXIVARR_PACKET_RAW copy = inPacket;
|
2018-12-23 03:53:08 +01:00
|
|
|
auto pTeriMgr = pFw->get< TerritoryMgr >();
|
|
|
|
auto pExdData = pFw->get< Data::ExdDataGenerated >();
|
2018-03-16 21:40:59 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::vector< uint16_t > selectedContent;
|
2018-03-16 21:40:59 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
for( uint32_t offset = 0x1E; offset <= 0x26; offset += 0x2 )
|
|
|
|
{
|
|
|
|
auto id = *reinterpret_cast< uint16_t* >( ©.data[ offset ] );
|
|
|
|
if( id == 0 )
|
|
|
|
break;
|
2018-03-16 21:40:59 +11:00
|
|
|
|
2019-01-05 12:32:10 +01:00
|
|
|
player.sendDebug( "got contentId#{0}", id );
|
2018-03-16 21:40:59 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
selectedContent.push_back( id );
|
|
|
|
}
|
2018-03-16 21:40:59 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// todo: rand bias problem, will do for now tho
|
|
|
|
auto index = std::rand() % selectedContent.size();
|
|
|
|
auto contentId = selectedContent.at( index );
|
2018-03-16 21:40:59 +11:00
|
|
|
|
2019-01-05 12:32:10 +01:00
|
|
|
player.sendDebug( "Duty register request for contentid#{0}", contentId );
|
2017-08-19 11:28:04 +09:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// let's cancel it because otherwise you can't register it again
|
|
|
|
auto cfCancelPacket = makeZonePacket< FFXIVIpcCFNotify >( player.getId() );
|
|
|
|
cfCancelPacket->data().state1 = 3;
|
|
|
|
cfCancelPacket->data().state2 = 1; // Your registration is withdrawn.
|
|
|
|
queueOutPacket( cfCancelPacket );
|
2018-02-05 01:55:10 +11:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
auto cfCondition = pExdData->get< Sapphire::Data::ContentFinderCondition >( contentId );
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !cfCondition )
|
|
|
|
return;
|
2018-02-05 01:55:10 +11:00
|
|
|
|
2018-11-23 21:16:02 +01:00
|
|
|
auto instance = pTeriMgr->createInstanceContent( cfCondition->content );
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !instance )
|
|
|
|
return;
|
2018-02-05 01:55:10 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pInstance = instance->getAsInstanceContent();
|
2018-09-19 23:26:36 +02:00
|
|
|
pInstance->bindPlayer( player.getId() );
|
2018-03-16 21:40:59 +11:00
|
|
|
|
2019-01-05 12:32:10 +01:00
|
|
|
player.sendDebug( "Created instance with id#", instance->getGuId() );
|
2018-02-05 01:55:10 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.setInstance( instance );
|
2017-08-17 00:07:42 +02:00
|
|
|
}
|
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
void Sapphire::Network::GameConnection::cfRegisterRoulette( FrameworkPtr pFw,
|
|
|
|
const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
|
|
|
Entity::Player& player )
|
2017-08-17 00:07:42 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto cfCancelPacket = makeZonePacket< FFXIVIpcCFNotify >( player.getId() );
|
|
|
|
cfCancelPacket->data().state1 = 3;
|
|
|
|
cfCancelPacket->data().state2 = 1; // Your registration is withdrawn.
|
|
|
|
queueOutPacket( cfCancelPacket );
|
2018-03-16 21:40:59 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
player.sendDebug( "Roulette register" );
|
2017-08-17 00:07:42 +02:00
|
|
|
}
|
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
void Sapphire::Network::GameConnection::cfDutyAccepted( FrameworkPtr pFw,
|
|
|
|
const Packets::FFXIVARR_PACKET_RAW& inPacket,
|
|
|
|
Entity::Player& player )
|
2017-08-17 00:07:42 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
player.sendDebug( "TODO: Duty accept" );
|
2017-08-17 00:07:42 +02:00
|
|
|
}
|