Advertisement
wKtK

jazzjackrabbit.net GIP - wKtK version

Jul 15th, 2012
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.73 KB | None | 0 0
  1. function gipke () {
  2.    
  3.     /*
  4.      * Multiple lists:
  5.      * this array declared below here contains the urls of the
  6.      * listservers the script will check. It will query them in
  7.      * the order they are listed here, and will choose the first
  8.      * one it can connect succesfully to.
  9.      *
  10.      * To keep this efficient, each connection attempt gets a
  11.      * maximal timeout of 1 second.
  12.      *
  13.      * The one who mantains the site should add new servers and remove
  14.      * obsolete ones. Also, reorder them to make sure the servers
  15.      * that are online the most are first in the list.
  16.      *
  17.      * Worst case: 1 second per url here spent loading(!), so keep
  18.      * the list small and tidy!
  19.      *
  20.      */
  21.        
  22.     $servers = array(
  23.         'list1.digiex.net',
  24.         'list2.digiex.net'
  25.     );
  26.        
  27.        
  28.        
  29.     //Write start of table
  30.     $r = "\n".'<table border="0" align="center">'."\n".'';
  31.  
  32.     //Initialize the connection variable.
  33.     $connection = false;
  34.     foreach($servers as $server)
  35.     {      
  36.    
  37.         $connection = fsockopen($server, 10057, $errno, $errstr,1);
  38.         if (!$connection)
  39.         {
  40.             continue; //failed, on to the next value
  41.         } else {
  42.             break; //succeeded, proceed with this connection.
  43.         }
  44.     }
  45.        
  46.     if (!$connection)
  47.     {
  48.         //Not a single listserver responded, return false.
  49.         return false;
  50.     }
  51.        
  52.     $list = ''; //Received data accumulated here
  53.     while (!feof($connection)) $list .= fread($connection, 8192); //Read raw data
  54.     fclose($connection);
  55.        
  56.     //tidy up version names
  57.     $list = nl2br($list);      
  58.     $list = str_replace("   ", " ", $list);
  59.     $list = str_replace("1.25 c", "1.25c", $list);
  60.     $list = str_replace("1.25 d", "1.25d", $list);
  61.     $list = str_replace("1.24 x", "1.24x", $list);
  62.     $list = str_replace("1.24 s", "1.24s", $list);
  63.     $list = str_replace("1.21 s", "1.21s", $list);
  64.     $list = str_replace("1.20 s", "1.20s", $list);
  65.     $list = str_replace("1.21", "1.23", $list);
  66.        
  67.  
  68.  
  69.     $list = explode("\n", $list);
  70.        
  71.     /*
  72.      * Listservers always add an unneeded newline after the last line,
  73.      * because of the jj2 devs being lazy. because this script separates
  74.      * servers using newlines, 1 is subtracted from the count to ignore
  75.      * the last, empty line.
  76.      */
  77.     $number = count($list) - 1;
  78.     //Iterate over the servers to format them into a html table:
  79.     for ($counter=0; $counter<$number; $counter++)
  80.     {
  81.         $server = explode(" ",$list[$counter],8);
  82.                
  83.         /*
  84.          *Fix ampersands and '<','>' and remove formatting chars '|' and '§'.
  85.          */
  86.         $server[7] = str_replace("&","&amp;",$server[7]);
  87.         $server[7] = str_replace("<","&lt;",$server[7]);
  88.         $server[7] = str_replace(">","&gt;",$server[7]);
  89.         $server[7] = str_replace("|","",$server[7]);
  90.         /*
  91.          * '§' needs some extra work, because it is followed by a number specifying the spacing.
  92.          * We also need to remove this number.
  93.          *
  94.          * Code stolen from sl_remlixo() function.
  95.          */
  96.         while (($n = strpos($server[7],"§")) !== FALSE) {
  97.                 $server[7] = substr($server[7],0,$n).substr($server[7],$n +2);
  98.         }
  99.                
  100.         //Servers name
  101.         $r .=  '<tr>'."\n".'<td>'.$server[7].'</td>'."\n".'';
  102.        
  103.         //Private or public?
  104.         if ($server[2] == "private")
  105.         {
  106.             $r .= '<td><img src="nyckel.png" width="14" height="6" alt="private"/></td>'."\n".''; //private
  107.         } else {
  108.             $r .= "<td> </td>\n"; //public, no image displayed.
  109.         }
  110.         //Version
  111.         $r .=  "<td>".$server[4]."</td>\n";
  112.         //Gamemode
  113.         $r .=  "<td>".str_replace("unknown","?",str_replace("treasure","trs",str_replace("battle","btl",$server[3])))."</td>\n";
  114.         //Players/Max
  115.         list($players,$capacity) = explode("/",str_replace(array("[","]"),"",$server[6]));
  116.         $r .=  "<td>[".str_pad($players, 2, 0, STR_PAD_LEFT)."/".str_pad($capacity, 2, 0, STR_PAD_LEFT)."]</td>\n";
  117.         //Close table row
  118.         $r .=  "</tr>\n";
  119.  
  120.     }
  121.    
  122.     //return the html, close table
  123.     return $r."</table>\n";
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement