1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-22 20:57:46 +00:00

Merge pull request #64 from Minoost/master

Reimplement CFPenaltyTime to reflect recent refactoring
This commit is contained in:
SapphireMordred 2017-08-19 09:19:25 +02:00 committed by GitHub
commit bb4a84d51a
11 changed files with 144 additions and 63 deletions

View file

@ -77,6 +77,7 @@ CREATE TABLE charadetail (
`ContentRetryTime` blob, `ContentRetryTime` blob,
`ContentJoinTime` int(10) DEFAULT NULL, `ContentJoinTime` int(10) DEFAULT NULL,
`ContentClearFlag` blob, `ContentClearFlag` blob,
`CFPenaltyUntil` int unsigned NOT NULL DEFAULT '0',
`TownWarpFstFlags` binary(2) DEFAULT NULL, `TownWarpFstFlags` binary(2) DEFAULT NULL,
`PathId` int(10) DEFAULT NULL, `PathId` int(10) DEFAULT NULL,
`StepIndex` int(5) DEFAULT NULL, `StepIndex` int(5) DEFAULT NULL,

View file

@ -285,13 +285,15 @@ namespace Core {
HpMp = 0x00000800, HpMp = 0x00000800,
QuestTracker = 0x00001000, QuestTracker = 0x00001000,
NewGame = 0x00002000, NewGame = 0x00002000,
// 0x4000 is missing here
Unlocks = 0x00008000, Unlocks = 0x00008000,
PlayTime = 0x00010000, PlayTime = 0x00010000,
NewAdventurer = 0x00020000, NewAdventurer = 0x00020000,
SearchInfo = 0x00040000, SearchInfo = 0x00040000,
GC = 0x00080000, GC = 0x00080000,
CFPenaltyTime = 0x00100000,
All = 0xFFFFFFFF, All = 0xFFFFFFFF,
}; };

View file

@ -17,17 +17,14 @@ std::string Core::Util::binaryToHexString( uint8_t* pBinData, uint16_t size )
uint64_t Core::Util::getTimeMs() uint64_t Core::Util::getTimeMs()
{ {
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); std::chrono::milliseconds epoch = std::chrono::duration_cast< std::chrono::milliseconds >(std::chrono::system_clock::now().time_since_epoch());
auto now_ms = std::chrono::time_point_cast< std::chrono::milliseconds >( t1 ).time_since_epoch().count(); return epoch.count();
return now_ms;
} }
uint64_t Core::Util::getTimeSeconds() uint64_t Core::Util::getTimeSeconds()
{ {
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); std::chrono::seconds epoch = std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::now().time_since_epoch());
auto now = std::chrono::time_point_cast< std::chrono::seconds >( t1 ).time_since_epoch().count(); return epoch.count();
return now;
} }
uint64_t Core::Util::getEorzeanTimeStamp() uint64_t Core::Util::getEorzeanTimeStamp()

View file

@ -1569,3 +1569,39 @@ void Core::Entity::Player::handleScriptSkill( uint32_t type, uint32_t actionId,
break; break;
} }
} }
/////////////////////////////
// Content Finder
/////////////////////////////
uint32_t Core::Entity::Player::getCFPenaltyTimestamp() const
{
return m_cfPenaltyUntil;
}
void Core::Entity::Player::setCFPenaltyTimestamp( uint32_t timestamp )
{
m_cfPenaltyUntil = timestamp;
setSyncFlag( PlayerSyncFlags::CFPenaltyTime );
}
uint32_t Core::Entity::Player::getCFPenaltyMinutes() const
{
auto currentTimestamp = Core::Util::getTimeSeconds();
auto endTimestamp = getCFPenaltyTimestamp();
// check if penalty timestamp already passed current time
if (currentTimestamp > endTimestamp)
{
return 0;
}
auto deltaTime = endTimestamp - currentTimestamp;
return static_cast< uint32_t > ( ceil( static_cast< float > (deltaTime) / 60 ) );
}
void Core::Entity::Player::setCFPenaltyMinutes( uint32_t minutes )
{
auto currentTimestamp = Core::Util::getTimeSeconds();
setCFPenaltyTimestamp(static_cast< uint32_t >( currentTimestamp + minutes * 60 ));
}

