/** * Handle player info, different than quake3 base * * @param Buffer $buffer * * @return array * @throws \GameQ\Exception\Protocol */ protected function processPlayers(Buffer $buffer) { // Set the result to a new result instance $result = new Result(); // Loop until we are out of data while ($buffer->getLength()) { // Make a new buffer with this block $playerInfo = new Buffer($buffer->readString("\n")); // Add player info $result->addPlayer('frags', $playerInfo->readString(" ")); $result->addPlayer('ping', $playerInfo->readString(" ")); // Skip first " $playerInfo->skip(1); // Add player name, encoded $result->addPlayer('name', utf8_encode(trim($playerInfo->readString('"')))); // Skip space $playerInfo->skip(1); // Add team $result->addPlayer('team', $playerInfo->read()); // Clear unset($playerInfo); } // Clear unset($buffer); return $result->fetch(); }
/** * Specific player parse for The Ship * * Player response has unknown data after the last real player * * @param \GameQ\Buffer $buffer * * @return array */ protected function processPlayers(Buffer $buffer) { // Set the result to a new result instance $result = new Result(); // We need to read the number of players because this response has other data at the end usually $num_players = $buffer->readInt8(); // Player count $result->add('num_players', $num_players); // No players, no work if ($num_players == 0) { return $result->fetch(); } // Players list for ($player = 0; $player < $num_players; $player++) { $result->addPlayer('id', $buffer->readInt8()); $result->addPlayer('name', $buffer->readString()); $result->addPlayer('score', $buffer->readInt32Signed()); $result->addPlayer('time', $buffer->readFloat32()); } // Extra data if ($buffer->getLength() > 0) { for ($player = 0; $player < $num_players; $player++) { $result->addPlayer('deaths', $buffer->readInt32Signed()); $result->addPlayer('money', $buffer->readInt32Signed()); } } unset($buffer); return $result->fetch(); }
/** * Process the user listing * * @param string $data * @param \GameQ\Result $result */ protected function processPlayers($data, Result &$result) { // We need to split the data at the pipe $players = explode('|', $data); // Iterate over the channels foreach ($players as $player) { // Offload the parsing for these values $properties = $this->processProperties($player); // Iterate over the properties foreach ($properties as $key => $value) { $result->addPlayer($key, $value); } } unset($data, $player, $players, $properties, $key, $value); }
/** * Handles processing the the channels and user info * * @param array $data * @param \GameQ\Result $result */ protected function processChannelsAndUsers(array $data, Result &$result) { // Let's add all of the channel information foreach ($data as $key => $value) { // We will handle these later if (in_array($key, ['channels', 'users'])) { // skip continue; } // Add the channel property as a team $result->addTeam($key, $value); } // Itereate over the users in this channel foreach ($data['users'] as $user) { foreach ($user as $key => $value) { $result->addPlayer($key, $value); } } // Offload more channels to parse foreach ($data['channels'] as $channel) { $this->processChannelsAndUsers($channel, $result); } }
/** * Handles processing the player data into a usable format * * @param Buffer $buffer * * @return array */ protected function processPlayers(Buffer $buffer) { // Set the result to a new result instance $result = new Result(); // Get the number of players $result->add('numplayers', $buffer->readInt16()); // Parse players while ($buffer->getLength()) { // Player id if (($id = $buffer->readInt16()) !== 0) { // Add the results $result->addPlayer('id', $id); $result->addPlayer('name', utf8_encode($buffer->readPascalString())); } } unset($buffer, $id); return $result->fetch(); }
/** * Process the players * * @param \GameQ\Buffer $buffer * * @return array */ protected function processPlayers(Buffer $buffer) { // Decode into items $items = $this->decode($buffer); // Set the result to a new result instance $result = new Result(); // Number of data points per player $numTags = $items[1]; // Grab the tags for each player $tags = array_slice($items, 2, $numTags); // Get the player count $playerCount = $items[$numTags + 2]; // Iterate over the index until we run out of players for ($i = 0, $x = $numTags + 3; $i < $playerCount; $i++, $x += $numTags) { // Loop over the player tags and extract the info for that tag foreach ($tags as $index => $tag) { $result->addPlayer($tag, $items[$x + $index]); } } return $result->fetch(); }
/** * Handles processing the player data into a usable format * * @param \GameQ\Buffer $buffer * * @return array */ protected function processPlayers(Buffer $buffer) { // Set the result to a new result instance $result = new Result(); // Number of players $result->add('num_players', $buffer->readInt16()); // Run until we run out of buffer while ($buffer->getLength()) { $result->addPlayer('id', $buffer->readInt8()); $result->addPlayer('name', $buffer->readPascalString()); $result->addPlayer('score', $buffer->readInt32()); $result->addPlayer('ping', $buffer->readInt32()); } unset($buffer); return $result->fetch(); }
/** * Handles processing the player data into a usable format * * @param \GameQ\Buffer $buffer * * @return mixed */ protected function processPlayers(Buffer $buffer) { // Set the result to a new result instance $result = new Result(); // Pull out the number of players $num_players = $buffer->readInt8(); // Player count $result->add('num_players', $num_players); // No players so no need to look any further if ($num_players == 0) { return $result->fetch(); } // Players list while ($buffer->getLength()) { $result->addPlayer('id', $buffer->readInt8()); $result->addPlayer('name', $buffer->readString()); $result->addPlayer('score', $buffer->readInt32Signed()); $result->addPlayer('time', $buffer->readFloat32()); } unset($buffer); return $result->fetch(); }
/** * Process the user listing * * @param string $data * @param \GameQ\Result $result */ protected function processPlayers($data, Result &$result) { // Create a buffer $buffer = new Buffer($data); // The first line holds the column names, data returned is in column/row format $columns = explode("\t", trim($buffer->readString("\n")), 16); // Loop through the rows until we run out of information while ($buffer->getLength()) { // Grab the row, which is a tabbed list of items $row = trim($buffer->readString("\n")); // Explode and merge the data with the columns, then parse $data = array_combine($columns, explode("\t", $row, 16)); foreach ($data as $key => $value) { // Now add the data to the result $result->addPlayer($key, utf8_encode($value)); } } unset($data, $buffer, $row, $columns, $key, $value); }
/** * Handles processing the player and team data into a usable format * * @param \GameQ\Buffer $buffer * @param \GameQ\Result $result */ protected function processPlayersAndTeams(Buffer &$buffer, Result &$result) { // Players and team info while ($buffer->getLength()) { // Get the flags $flags = $buffer->readInt8(); // Get data according to the flags if ($flags & 1) { $result->addPlayer('name', $buffer->readPascalString(1, true)); } if ($flags & 2) { $result->addPlayer('team', $buffer->readPascalString(1, true)); } if ($flags & 4) { $result->addPlayer('skin', $buffer->readPascalString(1, true)); } if ($flags & 8) { $result->addPlayer('score', $buffer->readPascalString(1, true)); } if ($flags & 16) { $result->addPlayer('ping', $buffer->readPascalString(1, true)); } if ($flags & 32) { $result->addPlayer('time', $buffer->readPascalString(1, true)); } } }
/** * Handle processing the status buffer * * @param Buffer $buffer * * @return array */ protected function processStatus(Buffer $buffer) { // Set the result to a new result instance $result = new Result(); // By default dedicted $result->add('dedicated', 1); // Lets peek and see if the data starts with a \ if ($buffer->lookAhead(1) == '\\') { // Burn the first one $buffer->skip(1); } // Explode the data $data = explode('\\', $buffer->getBuffer()); // No longer needed unset($buffer); // Init some vars $numPlayers = 0; $numTeams = 0; $itemCount = count($data); // Now lets loop the array for ($x = 0; $x < $itemCount; $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); $numTeams++; } else { // Its a player if (substr($key, 0, $suffix) == 'playername') { $numPlayers++; } $result->addPlayer(substr($key, 0, $suffix), utf8_encode($val)); } } else { // Regular variable so just add the value. $result->add($key, $val); } } // Add the player and team count $result->add('num_players', $numPlayers); $result->add('num_teams', $numTeams); // Unset some stuff to free up memory unset($data, $key, $val, $suffix, $x, $itemCount); // Return the result return $result->fetch(); }