Advertisement
Guest User

AssaultCube server info by PxL

a guest
Nov 9th, 2010
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.80 KB | None | 0 0
  1. <head>
  2. <title>AssaultCube server info by PxL</title>
  3. <style>
  4. body {
  5.         background-color: #696969;
  6.         color: #000000;
  7. }
  8. </style>
  9. </head>
  10.  
  11. <body>
  12. <?php
  13. if(!isset($_POST['ac_server'])) {
  14. ?>
  15. <center>
  16. <form action="" method="post">
  17. <table width="600" border=1>
  18. <tr>
  19.         <td>Server IP:</td>
  20.         <td><input type="text" name="ac_server" /></td>
  21. </tr>
  22. <tr>
  23.         <td>Server Port:</td>
  24.         <td><input type="text" name="port" /></td>
  25. </tr>
  26. <tr>
  27.         <td colspan="2" align="center"><input type="submit" value="check" /></td>
  28. </tr>
  29. </table>
  30. </form>
  31. </center>
  32. <?php
  33.         exit;
  34. }
  35.  
  36. $ip = $_REQUEST['ac_server'];
  37. $port = (int)$_REQUEST['port'];
  38.  
  39. 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
  40.         die("Error:: Incorrect IP address");
  41. }
  42.  
  43. $si = ac_serverinfo($ip, $port);
  44. if ($si == -1) {
  45.         die("Error:: Cannot get server status");
  46. }
  47.  
  48. $si['description'] = textcolors($si['description']);
  49.  
  50. ?>
  51. <center>
  52. <table width="600" border=1>
  53. <tr>
  54.         <td align="right"><b>Server:</b></td>
  55.         <td><?=$ip.":".$port?></td>
  56. </tr>
  57. <tr>
  58.         <td align="right"><b>Mode:</b></td>
  59.         <td><?=$si['mode']?></td>
  60. </tr>
  61. <tr>
  62.         <td align="right"><b>Players:</b></td>
  63.         <td><?=$si['numplayers']."/".$si['maxplayers']?></td>
  64. </tr>
  65. <tr>
  66.         <td align="right"><b>Map:</b></td>
  67.         <td><?=$si['map']?></td>
  68. </tr>
  69. <tr>
  70.         <td align="right"><b>Description:</b></td>
  71.         <td><?=$si['description']?></td>
  72. </tr>
  73. <tr>
  74.         <td align="right"><b>Status:</b></td>
  75.         <td><?=$si['pongresponse']?></td>
  76. </tr>
  77. <tr>
  78.         <td align="right"><b>Playerlist:</b></td>
  79.         <td>
  80. <?php
  81.         $players = explode(',', $si['players']);
  82.  
  83.         foreach($players as $player) {
  84.                 print htmlspecialchars($player)."<br />";
  85.         }
  86. ?>
  87.         </td>
  88. </tr>
  89. </table>
  90. </center>
  91.  
  92. </body>
  93.  
  94. <?php
  95. // from AC docs/colouredtext.txt
  96. function textcolors($text) {
  97. //      $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
  98.         $html_colors = array(
  99.                 "<span style='color: #00ee00'>",
  100.                 "<span style='color: #0000ee'>",
  101.                 "<span style='color: #f7de12'>",
  102.                 "<span style='color: #ee0000'>",
  103.                 "<span style='color: #767676'>",
  104.                 "<span style='color: #eeeeee'>",
  105.                 "<span style='color: #824f03'>",
  106.                 "<span style='color: #9a0000'>"
  107.         );
  108.  
  109.         $cflg = false;
  110.         $out = '';
  111.         $first = true;
  112.         $founded = false;
  113.  
  114.         for($i = 0; $i < strlen($text); $i++) {
  115.                 $c = ord($text[$i]);
  116.  
  117.                 if ($cflg) {
  118.                         $out.=($first?'':"</span>").$html_colors[(int)$text[$i]];
  119.                         $cflg = false;
  120.                         $first = false;
  121.                 } else if($c == 12) {
  122.                         $cflg = true;
  123.                         $founded = true;
  124.                 }
  125.                 else {
  126.                         $out.=$text[$i];
  127.                 }
  128.         }
  129.  
  130.         return $out.($founded?'</span>':'');
  131. }
  132.  
  133. function ac_serverinfo($server, $port) {
  134. // by PxL pxl@insecurebg.org
  135. // do whatever you like with that code as long as this comment stayes
  136. // 02/25/2009
  137.  
  138.         //Local functions
  139.         function tostr($hs) {
  140.                 $rsp = '';
  141.                 for($i = 0; $i < strlen($hs); $i+=2) {
  142.                         $rsp.= chr(hexdec($hs[$i].$hs[$i+1]));
  143.                 }
  144.  
  145.                 return $rsp;
  146.         }
  147.  
  148.         // From AC protocol.cpp
  149.         function getint($p) {
  150.                 $c = ord($p);
  151.  
  152.                         if($c == -128) return ($c | char($c) << <img src="./images/smilies/icon_cool.gif" alt="8)" title="Cool" />;
  153.                         else if($c== -127) { $n = $c; $n |= $c<<8; $n |= $c<<16; $n |= ($c<<24); return $n; }
  154.  
  155.                     return $c;
  156.         }
  157.  
  158.         define("DEFAULT_TIMEOUT", '3');
  159.         define("PING_REQUEST", '0a01');
  160.  
  161.         // protocol.h:enum { PONGFLAG_PASSWORD = 0, PONGFLAG_BANNED, PONGFLAG_BLACKLIST, PONGFLAG_MASTERMODE = 6, PONGFLAG_NUM };
  162.         define('PONGFLAG_PASSWORD', 0);
  163.         define('PONGFLAG_BANNED', 1);
  164.         define('PONGFLAG_BLACKLIST', 2);
  165.         define('PONGFLAG_MASTERMODE', 6);
  166.         define('PONGFLAG_NUM', 7);
  167.  
  168.         // From AC prtocol.cpp
  169.         $mmnames = array("open", "private");
  170.  
  171.         $modefullnames = array(
  172.                 "demo playback",
  173.                 "team deathmatch", "coopedit", "deathmatch", "survivor",
  174.                 "team survivor", "ctf", "pistol frenzy", "bot team deathmatch", "bot deathmatch", "last swiss standing",
  175.                 "one shot, one kill", "team one shot, one kill", "bot one shot, one kill", "hunt the flag", "team keep the flag", "keep the flag"
  176.         );
  177.  
  178.  
  179.         $server_h = fsockopen("udp://" . $server, $port, $errno, $errstr);
  180.         if (!$server_h) {
  181.                 printf("Error creating socket[%d]:: %s\n", $errno, $errstr);
  182.                 return -1;
  183.         }
  184.         socket_set_timeout($server_h, DEFAULT_TIMEOUT);
  185.  
  186.         fwrite($server_h, tostr(PING_REQUEST));
  187.         $data = fread($server_h, 1024);
  188.  
  189.         if (strlen($data) == 0) return -1;
  190.  
  191.         $si['mode'] = $modefullnames[getint($data[5])+1];
  192.         $si['numplayers'] = getint($data[6]);
  193.         $si['minremain'] = getint($data[7]);
  194.  
  195.         $si['map'] = '';
  196.         for($i = 8;;$i++) {
  197.                 if (ord($data[$i]) == 0) break;
  198.  
  199.                 $si['map'].=$data[$i];
  200.         }
  201.  
  202.         $si['description'] = '';
  203.         for($j = $i+1;;$j++) {
  204.                 if (ord($data[$j]) == 0) break;
  205.  
  206.                 $si['description'].=$data[$j];
  207.         }
  208.  
  209.         $si['maxplayers'] = getint($data[$j+1]);
  210.         $pongflags = $si['pongflags'] = getint($data[$j + 2]);
  211.         $j = $j+4;
  212.         $si['players'] = preg_replace('!\00!s', ',', substr($data, $j, strlen($data)-$j-2));
  213.  
  214.         $si['pongresponse'] = 'open';
  215.  
  216.         // from AC serverbrowser.cpp
  217.         if($pongflags > 0) {
  218.                 $mm = $pongflags >> PONGFLAG_MASTERMODE;
  219.  
  220.                 if($pongflags & (1 << PONGFLAG_BANNED))
  221.                         $si['pongresponse'] = "you are banned from this server";
  222.                 if($pongflags & (1 << PONGFLAG_BLACKLIST))
  223.                         $si['pongresponse'] = "you are blacklisted on this server";
  224.                 else if($pongflags & (1 << PONGFLAG_PASSWORD))
  225.                         $si['pongresponse'] = "this server is password-protected";
  226.                 else if($mm)  $si['pongresponse'] = $mmnames[$mm];
  227.         }
  228.  
  229.         fclose($server_h);
  230.  
  231.         return $si;
  232. }
  233.  
  234. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement