| 1: | <?php | 
| 2: | /** | 
| 3: | * This file is part of GameQ. | 
| 4: | * | 
| 5: | * GameQ is free software; you can redistribute it and/or modify | 
| 6: | * it under the terms of the GNU Lesser General Public License as published by | 
| 7: | * the Free Software Foundation; either version 3 of the License, or | 
| 8: | * (at your option) any later version. | 
| 9: | * | 
| 10: | * GameQ is distributed in the hope that it will be useful, | 
| 11: | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 12: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 13: | * GNU Lesser General Public License for more details. | 
| 14: | * | 
| 15: | * You should have received a copy of the GNU Lesser General Public License | 
| 16: | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 
| 17: | */ | 
| 18: | |
| 19: | namespace GameQ\Protocols; | 
| 20: | |
| 21: | use GameQ\Buffer; | 
| 22: | use GameQ\Helpers\Str; | 
| 23: | use GameQ\Result; | 
| 24: | |
| 25: | /** | 
| 26: | * Quake 4 Protocol Class | 
| 27: | * | 
| 28: | * @package GameQ\Protocols | 
| 29: | * | 
| 30: | * @author Wilson Jesus <> | 
| 31: | */ | 
| 32: | class Quake4 extends Doom3 | 
| 33: | { | 
| 34: | /** | 
| 35: | * String name of this protocol class | 
| 36: | * | 
| 37: | * @var string | 
| 38: | */ | 
| 39: | protected $name = 'quake4'; | 
| 40: | |
| 41: | /** | 
| 42: | * Longer string name of this protocol class | 
| 43: | * | 
| 44: | * @var string | 
| 45: | */ | 
| 46: | protected $name_long = "Quake 4"; | 
| 47: | |
| 48: | /** | 
| 49: | * Handle processing of player data | 
| 50: | * | 
| 51: | * @param \GameQ\Buffer $buffer | 
| 52: | * @return array | 
| 53: | * @throws \GameQ\Exception\Protocol | 
| 54: | */ | 
| 55: | protected function processPlayers(Buffer $buffer) | 
| 56: | { | 
| 57: | // Some games do not have a number of current players | 
| 58: | $playerCount = 0; | 
| 59: | |
| 60: | // Set the result to a new result instance | 
| 61: | $result = new Result(); | 
| 62: | |
| 63: | // Parse players | 
| 64: | // Loop thru the buffer until we run out of data | 
| 65: | while (($id = $buffer->readInt8()) != 32) { | 
| 66: | // Add player info results | 
| 67: | $result->addPlayer('id', $id); | 
| 68: | $result->addPlayer('ping', $buffer->readInt16()); | 
| 69: | $result->addPlayer('rate', $buffer->readInt32()); | 
| 70: | // Add player name, encoded | 
| 71: | $result->addPlayer('name', Str::isoToUtf8(trim($buffer->readString()))); | 
| 72: | $result->addPlayer('clantag', $buffer->readString()); | 
| 73: | // Increment | 
| 74: | $playerCount++; | 
| 75: | } | 
| 76: | |
| 77: | // Add the number of players to the result | 
| 78: | $result->add('numplayers', $playerCount); | 
| 79: | |
| 80: | // Clear | 
| 81: | unset($buffer, $playerCount); | 
| 82: | |
| 83: | return $result->fetch(); | 
| 84: | } | 
| 85: | } | 
| 86: |