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

Source for file Unreal2XMP.php

Documentation is available at Unreal2XMP.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: Unreal2XMP.php,v 1.5 2004/09/14 10:47:40 ortega Exp $
  20.  
  21.  
  22. require_once 'Net\GameServerQuery\Protocol.php';
  23.  
  24.  
  25. /**
  26.  * Unreal 2 XMP protocol
  27.  *
  28.  * @category       Net
  29.  * @package        Net_GameServerQuery
  30.  * @author         Tom Buskens <ortega@php.net>
  31.  * @version        $Revision: 1.5 $
  32.  */
  33. {
  34.     /**
  35.      * Players packet
  36.      *
  37.      * @access  protected
  38.      * @return  array      Array containing formatted server response
  39.      */
  40.     protected function _players()
  41.     {
  42.         // Packet id
  43.         if (!$this->_match("\x02")) {
  44.             throw new Exception('Parsing error');
  45.         }
  46.  
  47.         // Init player id, needed for player properties
  48.         $player_id = 0;
  49.  
  50.         // Players
  51.         while ($this->_match("(.{4})(.{4})(.)")) {
  52.  
  53.             // Player number & ID (never updated, bug?)
  54.             $this->_add('playernumber'$this->toInt($this->_result[1]32));
  55.             $this->_add('playerid',     $this->toInt($this->_result[2]32));
  56.  
  57.             // Get player name length and create expression
  58.             $name_length $this->toInt($this->_result[3]- 1;
  59.             $expr sprintf("(.{%d})\x00(.{4})(.{4})(.{4})(.)"$name_length);
  60.  
  61.             if (!$this->_match($expr)) {
  62.                 return false;
  63.             }
  64.  
  65.             $this->_addPlayer('name',   $this->_result[1]);
  66.             $this->_addPlayer('ping',   $this->toInt($this->_result[2]32));
  67.             $this->_addPlayer('score',  $this->toInt($this->_result[3]32));
  68.             $this->_addPlayer('statid'$this->toInt($this->_result[4]32));
  69.  
  70.             // Get player properties
  71.             $properties_number $this->toInt($this->_result[5]));
  72.             for ($i = 0; $i != $properties_number$i++{
  73.  
  74.                 // Get property name length
  75.                 if (!$this->_match(".")) {
  76.                     throw new Exception('Parsing error');
  77.                 }
  78.                 $name_length $this->toInt($this->_result[0]- 1;
  79.  
  80.                 // Get property name
  81.                 $expr sprintf("(.{%d})(.)"$name_length);
  82.                 if (!$this->_match($expr)) {
  83.                     throw new Exception('Parsing error');
  84.                 }
  85.                 $name $this->_result[1];
  86.  
  87.                 // Get property value length
  88.                 $val_length $this->toInt($this->_result[2]- 1;
  89.  
  90.                 // Get property value
  91.                 $expr sprintf(".{%d}"$val_length);
  92.                 if (!$this->_match($expr)) {
  93.                     throw new Exception('Parsing error');
  94.                 }
  95.  
  96.                 // Assign property value to a variable with property name
  97.                 $this->_add($name $player_id$this->_match[0]);
  98.             }
  99.  
  100.             ++$player_id;
  101.         }
  102. }
  103.  
  104. ?>

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