[PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

This is the place where you can find everything related to the dedicated server, control scripts and community tools.

Moderators: Pit Crew, TM-Patrol

Post Reply
User avatar
xai
happy cruiser
happy cruiser
Posts: 162
Joined: 13 Nov 2008 15:46
Owned TM-games: TMU(F),TMN(F)
Manialink(s): xai

[PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by xai » 14 Jul 2009 11:04

I made a little workaround so you can now show who of your friends are online by using a php script! Ideal for making a clan account with the whole clan in it.

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
?>
connect.php:

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
?>
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>';
?>
You can also download the zip file from the example site
Last edited by xai on 14 Jul 2009 22:51, edited 1 time in total.
Weeeeeeeeeeee

Ouwe
happy cruiser
happy cruiser
Posts: 152
Joined: 07 Sep 2007 15:01
Owned TM-games: TMUF, Canyon
Location: The Netherlands

Re: [PHP] TMOnline 0.02 béta: Show Online Players(Friendlist)

Post by Ouwe » 14 Jul 2009 18:02

Thank you very much, it works good.
Only when I am online it says I am online but there's no link to join me. For others it works.
http://www.oldandcrazy.nl to see it working.

I added colorparser to, to see the special characters of the nicknames.

Edit:
I see some of my buddy's not in the list, why is that?

User avatar
xai
happy cruiser
happy cruiser
Posts: 162
Joined: 13 Nov 2008 15:46
Owned TM-games: TMU(F),TMN(F)
Manialink(s): xai

Re: [PHP] TMOnline 0.02 béta: Show Online Players(Friendlist)

Post by xai » 14 Jul 2009 22:40

Probably a small problem with getting the players, I'll see if I can fix it. What colourparser do you use?
Weeeeeeeeeeee

User avatar
w1lla
TM-Patrol
TM-Patrol
Posts: 1466
Joined: 23 May 2007 07:20
Owned TM-games: TMU, TMN, TMF
Manialink(s): intr
Location: Venray

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by w1lla » 15 Jul 2009 10:18

Code: Select all

tmnforever is nations and united makes it special. tmnforever has united. I need united!

Ouwe
happy cruiser
happy cruiser
Posts: 152
Joined: 07 Sep 2007 15:01
Owned TM-games: TMUF, Canyon
Location: The Netherlands

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by Ouwe » 15 Jul 2009 14:43

Thanks for the update, it works perfect now. Thank you very much :thumbsup:
Yes I used that.

User avatar
Shaigan
happy cruiser
happy cruiser
Posts: 118
Joined: 06 May 2008 10:56
Owned TM-games: TMN, TMU, TMUF
Manialink(s): :shaigan
Location: Tarbes, FR
Contact:

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by Shaigan » 15 Jul 2009 16:37

Problem for the coloring process... The color parser add some &nbsp; characters inside the <span style=... and it become <span&nbsp;style=...

How did you solve this problem ?

Ouwe
happy cruiser
happy cruiser
Posts: 152
Joined: 07 Sep 2007 15:01
Owned TM-games: TMUF, Canyon
Location: The Netherlands

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by Ouwe » 15 Jul 2009 20:23

I added this at the en of the index.php from the colorparser wich I downloaded from above.
So after this in the index

Code: Select all

	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);
?>
I copieed this:

Code: Select all

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="background:#000000; font-family:Arial, sans-serif">
<?php

require_once('./classes/tmfcolorparser.inc.php');
$cp= new TMFColorParser();
?>
</body>
</html>
I added the folders "classes" en "fonts" in the same dir.

User avatar
Shaigan
happy cruiser
happy cruiser
Posts: 118
Joined: 06 May 2008 10:56
Owned TM-games: TMN, TMU, TMUF
Manialink(s): :shaigan
Location: Tarbes, FR
Contact:

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by Shaigan » 15 Jul 2009 20:37

OK thx

But, logically, this is a non sense... The code you added just change the charset and doesn't do anything else. You initiate the class but you don't do anything with it (like changing the real[0] variable, which contains the player name in a row)

I think if we just make the index.php with an UTF-8 .htaccess, it will works without the class from f**kfish.

User avatar
SmashingDeluXe
sunday driver
sunday driver
Posts: 58
Joined: 04 Dec 2007 20:38
Owned TM-games: All
Manialink(s): NO
Location: Germany
Contact:

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by SmashingDeluXe » 16 Jul 2009 06:27

Really nice!

I'll try it ou - the next time.
cool idea
Intel Core Duo Quad Q6600 4x 2.4 Ghz / Gainward NVidia GeForce 8800 GT 1024MB / 4GigRAM DDR2 1066Mhz
Gigabyte P35-DS3P / Win7 Ultimate

JOIN OUR SERVER!
Tech&Mini.ne
http://www.tm-creative.org

Ouwe
happy cruiser
happy cruiser
Posts: 152
Joined: 07 Sep 2007 15:01
Owned TM-games: TMUF, Canyon
Location: The Netherlands

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by Ouwe » 16 Jul 2009 14:21

Shaigan wrote:OK thx

But, logically, this is a non sense... The code you added just change the charset and doesn't do anything else. You initiate the class but you don't do anything with it (like changing the real[0] variable, which contains the player name in a row)

I think if we just make the index.php with an UTF-8 .htaccess, it will works without the class from f**kfish.
I am a noob in php, I just know a little.
I just try things to make it work for me. You ask me how I did it and I answered you. I know it's not in the right way.
But on my page it works how I want it to work so I am happy.

turbo_paule
wheelbarrow operator
wheelbarrow operator
Posts: 24
Joined: 11 May 2008 05:56
Owned TM-games: TMU

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by turbo_paule » 16 Jul 2009 18:02

i get this error!
Fatal error: Call to undefined function curl_init() in /var/www/online/connect.php on line 5
why?

User avatar
xai
happy cruiser
happy cruiser
Posts: 162
Joined: 13 Nov 2008 15:46
Owned TM-games: TMU(F),TMN(F)
Manialink(s): xai

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by xai » 16 Jul 2009 21:30

turbo_paule wrote:i get this error!
Fatal error: Call to undefined function curl_init() in /var/www/online/connect.php on line 5
why?
Curl probably isn't enabled on your server
Weeeeeeeeeeee

Erwin
wheelbarrow operator
wheelbarrow operator
Posts: 23
Joined: 06 Apr 2008 21:01
Owned TM-games: TMN, TMU, TMF
Contact:

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by Erwin » 31 Oct 2009 22:07

How i must change the script that the playernames are the link instead of "YES" :?:

User avatar
AR | MadMax
wheelbarrow operator
wheelbarrow operator
Posts: 23
Joined: 20 Sep 2009 03:04
Owned TM-games: TMUF/TMNF
Location: Texas,USA
Contact:

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by AR | MadMax » 31 Oct 2009 23:14

i have a quick question. what do i type into my website for the html code. i have all 3 of these in my web folder but when i bring up my website all i see is that script. so i have to move it to a different folder. other than that i like your script, nice feature to have. :thumbsup:
Image
Image
Image
λμяैσяα»WarZone..0K-50K
λμяैσяα»ςρєєď..50K-80K
λμяैσяα»τєҫҥ-мΐηΐ..40K-80K

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: [PHP] TMOnline 0.02b béta: Show Online Players(Friendlist)

Post by nocturne » 01 Nov 2009 03:29

Is it possible to use the community code instead of account password..?

Post Reply