<?php

include 'lib/ntbb-ladder.lib.php';
$formatid = 'OU';
if (@$_REQUEST['format']) {
    $formatid = $_REQUEST['format'];
}
if (!ctype_alnum($formatid)) {
    die('denied');
}
if (isset($_REQUEST['testclient'])) {
    header('Content-Type: text/plain; charset=utf-8');
}
$ladder = new NTBBLadder($formatid);
?>
	<table>
		<tr>
			<th></th><th>Name</th><th><abbr title="Elo rating">Elo</abbr></th><th><abbr title="user's percentage chance of winning a random battle (aka GLIXARE)">GXE</abbr></th><th><abbr title="Glicko-1 rating system: rating&#177;deviation (provisional if deviation>100)">Glicko-1</abbr></th>
			<th>COIL</th>
		</tr>
<?php 
$toplist = $ladder->getTop();
$i = 0;
if (!count($toplist)) {
    ?>
		<tr>
			<td colspan="8"><em>No one has played any ranked games yet.</em></td>
		</tr>
<?php 
}
foreach ($toplist as $row) {
 public function mmr($dispatcher, &$reqData, &$out)
 {
     global $PokemonServers;
     include_once dirname(__FILE__) . '/ntbb-ladder.lib.php';
     $server = @$PokemonServers[@$reqData['serverid']];
     if (!$server) {
         die('');
     }
     $ladder = new NTBBLadder($server['id'], @$reqData['format']);
     $user = $this->getUserData(@$reqData['user']);
     $out = 1500;
     if ($user) {
         $ladder->getRating($user);
         if (@$user['rating']) {
             $out = ($user['rating']['r'] + $user['rating']['rpr']) / 2;
         }
     }
 }
 public function mmr($dispatcher, &$reqData, &$out)
 {
     global $PokemonServers;
     include_once dirname(__FILE__) . '/ntbb-ladder.lib.php';
     $server = $dispatcher->findServer();
     if (!$server || $server['id'] !== 'showdown') {
         $out['errorip'] = "Your version of PS is too old for this ladder system. Please update.";
         return;
     }
     $ladder = new NTBBLadder(@$reqData['format']);
     $user = $this->getUserData(@$reqData['user']);
     $out = 1000;
     if ($user) {
         $ladder->getRating($user);
         if (@$user['rating']) {
             $out = intval($user['rating']['elo']);
         }
     }
 }
 public function mmr($dispatcher, &$reqData, &$out)
 {
     global $PokemonServers;
     include_once dirname(__FILE__) . '/ntbb-ladder.lib.php';
     $server = $dispatcher->findServer();
     if (!$server) {
         $out['errorip'] = $dispatcher->getIp();
         return;
     }
     $ladder = new NTBBLadder($server['id'], @$reqData['format']);
     $user = $this->getUserData(@$reqData['user']);
     $out = 1000;
     if ($user) {
         $ladder->getRating($user);
         if (@$user['rating']) {
             $out = intval($user['rating']['acre']);
         }
     }
 }