View file

@ -484,6 +484,16 @@ public:
void handleScriptSkill( uint32_t type, uint32_t actionId, uint64_t param1, uint64_t param2, Entity::Actor& target ); void handleScriptSkill( uint32_t type, uint32_t actionId, uint64_t param1, uint64_t param2, Entity::Actor& target );
// Content Finder handling
//////////////////////////////////////////////////////////////////////////////////////////////////////
/*! Get an unix time when the player can register into content finder again. */
uint32_t getCFPenaltyTimestamp() const;
/*! Set an unix time when the player can register into content finder again. */
void setCFPenaltyTimestamp( uint32_t timestamp );
uint32_t getCFPenaltyMinutes() const;
void setCFPenaltyMinutes( uint32_t minutes );
private: private:
uint32_t m_lastWrite; uint32_t m_lastWrite;
uint32_t m_lastPing; uint32_t m_lastPing;
@ -599,6 +609,8 @@ private:
uint8_t m_gc; uint8_t m_gc;
uint8_t m_gcRank[3]; uint8_t m_gcRank[3];
// content finder info
uint32_t m_cfPenaltyUntil; // unix time
}; };
} }

View file

@ -43,7 +43,8 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
// TODO: can't help but think that the whole player loading could be handled better... // TODO: can't help but think that the whole player loading could be handled better...
const std::string char_id_str = std::to_string( charId ); const std::string char_id_str = std::to_string( charId );
auto pQR = g_database.query( "SELECT c.Name, " auto pQR = g_database.query( "SELECT "
"c.Name, "
"c.PrimaryTerritoryId, " "c.PrimaryTerritoryId, "
"c.Hp, " "c.Hp, "
"c.Mp, " "c.Mp, "
@ -53,7 +54,7 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
"c.Pos_0_1, " "c.Pos_0_1, "
"c.Pos_0_2, " "c.Pos_0_2, "
"c.Pos_0_3, " "c.Pos_0_3, "
"c.FirstLogin, " "c.FirstLogin, " // 10
"c.Customize, " "c.Customize, "
"c.ModelMainWeapon, " "c.ModelMainWeapon, "
"c.ModelSubWeapon, " "c.ModelSubWeapon, "
@ -63,7 +64,7 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
"cd.BirthMonth, " "cd.BirthMonth, "
"cd.Status, " "cd.Status, "
"cd.Class, " "cd.Class, "
"cd.Homepoint, " "cd.Homepoint, " // 20
"cd.HowTo, " "cd.HowTo, "
"c.ContentId, " "c.ContentId, "
"c.Voice, " "c.Voice, "
@ -73,11 +74,12 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
"cd.Aetheryte, " "cd.Aetheryte, "
"cd.unlocks, " "cd.unlocks, "
"cd.Discovery, " "cd.Discovery, "
"cd.StartTown, " "cd.StartTown, " // 30
"cd.TotalPlayTime, " "cd.TotalPlayTime, "
"c.IsNewAdventurer, " "c.IsNewAdventurer, "
"cd.GrandCompany, " "cd.GrandCompany, "
"cd.GrandCompanyRank " "cd.GrandCompanyRank, "
"cd.CFPenaltyUntil "
"FROM charabase AS c " "FROM charabase AS c "
" INNER JOIN charadetail AS cd " " INNER JOIN charadetail AS cd "
" ON c.CharacterId = cd.CharacterId " " ON c.CharacterId = cd.CharacterId "
@ -166,6 +168,8 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
m_gc = field[33].getUInt8(); m_gc = field[33].getUInt8();
field[34].getBinary( reinterpret_cast< char* >( m_gcRank ), 3 ); field[34].getBinary( reinterpret_cast< char* >( m_gcRank ), 3 );
m_cfPenaltyUntil = field[35].getUInt32();
m_pCell = nullptr; m_pCell = nullptr;
if( !loadActiveQuests() || !loadClassData() || !loadSearchInfo() ) if( !loadActiveQuests() || !loadClassData() || !loadSearchInfo() )
@ -327,7 +331,10 @@ void Core::Entity::Player::createUpdateSql()
charaDetailSet.insert( " GrandCompanyRank = UNHEX('" + std::string( Util::binaryToHexString( reinterpret_cast< uint8_t* >( m_gcRank ), sizeof( m_gcRank ) ) ) + "')" ); charaDetailSet.insert( " GrandCompanyRank = UNHEX('" + std::string( Util::binaryToHexString( reinterpret_cast< uint8_t* >( m_gcRank ), sizeof( m_gcRank ) ) ) + "')" );
} }
if( m_updateFlags & PlayerSyncFlags::CFPenaltyTime )
{
charaDetailSet.insert( " CFPenaltyUntil = " + std::to_string( m_cfPenaltyUntil ) );
}
if( m_updateFlags & PlayerSyncFlags::ExpLevel ) if( m_updateFlags & PlayerSyncFlags::ExpLevel )
{ {

View file

@ -0,0 +1,7 @@
#ifndef _CONTENTFINDER_H
#define _CONTENTFINDER_H
#include "../Forwards.h"
#endif

View file

@ -104,7 +104,6 @@ void Core::DebugCommandHandler::execCommand( char * data, Core::Entity::PlayerPt
} }
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
// Definition of the commands // Definition of the commands
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
@ -267,8 +266,6 @@ void Core::DebugCommandHandler::set( char * data, Core::Entity::PlayerPtr pPlaye
sscanf( params.c_str(), "%d", &id ); sscanf( params.c_str(), "%d", &id );
uint8_t typeshift = 0x6; uint8_t typeshift = 0x6;
uint8_t mask = 1 << typeshift; uint8_t mask = 1 << typeshift;
id &= mask; id &= mask;
@ -282,6 +279,14 @@ void Core::DebugCommandHandler::set( char * data, Core::Entity::PlayerPtr pPlaye
sscanf( params.c_str(), "%d", &id ); sscanf( params.c_str(), "%d", &id );
pPlayer->sendDebug( std::to_string( pPlayer->actionHasCastTime( id ) ) ); pPlayer->sendDebug( std::to_string( pPlayer->actionHasCastTime( id ) ) );
} }
else if ( subCommand == "cfpenalty" )
{
int32_t minutes;
sscanf( params.c_str(), "%d", &minutes );
pPlayer->setCFPenaltyMinutes( minutes );
}
} }

