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

Source for file GameSpy04.php

Documentation is available at GameSpy04.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: GameSpy04.php,v 1.13 2004/11/05 15:23:33 ortega Exp $
  20.  
  21.  
  22. require_once 'Net\GameServerQuery\Protocol.php';
  23.  
  24.  
  25. /**
  26.  * GameSpy04 Protocol
  27.  *
  28.  * @category       Net
  29.  * @package        Net_GameServerQuery
  30.  * @author         Tom Buskens <ortega@php.net>
  31.  * @version        $Revision: 1.13 $
  32.  */
  33. {
  34.     /**
  35.      * Rules packet
  36.      *
  37.      * @access    protected
  38.      * @return    array      Array containing formatted server response
  39.      */
  40.     protected function _rules()
  41.     {
  42.         // Header
  43.         $this->_getHeader();
  44.  
  45.         // Variable / value pairs
  46.         while ($this->_match("([^\x00]+)\x00([^\x00]*)\x00")) {
  47.             $this->_add($this->_result[1]$this->_result[2]);
  48.         }
  49.  
  50.         return $this->_output;
  51.  
  52.     }
  53.  
  54.  
  55.     /**
  56.      * Player packet
  57.      *
  58.      * @access     protected
  59.      * @return     array     Array containing formatted server response
  60.      */
  61.     protected function _players()
  62.     {
  63.         // Header
  64.         $this->_getHeader();
  65.  
  66.         // Get values
  67.         if (!$this->_getValues('player')) {
  68.             return false;
  69.         }
  70.  
  71.         // Get team info (same packet)
  72.         $this->_team(true);
  73.  
  74.         return $this->_output;
  75.  
  76.     }
  77.  
  78.     /**
  79.      * Team packet
  80.      *
  81.      * @access     protected
  82.      * @param      bool  $from_players  True if packet was also contained player data.
  83.      * @return     array Array containing formatted server response
  84.      */
  85.     protected function _team($from_players = false)
  86.     {
  87.         // Header
  88.         if (!$from_players{
  89.             $this->_getHeader();
  90.         }
  91.  
  92.         // Get values
  93.         if (!$this->_getValues('team')) {
  94.             return false;
  95.         }
  96.  
  97.     }
  98.  
  99.     /**
  100.      * Checks header
  101.      *
  102.      * @access     private
  103.      * @return     bool      True if matched, false if not
  104.      */
  105.     private function _getHeader()
  106.     {
  107.         if ($this->_getPrefix(5== "\x00NGSQ"{
  108.             return true;
  109.         }
  110.         else {
  111.             throw new Exception('Parsing error: header not matched');
  112.             return false;
  113.         }
  114.     }
  115.  
  116.     /**
  117.      * Gets variables according to a specific pattern
  118.      *
  119.      * @access     private
  120.      * @param      string    $type     Variable type
  121.      * @return     bool      True on success, false on pattern match failure
  122.      */
  123.     private function _getValues($type)
  124.     {
  125.         // Get number of sets
  126.         if (!$this->_match("\x00(.)")) {
  127.             throw new Exception('Parsing error');
  128.         }
  129.  
  130.         // Convert byte to integer
  131.         $count $this->toInt($this->_result[1]8);
  132.  
  133.         // Add count to output
  134.         $this->_add($type 'count'$count);
  135.  
  136.         // Get variable names, always start with an underscore
  137.         $variables = array();
  138.  
  139.         while (true{
  140.  
  141.             if (!$this->_match("_([^\x00]+)\x00")) {
  142.                 return false;
  143.             }
  144.  
  145.             // Save variable name
  146.             array_push($variables$this->_result[1]);
  147.  
  148.             // Variable name sequence is ended with a second \x00
  149.             if ($this->_match("\x00")) {
  150.                 break;
  151.             }
  152.  
  153.         }
  154.  
  155.         // Get variable values
  156.         $var_count count($variables);
  157.  
  158.         // Loop through sets
  159.         for ($i = 0; $i !== $count$i++{
  160.  
  161.             // Get values for each set
  162.             for ($j = 0; $j !== $var_count$j++{
  163.  
  164.                 if (!$this->_match("([^\x00]+)\x00")) {
  165.                     return false;
  166.                 }
  167.  
  168.                 // Add variables to output
  169.                 $this->_addPlayer($variables[$j]$this->_result[1]);
  170.  
  171.             }
  172.  
  173.         }
  174.  
  175.         return true;
  176.  
  177.     }
  178.  
  179. }
  180.  
  181. ?>

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