This is just a béta now, I'll try to improve it soon with caching etc.
EXAMPLE: http://mania-world.net/tmonline/
this is NO serverplugin, it can be used on any site
RELEASE NOTES:
0.02b:
-Fixed a bug that didn't load all players
0.02:
-Added basic caching
-Added link to join player if player is on a server
0.01:
Well, kinda made the script didn't I

SCRIPT:
config.php:
Code: Select all
<?php
$config['username'] = 'yourusername';//Place your username here
$config['password'] = 'yourpassword';//Place your password here
?>
Code: Select all
<?php
include_once('config.php');//Load the configuration
$url = "http://official.trackmania.com/tmf-playerpage/main.php";
$ch = curl_init();//Initialise CURL
curl_setopt($ch, CURLOPT_URL, $url);//Set the url
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);//Of course, we don't want your script to run forever, so set a timeout
curl_setopt($ch, CURLOPT_POST, true);//We want to request the page by post
curl_setopt($ch, CURLOPT_POSTFIELDS, "login=".$config['username']."&password=".$config['password']."&submitLogin=Connexion");//Post the fields :)
$text = curl_exec($ch);//Execute and get the page
$exploded = explode('<tr><th class="left">Buddy</th><th class="center">Is Online</th><th class="center">Join Buddy</th><th class="right">World Ranking</th><th class="right">Medals</th><th></th></tr><tr class="even inner">',$text);//Explode on the header of the friends table first
$exploded = explode('</td></tr> ',$exploded[1]);//Now at the footer of the friends table
$players = preg_split('/<td class="left" title="([^<]+)">/i',$exploded[0]);//And now a preg split to get the start of every player, WARNING: This also contains all following players, that problem is fixed in the index.php
?>
Code: Select all
<?php
function table() {
include_once('connect.php');
ob_start();
echo '<table>'.chr(10);
echo '<tr><th>Name:</th><th>Online:</th></tr>'.chr(10);
$firstrun = true;//A little bugfix
foreach($players as $player) {
if(!$firstrun) {
$real = explode('</td>',$player);//Ok, get the formatted playername
$total = explode('</td></tr>',$player);//Now get all playerdata
if(strpos($total[0],'online') !== false) {//If player is online
if(strpos($total[0],'tmtp://#join=') !== false) {//Player is in a server
$server = explode('tmtp://#join=',$total[0]);
$server = explode('\'; return false;',$server[1]);
echo '<tr bgcolor="#00ff00"><td>'.$real[0].'</td><td><a href="tmtp://#join='.$server[0].'" title="Join this player">Yes</a></td></tr>';
} else {
echo '<tr bgcolor="#00ff00"><td>'.$real[0].'</td><td>Yes</td></tr>';
}
} else {//Player is offline
echo '<tr bgcolor="#ff0000"><td>'.$real[0].'</td><td>No</td></tr>';
}
echo chr(10);
} else {
$firstrun = false;
}
}
echo '</table>';
$output = ob_get_contents();
$cache = fopen("cache.tm","w");
fputs($cache, $output);
fclose($cache);
}
if(!file_exists("cache.tm")) {//If cache doesn't exist
table();//Always make it :)
} else {
$cachetime = 600;//10 minutes
$wantedtime = filemtime("cache.tm")+$cachetime;
if(time() > $wantedtime) {//If current time is higher than modified time + 10 minutes
table();//Recreate the file
} else {
include("cache.tm");//Just show the cache
}
}
echo chr(10);
echo '<a href="TMOnline 0.02.zip" title="TMOnline 0.02.zip">Download this script</a>';
?>