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: | * Warsow Protocol Class |
27: | * |
28: | * @package GameQ\Protocols |
29: | * @author Austin Bischoff <austin@codebeard.com> |
30: | */ |
31: | class Warsow extends Quake3 |
32: | { |
33: | /** |
34: | * String name of this protocol class |
35: | * |
36: | * @var string |
37: | */ |
38: | protected $name = 'warsow'; |
39: | |
40: | /** |
41: | * Longer string name of this protocol class |
42: | * |
43: | * @var string |
44: | */ |
45: | protected $name_long = "Warsow"; |
46: | |
47: | /** |
48: | * The client join link |
49: | * |
50: | * @var string |
51: | */ |
52: | protected $join_link = "warsow://%s:%d/"; |
53: | |
54: | /** |
55: | * Handle player info, different than quake3 base |
56: | * |
57: | * @param Buffer $buffer |
58: | * @return array |
59: | * @throws \GameQ\Exception\Protocol |
60: | */ |
61: | protected function processPlayers(Buffer $buffer) |
62: | { |
63: | // Set the result to a new result instance |
64: | $result = new Result(); |
65: | |
66: | // Loop until we are out of data |
67: | while ($buffer->getLength()) { |
68: | // Make a new buffer with this block |
69: | $playerInfo = new Buffer($buffer->readString("\x0A")); |
70: | |
71: | // Add player info |
72: | $result->addPlayer('frags', $playerInfo->readString("\x20")); |
73: | $result->addPlayer('ping', $playerInfo->readString("\x20")); |
74: | |
75: | // Skip first " |
76: | $playerInfo->skip(1); |
77: | |
78: | // Add player name, encoded |
79: | $result->addPlayer('name', Str::isoToUtf8(trim(($playerInfo->readString('"'))))); |
80: | |
81: | // Skip space |
82: | $playerInfo->skip(1); |
83: | |
84: | // Add team |
85: | $result->addPlayer('team', $playerInfo->read()); |
86: | |
87: | // Clear |
88: | unset($playerInfo); |
89: | } |
90: | |
91: | // Clear |
92: | unset($buffer); |
93: | |
94: | return $result->fetch(); |
95: | } |
96: | } |
97: |