Advertisement
Guest User

AssaultCube server info by PxL

a guest
Nov 9th, 2010
521
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. // do whatever you like with that code as long as this comment stayes
  135. // 02/25/2009
  136.  
  137.         //Local functions
  138.         function tostr($hs) {
  139.                 $rsp = '';
  140.                 for($i = 0; $i < strlen($hs); $i+=2) {
  141.                         $rsp.= chr(hexdec($hs[$i].$hs[$i+1]));
  142.                 }
  143.  
  144.                 return $rsp;
  145.         }
  146.  
  147.         // From AC protocol.cpp
  148.         function getint($p) {
  149.                 $c = ord($p);
  150.  
  151.                         if($c == -128) return ($c | char($c) << <img src="./images/smilies/icon_cool.gif" alt="8)" title="Cool" />;
  152.                         else if($c== -127) { $n = $c; $n |= $c<<8; $n |= $c<<16; $n |= ($c<<24); return $n; }
  153.  
  154.                     return $c;
  155.         }
  156.  
  157.         define("DEFAULT_TIMEOUT", '3');
  158.         define("PING_REQUEST", '0a01');
  159.  
  160.         // protocol.h:enum { PONGFLAG_PASSWORD = 0, PONGFLAG_BANNED, PONGFLAG_BLACKLIST, PONGFLAG_MASTERMODE = 6, PONGFLAG_NUM };
  161.         define('PONGFLAG_PASSWORD', 0);
  162.         define('PONGFLAG_BANNED', 1);
  163.         define('PONGFLAG_BLACKLIST', 2);
  164.         define('PONGFLAG_MASTERMODE', 6);
  165.         define('PONGFLAG_NUM', 7);
  166.  
  167.         // From AC prtocol.cpp
  168.         $mmnames = array("open", "private");
  169.  
  170.         $modefullnames = array(
  171.                 "demo playback",
  172.                 "team deathmatch", "coopedit", "deathmatch", "survivor",
  173.                 "team survivor", "ctf", "pistol frenzy", "bot team deathmatch", "bot deathmatch", "last swiss standing",
  174.                 "one shot, one kill", "team one shot, one kill", "bot one shot, one kill", "hunt the flag", "team keep the flag", "keep the flag"
  175.         );
  176.  
  177.  
  178.         $server_h = fsockopen("udp://" . $server, $port, $errno, $errstr);
  179.         if (!$server_h) {
  180.                 printf("Error creating socket[%d]:: %s\n", $errno, $errstr);
  181.                 return -1;
  182.         }
  183.         socket_set_timeout($server_h, DEFAULT_TIMEOUT);
  184.  
  185.         fwrite($server_h, tostr(PING_REQUEST));
  186.         $data = fread($server_h, 1024);
  187.  
  188.         if (strlen($data) == 0) return -1;
  189.  
  190.         $si['mode'] = $modefullnames[getint($data[5])+1];
  191.         $si['numplayers'] = getint($data[6]);
  192.         $si['minremain'] = getint($data[7]);
  193.  
  194.         $si['map'] = '';
  195.         for($i = 8;;$i++) {
  196.                 if (ord($data[$i]) == 0) break;
  197.  
  198.                 $si['map'].=$data[$i];
  199.         }
  200.  
  201.         $si['description'] = '';
  202.         for($j = $i+1;;$j++) {
  203.                 if (ord($data[$j]) == 0) break;
  204.  
  205.                 $si['description'].=$data[$j];
  206.         }
  207.  
  208.         $si['maxplayers'] = getint($data[$j+1]);
  209.         $pongflags = $si['pongflags'] = getint($data[$j + 2]);
  210.         $j = $j+4;
  211.         $si['players'] = preg_replace('!\00!s', ',', substr($data, $j, strlen($data)-$j-2));
  212.  
  213.         $si['pongresponse'] = 'open';
  214.  
  215.         // from AC serverbrowser.cpp
  216.         if($pongflags > 0) {
  217.                 $mm = $pongflags >> PONGFLAG_MASTERMODE;
  218.  
  219.                 if($pongflags & (1 << PONGFLAG_BANNED))
  220.                         $si['pongresponse'] = "you are banned from this server";
  221.                 if($pongflags & (1 << PONGFLAG_BLACKLIST))
  222.                         $si['pongresponse'] = "you are blacklisted on this server";
  223.                 else if($pongflags & (1 << PONGFLAG_PASSWORD))
  224.                         $si['pongresponse'] = "this server is password-protected";
  225.                 else if($mm)  $si['pongresponse'] = $mmnames[$mm];
  226.         }
  227.  
  228.         fclose($server_h);
  229.  
  230.         return $si;
  231. }
  232.  
  233. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement