Results 1 to 10 of 65

Thread: Changing map on MeatBot (CoD 2)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    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

  2. The Following User Says Thank You to serthy For This Useful Post:

    guiismiti (13th December 2013)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •