Net_GameServerQuery
[ class tree: Net_GameServerQuery ] [ index: Net_GameServerQuery ] [ all elements ]

Source for file UnrealTournament03.php

Documentation is available at UnrealTournament03.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2004 The PHP Group                                |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 3.0 of the PHP license,       |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available through the world-wide-web at the following url:           |
  10. // | http://www.php.net/license/3_0.txt.                                  |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Authors: Aidan Lister <aidan@php.net>                                |
  16. // |          Tom Buskens <ortega@php.net>                                |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: UnrealTournament03.php,v 1.4 2004/09/14 10:47:40 ortega Exp $
  20.  
  21.  
  22. require_once 'Net\GameServerQuery\Protocol.php';
  23.  
  24.  
  25. /**
  26.  * Unreal Tournament 2003 protocol
  27.  *
  28.  * @category       Net
  29.  * @package        Net_GameServerQuery
  30.  * @author         Tom Buskens <ortega@php.net>
  31.  * @version        $Revision: 1.4 $
  32.  */
  33. {
  34.  
  35.     /**
  36.      * Players packet
  37.      *
  38.      * @access  protected
  39.      * @return  array      Array containing formatted server response
  40.      */
  41.     protected function _players()
  42.     {
  43.         // Packet id
  44.         if (!$this->_match("\x02")) {
  45.             throw new Exception('Parsing error');
  46.         }
  47.  
  48.         // Players
  49.         while ($this->_match("(.{4})(.)")) {
  50.  
  51.             // Player id
  52.             $this->_add('playerid'$this->toInt($this->_result[1]32));
  53.  
  54.             // Get player name length and create expression
  55.             $name_length $this->toInt($this->_result[2]- 1;
  56.             $expr sprintf("(.{%d})\x00(.{4})(.{4})(.{4})"$name_length);
  57.  
  58.             // Match expression
  59.             if (!$this->_match($expr)) {
  60.                 throw new Exception('Parsing error');
  61.             }
  62.  
  63.             $this->_addPlayer('name',  $this->_result[1]);
  64.             $this->_addPlayer('ping',  $this->toInt($this->_result[2]32));
  65.             $this->_addPlayer('score'$this->toInt($this->_result[2]32));
  66.             $this->_addPlayer('team',  $this->toInt($this->_result[2]32));
  67.         }
  68.  
  69.         return $this->_output;
  70.     }
  71.  
  72.  
  73.     /**
  74.      * Rules packet
  75.      *
  76.      * @access  protected
  77.      * @return  array      Array containing formatted server response
  78.      */
  79.     protected function _rules()
  80.     {
  81.         // Packet id
  82.         if (!$this->_match("\x01")) {
  83.             throw new Exception('Parsing error');
  84.         }
  85.  
  86.         // Var / value set.
  87.         while ($this->_match(".")) {
  88.  
  89.             // Create expression using result of previous match to set the string length
  90.             $expr sprintf("(.{%d})\x00(.)"($this->toInt($this->_result[0]- 1));
  91.  
  92.             // Get variable name
  93.             if ($this->_match($expr)) {
  94.                 $name $this->_result[1];
  95.  
  96.                 // Create expression using result of previous match to set string length
  97.                 $expr sprintf("(.{%d})\x00"($this->toInt($this->_result[2]- 1));
  98.  
  99.                 // Get variable value
  100.                 if ($this->_match($expr)) {
  101.                     $this->_add($name$this->_result[1]);
  102.                 }
  103.                 else {
  104.                     throw new Exception('Parsing error');
  105.                 }
  106.             }
  107.             else {
  108.                 throw new Exception('Parsing error');
  109.             }
  110.  
  111.         }
  112.     }
  113.  
  114.  
  115.     /**
  116.      * Status packet
  117.      *
  118.      * @access  protected
  119.      * @return  array      Array containing formatted server response
  120.      */
  121.     protected function _status()
  122.     {
  123.         // Get some 32 bit variables
  124.         if (!$this->_match("\x00(.{4})\x00(.{4})(.{4})([^\x00]+)\x00(.)")) {
  125.             throw new Exception('Parsing error');
  126.         }
  127.  
  128.         $this->_add('gameport',  $this->toInt($this->_result[2]32));
  129.         $this->_add('queryport'$this->toInt($this->_result[3]32));
  130.         $this->_add('hostname',  $this->_result[4]);
  131.  
  132.         // Create expression using result of previous match to set string length
  133.         $expr sprintf("(.{%d})(.)"($this->toInt($this->_result[5]- 1));
  134.         if (!$this->_match($expr)) {
  135.             throw new Exception('Parsing error');
  136.         }
  137.  
  138.         $this->_add('map'$this->_result[1]);
  139.  
  140.         // Create expression using result of previous match to set string length
  141.         $expr sprintf("(.{%d})(.{4})(.{4})"($this->toInt($this->_result[2]- 1));
  142.         if (!$this->_match($expr)) {
  143.             throw new Exception('Parsing error');
  144.         }
  145.  
  146.         $this->_add('gametype',   $this->_result[1]);
  147.         $this->_add('players',    $this->toInt($this->_result[2]32));
  148.         $this->_add('maxplayers'$this->toInt($this->_result[3]32));
  149.  
  150.         return $this->_output;
  151.  
  152.     }
  153. }
  154. ?>

Documentation generated on Mon, 11 Mar 2019 13:58:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.