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\Result; |
23: | |
24: | /** |
25: | * Quake 4 Protocol Class |
26: | * |
27: | * @package GameQ\Protocols |
28: | * |
29: | * @author Wilson Jesus <> |
30: | */ |
31: | class Quake4 extends Doom3 |
32: | { |
33: | /** |
34: | * String name of this protocol class |
35: | * |
36: | * @type string |
37: | */ |
38: | protected $name = 'quake4'; |
39: | |
40: | /** |
41: | * Longer string name of this protocol class |
42: | * |
43: | * @type string |
44: | */ |
45: | protected $name_long = "Quake 4"; |
46: | |
47: | /** |
48: | * Handle processing of player data |
49: | * |
50: | * @param \GameQ\Buffer $buffer |
51: | * |
52: | * @return array |
53: | */ |
54: | protected function processPlayers(Buffer $buffer) |
55: | { |
56: | // Some games do not have a number of current players |
57: | $playerCount = 0; |
58: | |
59: | // Set the result to a new result instance |
60: | $result = new Result(); |
61: | |
62: | // Parse players |
63: | // Loop thru the buffer until we run out of data |
64: | while (($id = $buffer->readInt8()) != 32) { |
65: | // Add player info results |
66: | $result->addPlayer('id', $id); |
67: | $result->addPlayer('ping', $buffer->readInt16()); |
68: | $result->addPlayer('rate', $buffer->readInt32()); |
69: | // Add player name, encoded |
70: | $result->addPlayer('name', utf8_encode(trim($buffer->readString()))); |
71: | $result->addPlayer('clantag', $buffer->readString()); |
72: | // Increment |
73: | $playerCount++; |
74: | } |
75: | |
76: | // Add the number of players to the result |
77: | $result->add('numplayers', $playerCount); |
78: | |
79: | // Clear |
80: | unset($buffer, $playerCount); |
81: | |
82: | return $result->fetch(); |
83: | } |
84: | } |
85: |