Esempio n. 1
0
 /**
  * Handles processing the status data into a usable format
  *
  * @throws GameQ_ProtocolsException
  */
 protected function process_status()
 {
     // Make sure we have a valid response
     if (!$this->hasValidResponse(self::PACKET_STATUS)) {
         return array();
     }
     // Set the result to a new result instance
     $result = new GameQ_Result();
     // Let's preprocess the rules
     $data = $this->preProcess_status($this->packets_response[self::PACKET_STATUS]);
     // Create a new buffer
     $buf = new GameQ_Buffer($data);
     // Skip the header
     $buf->skip(6);
     $result->add('mod', $buf->readPascalString());
     $result->add('gametype', $buf->readPascalString());
     $result->add('map', $buf->readPascalString());
     // Grab the flag
     $flag = $buf->read();
     $bit = 1;
     foreach (array('dedicated', 'password', 'linux', 'tournament', 'no_alias') as $var) {
         $value = $flag & $bit ? 1 : 0;
         $result->add($var, $value);
         $bit *= 2;
     }
     $result->add('num_players', $buf->readInt8());
     $result->add('max_players', $buf->readInt8());
     $result->add('num_bots', $buf->readInt8());
     $result->add('cpu', $buf->readInt16());
     $result->add('info', $buf->readPascalString());
     $buf->skip(2);
     // Do teams
     $num_teams = $buf->read();
     $result->add('num_teams', $num_teams);
     $buf->skip();
     for ($i = 0; $i < $num_teams; $i++) {
         $result->addTeam('name', $buf->readString("\t"));
         $result->addTeam('score', $buf->readString("\n"));
     }
     // Do players
     // @todo:  No code here to do players, no docs either, need example server with players
     unset($buf, $data);
     return $result->fetch();
 }
Esempio n. 2
0
 /**
  * Process the server status
  *
  * @throws GameQ_ProtocolsException
  */
 protected function process_status()
 {
     // Make sure we have a valid response
     if (!$this->hasValidResponse(self::PACKET_STATUS)) {
         return array();
     }
     // Set the result to a new result instance
     $result = new GameQ_Result();
     // Lets pre process and make sure these things are in the proper order by id
     $data = $this->preProcess($this->packets_response[self::PACKET_STATUS]);
     // Create a new buffer
     $buf = new GameQ_Buffer($data);
     // Lets peek and see if the data starts with a \
     if ($buf->lookAhead(1) == '\\') {
         // Burn the first one
         $buf->skip(1);
     }
     // Explode the data
     $data = explode('\\', $buf->getBuffer());
     // Remove the last 2 "items" as it should be final\
     array_pop($data);
     array_pop($data);
     // Init some vars
     $num_players = 0;
     $num_teams = 0;
     // Now lets loop the array
     for ($x = 0; $x < count($data); $x += 2) {
         // Set some local vars
         $key = $data[$x];
         $val = $data[$x + 1];
         // Check for <variable>_<count> variable (i.e players)
         if (($suffix = strrpos($key, '_')) !== FALSE && is_numeric(substr($key, $suffix + 1))) {
             // See if this is a team designation
             if (substr($key, 0, $suffix) == 'teamname') {
                 $result->addTeam('teamname', $val);
                 $num_teams++;
             } else {
                 if (substr($key, 0, $suffix) == 'playername') {
                     $num_players++;
                 }
                 $result->addPlayer(substr($key, 0, $suffix), $val);
             }
         } else {
             $result->add($key, $val);
         }
     }
     // Add the player and team count
     $result->add('num_players', $num_players);
     $result->add('num_teams', $num_teams);
     unset($buf, $data, $key, $val, $suffix, $x);
     return $result->fetch();
 }
Esempio n. 3
0
 /**
  * Process the channel listing
  */
 protected function process_channels()
 {
     // Make sure we have a valid response
     if (!$this->hasValidResponse(self::PACKET_CHANNELS)) {
         return array();
     }
     // Let's preprocess the status
     $buffer = $this->preProcess($this->packets_response[self::PACKET_CHANNELS]);
     // Set the result to a new result instance
     $result = new GameQ_Result();
     // The first line holds the column names, data returned is in column/row format
     $columns = explode("\t", trim($buffer->readString("\n")), 9);
     // Loop thru the rows until we run out of information
     while ($buffer->getLength()) {
         // Grab the row, which is a tabbed list of items
         // Check for end of packet
         if (($row = trim($buffer->readString("\n"))) == 'OK') {
             break;
         }
         // Explode and merge the data with the columns, then parse
         $data = array_combine($columns, explode("\t", $row, 9));
         foreach ($data as $key => $value) {
             // Now add the data to the result
             $result->addTeam($key, $value);
         }
     }
     unset($data, $buffer, $row, $columns, $key, $value);
     return $result->fetch();
 }
Esempio n. 4
0
 /**
  * Process the channel listing
  */
 protected function process_channels()
 {
     // Make sure we have a valid response
     if (!$this->hasValidResponse(self::PACKET_CHANNELS)) {
         return array();
     }
     // Let's preprocess the status
     $buffer = $this->preProcess($this->packets_response[self::PACKET_CHANNELS]);
     // Process the buffer response
     $data = $this->parse_response($buffer);
     // Set the result to a new result instance
     $result = new GameQ_Result();
     foreach ($data as $channel) {
         $channel['channel_name'] = htmlentities($channel['channel_name'], ENT_QUOTES, "UTF-8");
         foreach ($channel as $key => $value) {
             $result->addTeam($key, $value);
         }
     }
     unset($data, $buffer, $channel, $key, $value);
     return $result->fetch();
 }
Esempio n. 5
0
 /**
  * Process the channel and user information
  *
  * @param GameQ_Result $result
  * @param array $item
  */
 protected function process_channels_users(GameQ_Result &$result, $item)
 {
     // Let's add all of the channel information
     foreach ($item as $key => $value) {
         // We will handle these later
         if (in_array($key, array('channels', 'users'))) {
             // skip
             continue;
         }
         // Add the channel property as a team
         $result->addTeam($key, $value);
     }
     // Itereate over the users in this channel
     foreach ($item['users'] as $user) {
         foreach ($user as $key => $value) {
             $result->addPlayer($key, $value);
         }
     }
     // Offload more channels to parse
     foreach ($item['channels'] as $channel) {
         $this->process_channels_users($result, $channel);
     }
 }