View file

@ -62,6 +62,11 @@ namespace Core
} }
} }
namespace ContentFinder
{
TYPE_FORWARD( ContentFinder );
}
namespace Scripting namespace Scripting
{ {
typedef std::function< void( Entity::Player&, uint32_t, uint16_t, uint16_t, uint16_t ) > EventReturnCallback; typedef std::function< void( Entity::Player&, uint32_t, uint16_t, uint16_t, uint16_t ) > EventReturnCallback;

View file

@ -28,6 +28,15 @@ void Core::Network::GameConnection::cfDutyInfoRequest( const Packets::GamePacket
Entity::PlayerPtr pPlayer ) Entity::PlayerPtr pPlayer )
{ {
GamePacketNew< FFXIVIpcCFDutyInfo > dutyInfoPacket( pPlayer->getId() ); GamePacketNew< FFXIVIpcCFDutyInfo > dutyInfoPacket( pPlayer->getId() );
auto penaltyMinutes = pPlayer->getCFPenaltyMinutes();
if (penaltyMinutes > 255)
{
// cap it since it's uint8_t in packets
penaltyMinutes = 255;
}
dutyInfoPacket.data().penaltyTime = penaltyMinutes;
queueOutPacket( dutyInfoPacket ); queueOutPacket( dutyInfoPacket );
GamePacketNew< FFXIVIpcCFPlayerInNeed > inNeedsPacket( pPlayer->getId() ); GamePacketNew< FFXIVIpcCFPlayerInNeed > inNeedsPacket( pPlayer->getId() );