Guest User

get_tw_server_0_5

a guest
Jan 22nd, 2014
168
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     /******************************************************************\
  3.     |* Copyright (c) by Starlex.de
  4.     |*
  5.     |* Visit:
  6.     |*      http://teeworlds.com
  7.     |*      http://teeworlds-community.de
  8.     |*
  9.     |* License:
  10.     |*      http://creativecommons.org/licenses/by-nc-sa/3.0/deed.de
  11.     |*
  12.     \******************************************************************/
  13.  
  14. function get_tw_srv($server) {
  15.  
  16.     $socket = stream_socket_client('udp://'.$server , $errno, $errstr, "2");
  17.     stream_set_timeout($socket, "2");
  18.     fwrite($socket, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xffgief");
  19.     stream_set_timeout($socket, "2");
  20.     $response = fread($socket, 2048);
  21.    
  22.     if ($response){
  23.         $test = explode("\x00",$response);
  24.         $players = array();
  25.  
  26.         for ($i = 0; $i <= $test[6]*2 ; $i += 2) {
  27.             $players[] = array("name" => $test[$i+8],"score" => $test[$i+8+1]);
  28.         }
  29.        
  30.         $tmp = array(
  31.         "version" => str_replace("info","",str_replace("\xff","",$test[0])),
  32.         "name" => $test[1],
  33.         "map" => $test[2],
  34.         "type" => $test[3],
  35.         "flags" => $test[4],
  36.         "progression" => $test[5],
  37.         "player_count" => $test[6],
  38.         "max_players" => $test[7],
  39.         "players" => $players);
  40.        
  41.         return $tmp;
  42.        
  43.     } else {
  44.         return FALSE;
  45.     }
  46. }
  47. ?>
RAW Paste Data