Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <head>
- <title>AssaultCube server info by PxL</title>
- <style>
- body {
- background-color: #696969;
- color: #000000;
- }
- </style>
- </head>
- <body>
- <?php
- if(!isset($_POST['ac_server'])) {
- ?>
- <center>
- <form action="" method="post">
- <table width="600" border=1>
- <tr>
- <td>Server IP:</td>
- <td><input type="text" name="ac_server" /></td>
- </tr>
- <tr>
- <td>Server Port:</td>
- <td><input type="text" name="port" /></td>
- </tr>
- <tr>
- <td colspan="2" align="center"><input type="submit" value="check" /></td>
- </tr>
- </table>
- </form>
- </center>
- <?php
- exit;
- }
- $ip = $_REQUEST['ac_server'];
- $port = (int)$_REQUEST['port'];
- if (!preg_match('![0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}!s', $ip)) { // Not the perfect check, but just for filtering
- die("Error:: Incorrect IP address");
- }
- $si = ac_serverinfo($ip, $port);
- if ($si == -1) {
- die("Error:: Cannot get server status");
- }
- $si['description'] = textcolors($si['description']);
- ?>
- <center>
- <table width="600" border=1>
- <tr>
- <td align="right"><b>Server:</b></td>
- <td><?=$ip.":".$port?></td>
- </tr>
- <tr>
- <td align="right"><b>Mode:</b></td>
- <td><?=$si['mode']?></td>
- </tr>
- <tr>
- <td align="right"><b>Players:</b></td>
- <td><?=$si['numplayers']."/".$si['maxplayers']?></td>
- </tr>
- <tr>
- <td align="right"><b>Map:</b></td>
- <td><?=$si['map']?></td>
- </tr>
- <tr>
- <td align="right"><b>Description:</b></td>
- <td><?=$si['description']?></td>
- </tr>
- <tr>
- <td align="right"><b>Status:</b></td>
- <td><?=$si['pongresponse']?></td>
- </tr>
- <tr>
- <td align="right"><b>Playerlist:</b></td>
- <td>
- <?php
- $players = explode(',', $si['players']);
- foreach($players as $player) {
- print htmlspecialchars($player)."<br />";
- }
- ?>
- </td>
- </tr>
- </table>
- </center>
- </body>
- <?php
- // from AC docs/colouredtext.txt
- function textcolors($text) {
- // $xterm_colors = array('\033[1;32m','\033[1;34m','\033[1;33m','\033[1;31m','\033[1;30m','\033[1;37m','\033[1;36m','\033[1;35m'); // used that for testing
- $html_colors = array(
- "<span style='color: #00ee00'>",
- "<span style='color: #0000ee'>",
- "<span style='color: #f7de12'>",
- "<span style='color: #ee0000'>",
- "<span style='color: #767676'>",
- "<span style='color: #eeeeee'>",
- "<span style='color: #824f03'>",
- "<span style='color: #9a0000'>"
- );
- $cflg = false;
- $out = '';
- $first = true;
- $founded = false;
- for($i = 0; $i < strlen($text); $i++) {
- $c = ord($text[$i]);
- if ($cflg) {
- $out.=($first?'':"</span>").$html_colors[(int)$text[$i]];
- $cflg = false;
- $first = false;
- } else if($c == 12) {
- $cflg = true;
- $founded = true;
- }
- else {
- $out.=$text[$i];
- }
- }
- return $out.($founded?'</span>':'');
- }
- function ac_serverinfo($server, $port) {
- // by PxL pxl@insecurebg.org
- // do whatever you like with that code as long as this comment stayes
- // 02/25/2009
- //Local functions
- function tostr($hs) {
- $rsp = '';
- for($i = 0; $i < strlen($hs); $i+=2) {
- $rsp.= chr(hexdec($hs[$i].$hs[$i+1]));
- }
- return $rsp;
- }
- // From AC protocol.cpp
- function getint($p) {
- $c = ord($p);
- if($c == -128) return ($c | char($c) << <img src="./images/smilies/icon_cool.gif" alt="8)" title="Cool" />;
- else if($c== -127) { $n = $c; $n |= $c<<8; $n |= $c<<16; $n |= ($c<<24); return $n; }
- return $c;
- }
- define("DEFAULT_TIMEOUT", '3');
- define("PING_REQUEST", '0a01');
- // protocol.h:enum { PONGFLAG_PASSWORD = 0, PONGFLAG_BANNED, PONGFLAG_BLACKLIST, PONGFLAG_MASTERMODE = 6, PONGFLAG_NUM };
- define('PONGFLAG_PASSWORD', 0);
- define('PONGFLAG_BANNED', 1);
- define('PONGFLAG_BLACKLIST', 2);
- define('PONGFLAG_MASTERMODE', 6);
- define('PONGFLAG_NUM', 7);
- // From AC prtocol.cpp
- $mmnames = array("open", "private");
- $modefullnames = array(
- "demo playback",
- "team deathmatch", "coopedit", "deathmatch", "survivor",
- "team survivor", "ctf", "pistol frenzy", "bot team deathmatch", "bot deathmatch", "last swiss standing",
- "one shot, one kill", "team one shot, one kill", "bot one shot, one kill", "hunt the flag", "team keep the flag", "keep the flag"
- );
- $server_h = fsockopen("udp://" . $server, $port, $errno, $errstr);
- if (!$server_h) {
- printf("Error creating socket[%d]:: %s\n", $errno, $errstr);
- return -1;
- }
- socket_set_timeout($server_h, DEFAULT_TIMEOUT);
- fwrite($server_h, tostr(PING_REQUEST));
- $data = fread($server_h, 1024);
- if (strlen($data) == 0) return -1;
- $si['mode'] = $modefullnames[getint($data[5])+1];
- $si['numplayers'] = getint($data[6]);
- $si['minremain'] = getint($data[7]);
- $si['map'] = '';
- for($i = 8;;$i++) {
- if (ord($data[$i]) == 0) break;
- $si['map'].=$data[$i];
- }
- $si['description'] = '';
- for($j = $i+1;;$j++) {
- if (ord($data[$j]) == 0) break;
- $si['description'].=$data[$j];
- }
- $si['maxplayers'] = getint($data[$j+1]);
- $pongflags = $si['pongflags'] = getint($data[$j + 2]);
- $j = $j+4;
- $si['players'] = preg_replace('!\00!s', ',', substr($data, $j, strlen($data)-$j-2));
- $si['pongresponse'] = 'open';
- // from AC serverbrowser.cpp
- if($pongflags > 0) {
- $mm = $pongflags >> PONGFLAG_MASTERMODE;
- if($pongflags & (1 << PONGFLAG_BANNED))
- $si['pongresponse'] = "you are banned from this server";
- if($pongflags & (1 << PONGFLAG_BLACKLIST))
- $si['pongresponse'] = "you are blacklisted on this server";
- else if($pongflags & (1 << PONGFLAG_PASSWORD))
- $si['pongresponse'] = "this server is password-protected";
- else if($mm) $si['pongresponse'] = $mmnames[$mm];
- }
- fclose($server_h);
- return $si;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement