<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
 *	Name: plugin.geryrec.php
 *	Created: 6th November 2009 (06/11/2009)
 *	Original Author: gery (http://trackmania.gery.perso.neuf.fr/)
 *	Original Design: Originally designed for TMGery
 *	Current Version: 3.1
 *	REQUIREMENTS: Requires TMGery Plugin Manager 0.22 by DedDerek
 *		http://www.tm-forum.com/viewtopic.php?t=18546
  ***********************************************************************
 * Release 1.0:
 * - Feature: creates a centralized record database on a distant http server and 
		displays on the right 2 top5 with local and global records
		when you clik on them you have more details and records
		adds a command /GeryRec ON or OFF to activate or deactivate it
		
 * Release 2.0: 26th November 2009 (26/11/2009)
 * - Feature: displays global records only if they are differents to local records
		adds the last record of each top at bottom if no record for the player
		when race ends, if no global records, TMGery displays his local Top20
		
 * Release 3.1: 1st December 2009 (01/12/2009)
 * - Feature: fix : displays only local records when they are same in global and local
		now works in round and cup mods with records to the left side
		doesn't display anything during warmup

* - installation: nothing to configure, just add it in plugins directory and in plugins.txt
* * * * * * * * * * * * * * * * * * * * * * *  * * * * * * * * * * * * * * * * * * * * * * */

define('REQUEST_AUTHENTICATE', 'VG1HZXJ5UmVjIHYyMDA5LTEwLTMwIGh0dHA6Ly90cmFja21hbmlhLmdlcnkucGVyc28ubmV1Zi5mcg==');
define('REMOTE_CALL_URL', 'http://sd-15945.dedibox.fr/TMGery_remote.php');

function sendRequest($url, $auth, $serviceName, $arguments = array())
{
   $data = http_build_query($arguments);
   
   $opts = array (
      'http'=>array (
         'method' => 'POST',
         'header' => "x-auth: $auth\r\n" .
                     "x-service-name: $serviceName\r\n" .
                     "Content-type: application/x-www-form-urlencoded\r\n" .
                     "Content-Length: " . strlen($data) . "\r\n",
         'content' => $data
       )
   );

   $context = stream_context_create($opts);

   $content = @file_get_contents($url, false, $context);
   if (false === $content) {
		throw new Exception('Problème d\'accès au serveur distant');
   } else {
      $result = unserialize($content);
      if (false === $result) {
			throw new Exception('Problème de délinéarisation du résultat');
      } elseif (! is_array($result) or
            !(
               array_key_exists('exception', $result) or
               array_key_exists('return', $result)
               )) {
 			throw new Exception('Résultat retourné non conforme');
     }
   }

   if (! empty($result['exception'])) {
		throw new Exception($result['exception']);
   } else {
      return $result['return'];
   }
}

class geryrec{

	private $on = 1;       // 0=off 1=on
	private $ServerLogin = 'x';
	private $start_geryrec = 0;
	private $Top = array();//array('login'=>'','nick'=>'','score'=>0)
	private $force = false;
	private $nick = ' ';
	private $gerymania;
	
	function geryrec_playerfinish($Player){ 
	//int PlayerUid, string Login, int TimeOrScore
	
	global $CurrentChallenge;
	global $CurrentGameMode;
	global $Server_Status;
	global $PlayerList;
	global $NbLaps;
	
		if (!$this->on) return;
		if ($Player[0] == 0) return;
		if ($Player[2] <= 0) return;
		if (($Server_Status['Name']!=='Running - Play') && !$this->force)	return;

		if (!$this->force) {
			$nick = purgelogin($Player[1]);
			foreach ($PlayerList as $player) {
				if ($Player[1]==$player['Login']) {
					$nick=$player['NickName'];
					break;
				}
			}
		} else $nick = $this->nick;
		
		if ($CurrentGameMode==4) {
			$found = false;
			$send = false;
			for ($i=0;$i<20;$i++) {
				$topplayer = $this->Top[0][$i];
				if (purgelogin($Player[1]) == $topplayer['login']) $found = true;
				if ($Player[2] > $topplayer['score']) $send = true;
				if ($found) break;
			}
		}
		else {
			$found = false;
			$send = false;
			for ($i=0;$i<20;$i++) {
				$topplayer = $this->Top[0][$i];
				if (purgelogin($Player[1]) == $topplayer['login']) $found = true;
				if (($Player[2] < $topplayer['score']) || ($topplayer['score']==0)) $send = true;
				if ($found) break;
			}
		}
		
		$uid = $CurrentChallenge['UId'];
		if ($NbLaps > 1) $uid .= ".".$NbLaps;

		if ($send) {
			try {
				$param = array('uid'=>$uid,'login'=>purgelogin($Player[1]),'nick'=>$nick,'score'=>intval($Player[2]),'server'=>$this->ServerLogin,'gamemode'=>intval($CurrentGameMode));
				$result = sendRequest(REMOTE_CALL_URL, REQUEST_AUTHENTICATE, 'playerfinish',$param);
			} catch(Exception $e) {
				error_log('playerfinish error : ' . $e->getMessage());
			}
		}
	}

	function getuid() {
		global $CurrentChallenge;
		global $NbLaps;
		global $TopLogin;
		global $TopBestTime;
		
		$uid = $CurrentChallenge['UId'];
		if ($NbLaps > 1) $uid .= ".".$NbLaps;

		try {
			$param = array('uid'=>$uid);
			$result = sendRequest(REMOTE_CALL_URL, REQUEST_AUTHENTICATE, 'gettop',$param);
		} catch(Exception $e) {
			error_log('gettop error : ' . $e->getMessage());
			$result[0] = false;
		}
		if ($result[0] !== false) $this->Top = $result;
		
		$found = false;	//init pas de difference
		foreach ($this->Top[0] as $Player) {
			if (intval($Player['score']) <= 0) break;
			$loginfound = false;	//init login pas trouve
			for ($i=0;$i<count($this->Top[0]);$i++) {
				if (purgelogin($TopLogin[$i]) == $Player['login']) {
					$loginfound = true;	
					if (intval($TopBestTime[$i]) != intval($Player['score'])) {$found = true; break;}
				}
			}
			if (!$loginfound || $found) {$found = true; break;}
		}
		$this->gerymania = $found;
	}
	
	function AfficheTop($PlayerLogin, $text, $text2) {
	//$text=top gery $text2=top local
	global $sunrise;
	global $PlayerScript;
	global $WarmUp;
	global $OWarmUp;
	global $CurrentGameMode;
	
		if (($sunrise != 0) && ($sunrise != 2)) return;
	
		if (($PlayerScript[$PlayerLogin] == '1') && !$WarmUp && !$OWarmUp) {
			if ($this->gerymania) {
				if (($CurrentGameMode!=0) && ($CurrentGameMode!=5)) {
					//fenetre  avec les TOP5 Gerymania + Local
					$xml = "<?xml version='1.0' encoding='utf-8' ?> 
								<manialink id='GeryRec'>
								<timeout>0</timeout>
								<type>default</type>
								<frame posn='48 8.5 0'>
								<quad  sizen='4 4'  posn='2 -1 0' halign='center'  valign='center'   style='Icons128x32_1' substyle='RT_Cup' />
								<label sizen='11.0 3'  posn='5 0 0' halign='left' style='TextStaticSmall'>$0f0Gery-mania</label>
								<quad  sizen='17 20'  posn='-1 1 0' halign='top'  valign='left'   style='Bgs1InRace' substyle='NavButton' action='90'/>
								<label sizen='7.6 20'  posn='0 -3 0' halign='left' style='TextStaticSmall'><![CDATA[".$text."\n\r ]]></label>
								</frame>
								</manialink>
								<manialink id='Top'>
								<timeout>0</timeout>
								<type>default</type>
								<frame posn='48 -12.5 0'>
								<quad  sizen='4 4'  posn='2 -1 0' halign='center'  valign='center'   style='Icons64x64_1' substyle='OfficialRace' />
								<label sizen='11.0 3'  posn='4 0 0' halign='left' style='TextStaticSmall'>$0f0Local Records</label>
								<quad  sizen='17 20'  posn='-1 1 0' halign='top'  valign='left'   style='Bgs1InRace' substyle='NavButton' action='64'/>
								<label sizen='7.6 20'  posn='0 -3 0' halign='left' style='TextStaticSmall'><![CDATA[".$text2."\n\r ]]></label>
								</frame>
								</manialink>";
				}
				else {
					//fenetre  avec les TOP5 Gerymania + Local
					$xml = "<?xml version='1.0' encoding='utf-8' ?> 
								<manialink id='GeryRec'>
								<timeout>0</timeout>
								<type>default</type>
								<frame posn='-63.5 14 0'>
								<quad  sizen='4 4'  posn='2 -1 0' halign='center'  valign='center'   style='Icons128x32_1' substyle='RT_Cup' />
								<label sizen='11.0 3'  posn='5 0 0' halign='left' style='TextStaticSmall'>$0f0Gery-mania</label>
								<quad  sizen='17 20'  posn='-1 1 0' halign='top'  valign='left'   style='Bgs1InRace' substyle='NavButton' action='90'/>
								<label sizen='7.6 20'  posn='0 -3 0' halign='left' style='TextStaticSmall'><![CDATA[".$text."\n\r ]]></label>
								</frame>
								</manialink>
								<manialink id='Top'>
								<timeout>0</timeout>
								<type>default</type>
								<frame posn='-63.5 -6 0'>
								<quad  sizen='4 4'  posn='2 -1 0' halign='center'  valign='center'   style='Icons64x64_1' substyle='OfficialRace' />
								<label sizen='11.0 3'  posn='4 0 0' halign='left' style='TextStaticSmall'>$0f0Local Records</label>
								<quad  sizen='17 20'  posn='-1 1 0' halign='top'  valign='left'   style='Bgs1InRace' substyle='NavButton' action='64'/>
								<label sizen='7.6 20'  posn='0 -3 0' halign='left' style='TextStaticSmall'><![CDATA[".$text2."\n\r ]]></label>
								</frame>
								</manialink>";
				}
			} else {
				if (($CurrentGameMode!=0) && ($CurrentGameMode!=5)) {
					//fenetre  avec le TOP10  Local
					$xml = "<?xml version='1.0' encoding='utf-8' ?> 
								<manialink id='GeryRec'></manialink>
								<manialink id='Top'>
								<timeout>0</timeout>
								<type>default</type>
								<frame posn='48 4.5 0'>
								<quad  sizen='4 4'  posn='2 -1 0' halign='center'  valign='center'   style='Icons64x64_1' substyle='OfficialRace' />
								<label sizen='11.0 3'  posn='4 0 0' halign='left' style='TextStaticSmall'>$0f0Local Records</label>
								<quad  sizen='17 32.5'  posn='-1 1 0' halign='top'  valign='left'   style='Bgs1InRace' substyle='NavButton' action='64'/>
								<label sizen='7.6 20'  posn='0 -3 0' halign='left' style='TextStaticSmall'><![CDATA[".$text2."\n\r ]]></label>
								</frame>
								</manialink>";
				}
				else {
					//fenetre  avec le TOP10  Local
					$xml = "<?xml version='1.0' encoding='utf-8' ?> 
								<manialink id='GeryRec'></manialink>
								<manialink id='Top'>
								<timeout>0</timeout>
								<type>default</type>
								<frame posn='-63.5 6 0'>
								<quad  sizen='4 4'  posn='2 -1 0' halign='center'  valign='center'   style='Icons64x64_1' substyle='OfficialRace' />
								<label sizen='11.0 3'  posn='4 0 0' halign='left' style='TextStaticSmall'>$0f0Local Records</label>
								<quad  sizen='17 32.5'  posn='-1 1 0' halign='top'  valign='left'   style='Bgs1InRace' substyle='NavButton' action='64'/>
								<label sizen='7.6 20'  posn='0 -3 0' halign='left' style='TextStaticSmall'><![CDATA[".$text2."\n\r ]]></label>
								</frame>
								</manialink>";
				}
			}
		}
		else {
			$xml = "<?xml version='1.0' encoding='utf-8'?>
				<manialink id='GeryRec'></manialink>
				<manialink id='Top'></manialink>";
		}
		
		addCall("SendDisplayManialinkPageToLogin", $PlayerLogin, $xml, 0, false);

	}
	
	function Affiche_tops() {
	global $sunrise;
	global $PlayerList;
	global $colors;
	global $CurrentGameMode;
	global $TopLogin;
	global $TopBestTime;
	global $TopNickName;
	global $maxtop;

		if (($sunrise != 0) && ($sunrise != 2)) return;

		if ($CurrentGameMode == 2) return;	// rien si team 

		$text="";
		if ($this->gerymania) {
			$nbrec = 5;
			$rank = 1;
			for ($i=0;$i<$nbrec;$i++) {
				$player = $this->Top[0][$i];
				$login = $player['login'];
				$nick = $player['nick'];
				$score = MwTimeToString($player['score']);
				if (intval($player['score']) <= 0) break;
				$text .= '$z' . $colors['interact'] . $rank . '. ' . $colors['highlight'] . $score . ' $z';
				if (strlen(stripColors($nick, 1)) > 8) $text .= '$n';
				$text .= purgeNick($nick) . '$z' . "\n\r" ;
				$rank++;
			}
		} else $nbrec = 10;
		
		$text2="";
		$rank = 1;
		for ($i=0;$i<$nbrec;$i++) {
			$login = $TopLogin[$i];
			$nick = $TopNickName[$i];
			$score = MwTimeToString($TopBestTime[$i]);
			if (intval($TopBestTime[$i]) <= 0) break;
			$text2 .= '$z' . $colors['interact'] . $rank . '. ' . $colors['highlight'] . $score . ' $z';
			if (strlen(stripColors($nick, 1)) > 8) $text2 .= '$n';
			$text2 .= purgeNick($nick) . '$z' . "\n\r" ;
			$rank++;
		}
		
		foreach ($PlayerList as $Player) {
			$i=1;
			$found = false;
			foreach ($TopLogin as $login) {
				if ($login == $Player['Login']) {$found = true; break;}
				$i++;
			}
			$text22="";
			if (($i>$nbrec) && $found) {
				$text22 = '$z' . $colors['interact'] . $i . '. ' . $colors['highlight'] . MwTimeToString($TopBestTime[$i-1]) . ' $z';
				if (strlen(stripColors($TopNickName[$i-1], 1)) > 8) $text22 .= '$n';
				$text22 .= purgeNick($TopNickName[$i-1]) . '$z' . "\n\r" ;
			} elseif (!$found && (intval($TopBestTime[$maxtop-1]) > 0)) {
				$text22 = '$z' . $colors['interact'] . $maxtop . '. ' . $colors['highlight'] . MwTimeToString($TopBestTime[$maxtop-1]) . ' $z';
				if (strlen(stripColors($TopNickName[$maxtop-1], 1)) > 8) $text22 .= '$n';
				$text22 .= purgeNick($TopNickName[$maxtop-1]) . '$z' . "\n\r" ;
			}
			$text1="";
			if ($this->gerymania) {
				$i=1;
				$found = false;
				foreach ($this->Top[0] as $Player2) {
					if ($Player['Login'] == $Player2['login']) {$found = true; break;}
					$i++;
				}
				if (($i>$nbrec) && $found) {
					$text1 = '$z' . $colors['interact'] . $i . '. ' . $colors['highlight'] . MwTimeToString($Player2['score']) . ' $z';
					if (strlen(stripColors($Player2['nick'], 1)) > 8) $text1 .= '$n';
					$text1 .= purgeNick($Player2['nick']) . '$z' . "\n\r" ;
				} elseif (!$found && (intval($Player2['score']) > 0)) {
					$text1 = '$z' . $colors['interact'] . ($i-1) . '. ' . $colors['highlight'] . MwTimeToString($Player2['score']) . ' $z';
					if (strlen(stripColors($Player2['nick'], 1)) > 8) $text1 .= '$n';
					$text1 .= purgeNick($Player2['nick']) . '$z' . "\n\r" ;
				}
			}
			$this->AfficheTop($Player['Login'], $text.$text1, $text2.$text22);
		}
		multiquery();
	}

	function geryrec_gettop() {
		global $ServerStop;
		global $Server_Status;
		global $PlayerList;
		
		if (!$this->on) return;

		if (!$ServerStop) {
			$end_time = time();
			if ( ($end_time-$this->start_geryrec) >= 20) {
				$this->start_geryrec=$end_time;
				if ($Server_Status['Name']=='Running - Play') {

					$this->getuid();
					$this->Affiche_tops();
				}
			}
		}
	}
	
	function geryrec_beginrace() {
	global $TopLogin;
	global $TopBestTime;
	global $TopNickName;
	
		if (!$this->on) return;

		$this->getuid();
		
		$this->force = true;
		for ($i=0;$i<20;$i++) if ($TopBestTime[$i] > 0)	{
			$this->nick = $TopNickName[$i];
			$this->geryrec_playerfinish(array(255,$TopLogin[$i],$TopBestTime[$i]));
		}
		$this->force = false;
		
	}
	
	function geryrec_endRace($Datas) {
	global $CurrentGameInfo;
	global $PlayerList;
	global $PlayerLanguage;
	global $PlayerScript;
	global $colors;
	global $CurrentGameMode;
	global $TopLogin;
	global $TopBestTime;
	global $TopNickName;
	global $WarmUp;
	global $OWarmUp;
	global $client;

		if (!$this->on) return;

		if ($CurrentGameMode == 2) return;	// rien si team 
		if ($CurrentGameMode == 5) {
			if(!@$client->query("GetStatus")){
				echo "\n\rerreur de connexion a ".$ip.":".$port."\n\r";
				Error($client->getErrorMessage(), $client->getErrorCode());
				die(2);
			}
			$Server_Status = $client->getResponse();
			if ($Server_Status['Name'] =='Running - Play') return; //rien si cup et mode play
		}
	
		$this->getuid();
					
		if (!$this->gerymania) return;

		$text="";
		$rank = 1;
		for ($i=0;$i<8;$i++) {
			$player = $this->Top[0][$i];
			$login = $player['login'];
			$nick = $player['nick'];
			$score = MwTimeToString($player['score']);
			if (intval($player['score']) <= 0) break;
			$text .= '$z' . $colors['interact'] . $rank . '. ' . $colors['highlight'] . $score . ' $z' . purgeNick($nick) . '$z' . "\n\r" ;
			$rank++;
		}
		
		$text2="";
		$rank = 1;
		for ($i=0;$i<8;$i++) {
			$login = $TopLogin[$i];
			$nick = $TopNickName[$i];
			$score = MwTimeToString($TopBestTime[$i]);
			if (intval($TopBestTime[$i]) <= 0) break;
			$text2 .= '$z' . $colors['interact'] . $rank . '. ' . $colors['highlight'] . $score . ' $z' . purgeNick($nick) . '$z' . "\n\r" ;
			$rank++;
		}

		//fenetres  avec le classement Gerymania et local records
	
		if ($CurrentGameInfo['ChatTime']>0) {
			foreach ($PlayerList as $Player) {
				if (($PlayerScript[$Player['Login']] == '1') && !$WarmUp && !$OWarmUp) {
		
					$i=1;
					$found = false;
					foreach ($TopLogin as $login) {
						if ($login == $Player['Login']) {$found = true; break;}
						$i++;
					}
					$text22="";
					if (($i>8) && $found) {
						$text22 = '$z' . $colors['interact'] . $i . '. ' . $colors['highlight'] . MwTimeToString($TopBestTime[$i-1]) . ' $z' . purgeNick($TopNickName[$i-1]) . '$z' . "\n\r" ;
					}
					$i=1;
					$found = false;
					foreach ($this->Top[0] as $Player2) {
						if ($Player['Login'] == $Player2['login']) {$found = true; break;}
						$i++;
					}
					$text1="";
					if (($i>8) && $found) {
						$text1 = '$z' . $colors['interact'] . $i . '. ' . $colors['highlight'] . MwTimeToString($Player2['score']) . ' $z' . purgeNick($Player2['nick']) . '$z' . "\n\r" ;
					}

					$xml = "<?xml version='1.0' encoding='utf-8' ?> 
							<manialink id='GeryRec'>
							<timeout>0</timeout>
							<type>default</type>
							<frame posn='41 16 0'>
							<quad  sizen='4 4'  posn='2 -1 0' halign='center'  valign='center'   style='Icons128x32_1' substyle='RT_Cup' />
							<label sizen='11.0 3'  posn='8 0 0' halign='left' style='TextStaticSmall'>$0f0Gery-mania</label>
							<quad  sizen='24 27.5'  posn='-1 1 0' halign='top'  valign='left'   style='Bgs1InRace' substyle='NavButton' />
							<label sizen='11 20'  posn='0 -3 0' halign='left' style='TextStaticSmall'><![CDATA[".$text.$text1."\n\r ]]></label>
							</frame>
							</manialink>
							<manialink id='Top'>
							<timeout>0</timeout>
							<type>default</type>
							<frame posn='41 -13 0'>
							<quad  sizen='4 4'  posn='2 -1 0' halign='center'  valign='center'   style='Icons64x64_1' substyle='OfficialRace' />
							<label sizen='11.0 3'  posn='8 0 0' halign='left' style='TextStaticSmall'>$0f0Local Records</label>
							<quad  sizen='24 27.5'  posn='-1 1 0' halign='top'  valign='left'   style='Bgs1InRace' substyle='NavButton' />
							<label sizen='11 20'  posn='0 -3 0' halign='left' style='TextStaticSmall'><![CDATA[".$text2.$text22."\n\r ]]></label>
							</frame>
							</manialink>";
	
					addCall("SendDisplayManialinkPageToLogin", $Player['Login'], $xml, $CurrentGameInfo['ChatTime']+3000, false);
				}
			}
			multiquery();
		}
	}

	function geryrec_mania($Player) {
	//int PlayerUid, string Login, int Answer
	
	global $colors;
	global $sunrise;
	global $client;
	
		$PlayerAnswer=$Player[2];

		if ($PlayerAnswer != 90)  return;	//click sur 90 uniquement
	
		$text='  $0f0Gery-mania Records'."\n\r\n\r";
		$rank = 1;
		for ($i=0;$i<20;$i++) {
			$player = $this->Top[0][$i];
			$login = $player['login'];
			$nick = $player['nick'];
			$score = MwTimeToString($player['score']);
			if (intval($player['score']) <= 0) break;
			$text .= '$z' . $colors['interact'] . $rank . '. ' . $colors['highlight'] . $score . ' $z' . purgeNick($nick) . '$z' . $colors['interact'] . ' ( ' . $login . ' )'. '$z' . "\n\r" ;
			$rank++;
		}

		$login=$Player[1];

		if (($sunrise==0) || ($sunrise==2)) {
			$xml = "<?xml version='1.0' encoding='utf-8' ?> 
					<manialink id='List'>
					<timeout>0</timeout>
					<type>default</type>
					<frame posn='-40 43 0'>
					<quad  sizen='82 78'  posn='-1 1 0' halign='top'  valign='left'   style='Bgs1InRace' substyle='BgWindow3' />
					<label sizen='80 3'  posn='0 0 0' halign='left' style='TextStaticSmall'><![CDATA[".$text."]]></label>
					<label sizen='60 3'  posn='40 -75 0' halign='center' valign='center' style='TextValueSmall' action='99' >OK</label>
					</frame>
					</manialink>";

			if (!$client->query("SendDisplayManialinkPageToLogin", $login, $xml, 0, true)) {
				Error($client->getErrorMessage(), $client->getErrorCode());
			}	
		}
		else ChatSendServerMessageToLogin($text, $login);

	}

	function geryrec_chatcommand1($command,$playerlogin){ // show current state or set ON/OFF 
	global $PlayerLanguage;
	global $txtl;
	global $st;
	global $colors;
	global $client;
	
		$login = $playerlogin[0];
		if (isadmin($login) || isadmin2($login)) {
			if (isset($command[0])) {
				if ($command[0]=="ON") $this->on=1;
				if ($command[0]=="OFF") $this->on=0;
			}
			if ($this->on==1) { 
				ChatSendServerMessageToLogin('$fffGeryRec$0f0 ON',$login); 
			}
			else {
				ChatSendServerMessageToLogin('$fffGeryRec$0f0 OFF',$login);
				$xml = "<?xml version='1.0' encoding='utf-8' ?> 
						<manialink id='GeryRec'></manialink>
						<manialink id='Top'></manialink>";
	
				if (!$client->query("SendDisplayManialinkPage", $xml, 0, true)) {
					Error($client->getErrorMessage(), $client->getErrorCode());
				}
			}
		}
		else {
			$msg = $st . $colors['error'] . $txtl['_'.$PlayerLanguage[$login]]['seulement pour admin']; 
			SendMsgToLogin ($msg, $login);					
		}
	}  

	function geryrec_init() {
	global $client;
		if (!$client->query('GetSystemInfo')) {
			Error($client->getErrorMessage(), $client->getErrorCode());
		}
		else {
			$info = $client->getResponse();
			$this->ServerLogin = $info['ServerLogin'];
		}
	}
}
  
$this->AddPlugin(new geryrec());
$this->AddEvent('onStartup', 'geryrec_init');
$this->AddEvent('PlayerFinish', 'geryrec_playerfinish');  
$this->AddEvent('onMainLoop', 'geryrec_gettop'); 
$this->AddEvent('BeginRace', 'geryrec_beginrace');  
$this->AddEvent('EndRace', 'geryrec_endRace');  
$this->AddEvent('PlayerManialinkPageAnswer', 'geryrec_mania');  
$this->addChatCommand('GeryRec', true, 'geryrec_chatcommand1');

?>
