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
|
|
|
* Call of Duty: Modern Warfare 2 Protocol Class |
26
|
|
|
* |
27
|
|
|
* @package GameQ\Protocols |
28
|
|
|
* @author Wilson Jesus <> |
29
|
|
|
*/ |
30
|
|
|
class Codmw2 extends Quake3 |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* String name of this protocol class |
34
|
|
|
* |
35
|
|
|
* @type string |
36
|
|
|
*/ |
37
|
|
|
protected $name = 'codmw2'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Longer string name of this protocol class |
41
|
|
|
* |
42
|
|
|
* @type string |
43
|
|
|
*/ |
44
|
|
|
protected $name_long = "Call of Duty: Modern Warfare 2"; |
45
|
|
|
|
46
|
18 |
|
protected function processPlayers(Buffer $buffer) |
47
|
|
|
{ |
48
|
|
|
// Temporarily cache players in order to remove last |
49
|
18 |
|
$players = []; |
50
|
|
|
|
51
|
|
|
// Loop until we are out of data |
52
|
18 |
|
while ($buffer->getLength()) { |
53
|
|
|
// Make a new buffer with this block |
54
|
18 |
|
$playerInfo = new Buffer($buffer->readString("\x0A")); |
55
|
|
|
|
56
|
|
|
// Read player info |
57
|
9 |
|
$player = [ |
58
|
18 |
|
'frags' => $playerInfo->readString("\x20"), |
59
|
18 |
|
'ping' => $playerInfo->readString("\x20"), |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
// Skip first " |
63
|
18 |
|
$playerInfo->skip(1); |
64
|
|
|
|
65
|
|
|
// Add player name, encoded |
66
|
18 |
|
$player['name'] = utf8_encode(trim(($playerInfo->readString('"')))); |
67
|
|
|
|
68
|
|
|
// Add player |
69
|
18 |
|
$players[] = $player; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// Remove last, empty player |
73
|
18 |
|
array_pop($players); |
74
|
|
|
|
75
|
|
|
// Set the result to a new result instance |
76
|
18 |
|
$result = new Result(); |
77
|
|
|
|
78
|
|
|
// Add players |
79
|
18 |
|
$result->add('players', $players); |
80
|
|
|
|
81
|
|
|
// Add Playercount |
82
|
18 |
|
$result->add('clients', count($players)); |
83
|
|
|
|
84
|
|
|
// Clear |
85
|
18 |
|
unset($buffer, $players); |
86
|
|
|
|
87
|
18 |
|
return $result->fetch(); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|