1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-23 18:17:46 +00:00

Implement CFPenaltyTime

This commit is contained in:
Minho Kang 2017-08-15 21:22:56 +09:00
parent a730ef37aa
commit f3efd6d086
11 changed files with 136 additions and 50 deletions

View file

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

@ -1 +0,0 @@
Subproject commit 23b9c0a154a327b25d700cd6857a4e53bed2e8a1

View file

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

View file

@ -25,9 +25,8 @@ uint64_t Core::Util::getTimeMs()
uint64_t Core::Util::getTimeSeconds()
{
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
auto now = std::chrono::time_point_cast< std::chrono::seconds >( t1 ).time_since_epoch().count();
return now;
std::chrono::seconds epoch = std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::now().time_since_epoch());
return epoch.count();
}
uint64_t Core::Util::getEorzeanTimeStamp()

View file

@ -0,0 +1,12 @@
#ifndef _CONTENTFINDER_H
#define _CONTENTFINDER_H
namespace Core {
class ContentFinder {
private:
};
}
#endif

View file

@ -237,7 +237,6 @@ void Core::GameCommandHandler::set( char * data, Core::Entity::PlayerPtr pPlayer
g_database.execute( query2.c_str() );
}
else if( subCommand == "discovery_reset" )
{
pPlayer->resetDiscovery();
@ -257,6 +256,13 @@ void Core::GameCommandHandler::set( char * data, Core::Entity::PlayerPtr pPlayer
else
pPlayer->setClassJob( static_cast<Core::Common::ClassJob> ( id ) );
}
else if( subCommand == "cfpenalty")
{
uint32_t minutes;
sscanf( params.c_str(), "%d", &minutes );
pPlayer->setPenaltyMinutes( minutes );
}
}

View file

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

View file

@ -86,6 +86,9 @@ Core::Entity::Player::Player() :
memset( m_name, 0, sizeof( m_name ) );
memset( m_stateFlags, 0, sizeof( m_stateFlags ) );
memset( m_searchMessage, 0, sizeof( m_searchMessage ) );
// content finder
m_cfPenaltyUntil = 0;
}
Core::Entity::Player::~Player()
@ -1499,3 +1502,39 @@ void Core::Entity::Player::autoAttack( ActorPtr pTarget )
pTarget->takeDamage(damage);
}
/////////////////////////////
// Content Finder
/////////////////////////////
uint32_t Core::Entity::Player::getPenaltyTimestamp() const
{
return m_cfPenaltyUntil;
}
void Core::Entity::Player::setPenaltyTimestamp( uint32_t timestamp )
{
m_cfPenaltyUntil = timestamp;
setSyncFlag( PlayerSyncFlags::CFPenaltyTime );
}
uint32_t Core::Entity::Player::getPenaltyMinutes() const
{
auto currentTimestamp = Core::Util::getTimeSeconds();
auto endTimestamp = getPenaltyTimestamp();
// check if penalty timestamp already passed current time
if (currentTimestamp > endTimestamp)
{
return 0;
}
auto deltaTime = endTimestamp - currentTimestamp;
return ceil(static_cast< float > (deltaTime) / 60);
}
void Core::Entity::Player::setPenaltyMinutes( uint32_t minutes )
{
auto currentTimestamp = Core::Util::getTimeSeconds();
setPenaltyTimestamp(currentTimestamp + minutes * 60);
}

View file

@ -482,6 +482,14 @@ public:
void setAutoattack( bool mode );
bool isAutoattackOn() const;
// Player Content Finder Handling
//////////////////////////////////////////////////////////////////////////////////////////////////////
uint32_t getPenaltyTimestamp() const;
void setPenaltyTimestamp( uint32_t timestamp );
uint32_t getPenaltyMinutes() const;
void setPenaltyMinutes( uint32_t minutes );
private:
uint32_t m_lastWrite;
uint32_t m_lastPing;
@ -597,6 +605,8 @@ private:
uint8_t m_gc;
uint8_t m_gcRank[3];
// content finder info
uint32_t m_cfPenaltyUntil;
};
}

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...
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.Hp, "
"c.Mp, "
@ -53,7 +54,7 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
"c.Pos_0_1, "
"c.Pos_0_2, "
"c.Pos_0_3, "
"c.FirstLogin, "
"c.FirstLogin, " // 10
"c.Customize, "
"c.ModelMainWeapon, "
"c.ModelSubWeapon, "
@ -63,7 +64,7 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
"cd.BirthMonth, "
"cd.Status, "
"cd.Class, "
"cd.Homepoint, "
"cd.Homepoint, " // 20
"cd.HowTo, "
"c.ContentId, "
"c.Voice, "
@ -73,11 +74,12 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
"cd.Aetheryte, "
"cd.unlocks, "
"cd.Discovery, "
"cd.StartTown, "
"cd.StartTown, " // 30
"cd.TotalPlayTime, "
"c.IsNewAdventurer, "
"cd.GrandCompany, "
"cd.GrandCompanyRank "
"cd.GrandCompanyRank, "
"cd.CFPenaltyUntil "
"FROM charabase AS c "
" INNER JOIN charadetail AS cd "
" 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();
field[34].getBinary( reinterpret_cast< char* >( m_gcRank ), 3 );
m_cfPenaltyUntil = field[35].getUInt32();
m_pCell = nullptr;
if( !loadActiveQuests() || !loadClassData() || !loadSearchInfo() )
@ -388,6 +392,11 @@ void Core::Entity::Player::createUpdateSql()
charaInfoSearchSet.insert( " SearchComment = UNHEX('" + std::string( Util::binaryToHexString( reinterpret_cast< uint8_t* >( m_searchMessage ), sizeof( m_searchMessage ) ) + "')" ) );
}
if( m_updateFlags & PlayerSyncFlags::CFPenaltyTime )
{
charaDetailSet.insert( " CFPenaltyUntil = " + std::to_string( m_cfPenaltyUntil ) );
}
if( !charaInfoSearchSet.empty() )
{
for( auto entry : charaInfoSearchSet )