Ladle config update script for server owners

A place for threads related to tournaments and the like, and things related too.

Moderator: Light

Post Reply
User avatar
Jip
Round Winner
Posts: 397
Joined: Sat Sep 26, 2009 5:32 pm

Ladle config update script for server owners

Post by Jip »

Hi,

I wrote a small script to update your ladle config file. It fetches the wiki page and gives you back the RINCLUDs for the ladle.cfg, authorities.cfg and the server name.
Just change the $config array to your needs and run php path/to/script.php

Code: Select all

<?php

$config = array(
 	'server_name' => 'uNk\'s', 		// The name of your server
 	'config_file' => 'ladle.cfg' 	// The config file we write the settings to.
);

// Leave the rest alone

$handle = @fopen('http://wiki.armagetronad.org/index.php/Ladle/Challenge_Board', 'r');

if( ! $handle )
	die('Could not open wike page.');

$config_section = false;
$config_pre		= false;

$config_file	= NULL;
$auth_file		= NULL;
$server_name	= NULL;

$config_file_pattern = '/RINCLUDE (ladle\/ladle\d+\.cfg).*href="(.+)"/';
$auth_file_pattern	 = '/RINCLUDE (ladle\/ladle\d+_authorities\.cfg).*href="(.+)"/';
$server_name_pattern = '/(SERVER_NAME.+\))/';

while( ! feof($handle) )
{
	$line = trim( fgets($handle) );

	if( preg_match('/id="Server_Configuration"/i', $line) )
		$config_section = true;

	if( $config_section && preg_match('/\<pre\>/i', $line) )
		$config_pre = true;

	if( $config_pre )
	{
		if( preg_match( $config_file_pattern, $line, $matches ) )
			$config_file = 'RINCLUDE '.$matches[1].'('.$matches[2].')';

		if( preg_match( $auth_file_pattern, $line, $matches ) )
			$auth_file = 'RINCLUDE '.$matches[1].'('.$matches[2].')';

		if( preg_match( $server_name_pattern, $line, $matches ) )
			$server_name = preg_replace('/Player 1\'s Server/i', $config['server_name'], $matches[1]);

		if( preg_match( '/\<\/pre\>/i', $line ) )
			break;
	}
}

fclose($handle);

$handle = @fopen($config['config_file'], 'w');

if( ! $handle )
{
	echo "Could not open configuration file ".$config['config_file']." for writing.\n";
	echo "However, you can still copy and paste the following lines:\n\n";
	echo "$config_file\n$auth_file\n$server_name\n";
	die();
}

fwrite($handle, $config_file."\n");
fwrite($handle, $auth_file."\n");
fwrite($handle, $server_name."\n");
fclose($handle);

User avatar
Jip
Round Winner
Posts: 397
Joined: Sat Sep 26, 2009 5:32 pm

Re: Ladle config update script for server owners

Post by Jip »

Fixed a bug where it didn't get the server name when the closing </pre> was in the same line.
Post Reply