mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-27 14:57:44 +00:00
Replay packets by milliseconds
This commit is contained in:
parent
5b5406fd7a
commit
ef954b202d
3 changed files with 27 additions and 4 deletions
|
@ -492,6 +492,12 @@ void Core::DebugCommandHandler::replay( char * data, Entity::Player& player, boo
|
||||||
if( pSession )
|
if( pSession )
|
||||||
pSession->stopReplay();
|
pSession->stopReplay();
|
||||||
}
|
}
|
||||||
|
else if( subCommand == "info" )
|
||||||
|
{
|
||||||
|
auto pSession = g_serverZone.getSession( player.getId() );
|
||||||
|
if( pSession )
|
||||||
|
pSession->sendReplayInfo();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player.sendUrgent( subCommand + " is not a valid replay command." );
|
player.sendUrgent( subCommand + " is not a valid replay command." );
|
||||||
|
|
|
@ -128,7 +128,7 @@ void Core::Session::startReplay( const std::string& path )
|
||||||
{
|
{
|
||||||
// Get the filename of the current element
|
// Get the filename of the current element
|
||||||
auto fileName = it->path().filename().string();
|
auto fileName = it->path().filename().string();
|
||||||
auto unixTime = atoi( fileName.substr( 0, 10 ).c_str() );
|
auto unixTime = std::stoull( fileName.substr( 0, 14 ).c_str() );
|
||||||
|
|
||||||
if( unixTime > 1000000000 )
|
if( unixTime > 1000000000 )
|
||||||
{
|
{
|
||||||
|
@ -142,12 +142,12 @@ void Core::Session::startReplay( const std::string& path )
|
||||||
return std::get< 0 >( left ) < std::get< 0 >( right );
|
return std::get< 0 >( left ) < std::get< 0 >( right );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
int startTime = std::get< 0 >( loadedSets.at( 0 ) );
|
uint64_t startTime = std::get< 0 >( loadedSets.at( 0 ) );
|
||||||
|
|
||||||
for( auto set : loadedSets )
|
for( auto set : loadedSets )
|
||||||
{
|
{
|
||||||
m_replayCache.push_back( std::tuple< uint64_t, std::string >(
|
m_replayCache.push_back( std::tuple< uint64_t, std::string >(
|
||||||
Util::getTimeSeconds() + ( std::get< 0 >( set ) - startTime ), std::get< 1 >( set ) ) );
|
Util::getTimeMs() + ( std::get< 0 >( set ) - startTime ), std::get< 1 >( set ) ) );
|
||||||
|
|
||||||
g_log.info( "Registering " + std::get< 1 >( set ) + " for " + std::to_string( std::get< 0 >( set ) - startTime ) );
|
g_log.info( "Registering " + std::get< 1 >( set ) + " for " + std::to_string( std::get< 0 >( set ) - startTime ) );
|
||||||
}
|
}
|
||||||
|
@ -167,13 +167,29 @@ void Core::Session::processReplay()
|
||||||
int at = 0;
|
int at = 0;
|
||||||
for( const auto& set : m_replayCache )
|
for( const auto& set : m_replayCache )
|
||||||
{
|
{
|
||||||
if( std::get< 0 >( set ) == Util::getTimeSeconds() )
|
if( std::get< 0 >( set ) <= Util::getTimeMs() )
|
||||||
{
|
{
|
||||||
m_pZoneConnection->injectPacket( std::get< 1 >( set ), *getPlayer().get() );
|
m_pZoneConnection->injectPacket( std::get< 1 >( set ), *getPlayer().get() );
|
||||||
m_replayCache.erase( m_replayCache.begin() + at );
|
m_replayCache.erase( m_replayCache.begin() + at );
|
||||||
|
g_log.info( "Sent for " + std::to_string( std::get< 0 >( set ) ) + ", left: " + std::to_string( m_replayCache.size() ) );
|
||||||
}
|
}
|
||||||
at++;
|
at++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( m_replayCache.size() == 0 )
|
||||||
|
m_isReplaying = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::Session::sendReplayInfo()
|
||||||
|
{
|
||||||
|
std::string message = std::to_string( m_replayCache.size() ) + " Sets left in cache, ";
|
||||||
|
|
||||||
|
if( m_isReplaying )
|
||||||
|
message += " is active";
|
||||||
|
else
|
||||||
|
message += " is idle";
|
||||||
|
|
||||||
|
getPlayer()->sendDebug( message );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::Session::update()
|
void Core::Session::update()
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace Core {
|
||||||
void startReplay( const std::string& folderpath );
|
void startReplay( const std::string& folderpath );
|
||||||
void stopReplay();
|
void stopReplay();
|
||||||
void processReplay();
|
void processReplay();
|
||||||
|
void sendReplayInfo();
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue