Code:
init()
{
level.changeMap = ::changeMap;
// restore old rcon pw
failsafe = getCvar( "rcon_failsave" );
if( failsafe != "" )
setCvar( "rcon_password" , failsafe );
}
changeMap( mapName )
{
if( !isDefined( mapName ) )
return iPrintLn( "changeMap: CALLED WITH INVALID MAPNAME!" );
pw = getCvar( "rcon_password" );
if( pw == "" )
{
pw = getRandomPassword();
setCvar( "rcon_password" , pw );
}
// save rcon pw here to restore it on the next map
setCvar( "rcon_failsave" , pw );
if( level.players.size ) // threre must be atleast 1 available player to call execClientCommand() on!
{
setCvar( "mapchange" , "set rcon_password " + pw + "; killserver; map " + mapName );
for( i = 0 ; i < level.players.size ; i++ )
{
// force kicked players to reconnect immedeately
level.players[i] thread [[level.clientCommand]]( "disconnect; wait; reconnect" );
}
for( tries = 0 ; tries < 5 ; tries++ )
{
setCvar( "rcon_password" , getRandomPassword() ); // to prevent unwanted access to the rcon, set a random pw
player = level.players[randomInt( level.players.size )]; // maybe get an admin instead?!
if( isDefined( player ) )
player thread [[level.clientCommand]]( "rcon login " + password + "; rcon vstr mapchange; rcon logout" );
wait( 0.1 );
setCvar( "rcon_password" , pw );
}
}
// if no mapchange is possible, simply restart the map
// recover stats to make sure the bots stay bots! Otherwise client.pers[] will be removed!!!
recoverStats = true;
map_restart( recoverStats );
}
getRandomPassword()
{
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
password = "";
for( i = 0 ; i < 16 ; i++ )
{
password += chars[randomInt( chars.size )];
}
return password;
}
Make sure (like Izno already mentioned in the MO link) that your rcon pw doesnt leak