示例#1
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();
 }
示例#2
0
 /**
  * Read an Unreal Engine 2 string
  *
  * Adapted from original GameQ code
  *
  * @param GameQ_Buffer $buf
  * @return string <string, mixed>
  */
 private function _readUnrealString(GameQ_Buffer &$buf)
 {
     // Normal pascal string
     if (ord($buf->lookAhead(1)) < 129) {
         return $buf->readPascalString(1);
     }
     // UnrealEngine2 color-coded string
     $length = ($buf->readInt8() - 128) * 2 - 3;
     $encstr = $buf->read($length);
     $buf->skip(3);
     // Remove color-code tags
     $encstr = preg_replace('~\\x5e\\0\\x23\\0..~s', '', $encstr);
     // Remove every second character
     // The string is UCS-2, this approximates converting to latin-1
     $str = '';
     for ($i = 0, $ii = strlen($encstr); $i < $ii; $i += 2) {
         $str .= $encstr[$i];
     }
     return $str;
 }