Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gipke () {
- /*
- * Multiple lists:
- * this array declared below here contains the urls of the
- * listservers the script will check. It will query them in
- * the order they are listed here, and will choose the first
- * one it can connect succesfully to.
- *
- * To keep this efficient, each connection attempt gets a
- * maximal timeout of 1 second.
- *
- * The one who mantains the site should add new servers and remove
- * obsolete ones. Also, reorder them to make sure the servers
- * that are online the most are first in the list.
- *
- * Worst case: 1 second per url here spent loading(!), so keep
- * the list small and tidy!
- *
- */
- $servers = array(
- 'list1.digiex.net',
- 'list2.digiex.net'
- );
- //Write start of table
- $r = "\n".'<table border="0" align="center">'."\n".'';
- //Initialize the connection variable.
- $connection = false;
- foreach($servers as $server)
- {
- $connection = fsockopen($server, 10057, $errno, $errstr,1);
- if (!$connection)
- {
- continue; //failed, on to the next value
- } else {
- break; //succeeded, proceed with this connection.
- }
- }
- if (!$connection)
- {
- //Not a single listserver responded, return false.
- return false;
- }
- $list = ''; //Received data accumulated here
- while (!feof($connection)) $list .= fread($connection, 8192); //Read raw data
- fclose($connection);
- //tidy up version names
- $list = nl2br($list);
- $list = str_replace(" ", " ", $list);
- $list = str_replace("1.25 c", "1.25c", $list);
- $list = str_replace("1.25 d", "1.25d", $list);
- $list = str_replace("1.24 x", "1.24x", $list);
- $list = str_replace("1.24 s", "1.24s", $list);
- $list = str_replace("1.21 s", "1.21s", $list);
- $list = str_replace("1.20 s", "1.20s", $list);
- $list = str_replace("1.21", "1.23", $list);
- $list = explode("\n", $list);
- /*
- * Listservers always add an unneeded newline after the last line,
- * because of the jj2 devs being lazy. because this script separates
- * servers using newlines, 1 is subtracted from the count to ignore
- * the last, empty line.
- */
- $number = count($list) - 1;
- //Iterate over the servers to format them into a html table:
- for ($counter=0; $counter<$number; $counter++)
- {
- $server = explode(" ",$list[$counter],8);
- /*
- *Fix ampersands and '<','>' and remove formatting chars '|' and '§'.
- */
- $server[7] = str_replace("&","&",$server[7]);
- $server[7] = str_replace("<","<",$server[7]);
- $server[7] = str_replace(">",">",$server[7]);
- $server[7] = str_replace("|","",$server[7]);
- /*
- * '§' needs some extra work, because it is followed by a number specifying the spacing.
- * We also need to remove this number.
- *
- * Code stolen from sl_remlixo() function.
- */
- while (($n = strpos($server[7],"§")) !== FALSE) {
- $server[7] = substr($server[7],0,$n).substr($server[7],$n +2);
- }
- //Servers name
- $r .= '<tr>'."\n".'<td>'.$server[7].'</td>'."\n".'';
- //Private or public?
- if ($server[2] == "private")
- {
- $r .= '<td><img src="nyckel.png" width="14" height="6" alt="private"/></td>'."\n".''; //private
- } else {
- $r .= "<td> </td>\n"; //public, no image displayed.
- }
- //Version
- $r .= "<td>".$server[4]."</td>\n";
- //Gamemode
- $r .= "<td>".str_replace("unknown","?",str_replace("treasure","trs",str_replace("battle","btl",$server[3])))."</td>\n";
- //Players/Max
- list($players,$capacity) = explode("/",str_replace(array("[","]"),"",$server[6]));
- $r .= "<td>[".str_pad($players, 2, 0, STR_PAD_LEFT)."/".str_pad($capacity, 2, 0, STR_PAD_LEFT)."]</td>\n";
- //Close table row
- $r .= "</tr>\n";
- }
- //return the html, close table
- return $r."</table>\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement