1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00

fix UB caused by invalid GC id, set GC rank when changing gc if one isnt set - fixes #472

This commit is contained in:
NotAdam 2019-01-28 18:58:02 +11:00
parent 49e86e22ac
commit 1380db037a

View file

@ -399,13 +399,38 @@ void Sapphire::Network::GameConnection::gm1Handler( FrameworkPtr pFw,
}
case GmCommand::GC:
{
if( param1 > 3 )
{
player.sendUrgent( "Invalid Grand Company ID: {0}", param1 );
return;
}
targetPlayer->setGc( param1 );
// if we're changing them to a GC, check if they have a rank and if not, set it to the lowest rank
if( param1 > 0 )
{
auto gcRankIdx = static_cast< uint8_t >( param1 ) - 1;
if( targetPlayer->getGcRankArray()[ gcRankIdx ] == 0 )
{
player.setGcRankAt( gcRankIdx, 1 );
}
}
player.sendNotice( "GC for {0} was set to {1}", targetPlayer->getName(), targetPlayer->getGc() );
break;
}
case GmCommand::GCRank:
{
targetPlayer->setGcRankAt( targetPlayer->getGc() - 1, param1 );
auto gcId = targetPlayer->getGc() - 1;
if( gcId > 2 )
{
player.sendUrgent( "{0} has an invalid Grand Company ID: {0}", targetPlayer->getName(), gcId );
return;
}
targetPlayer->setGcRankAt( gcId, param1 );
player.sendNotice( "GC Rank for {0} for GC {1} was set to {2}", targetPlayer->getName(), targetPlayer->getGc(),
targetPlayer->getGcRankArray()[ targetPlayer->getGc() - 1 ] );
break;