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
|
|
|
protected function processPlayers(Buffer $buffer) |
47
|
|
|
{ |
48
|
|
|
// Some games do not have a number of current players |
49
|
|
|
$playerCount = 0; |
50
|
|
|
|
51
|
|
|
// Temporarily cache players in order to remove last |
52
|
|
|
$players = []; |
53
|
|
|
|
54
|
|
|
// Loop until we are out of data |
55
|
|
|
while ($buffer->getLength()) { |
56
|
|
|
// Make a new buffer with this block |
57
|
|
|
$playerInfo = new Buffer($buffer->readString("\x0A")); |
58
|
|
|
|
59
|
|
|
// Read player info |
60
|
|
|
$player = [ |
61
|
|
|
'frags' => $playerInfo->readString("\x20"), |
62
|
|
|
'ping' => $playerInfo->readString("\x20"), |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
// Skip first " |
66
|
|
|
$playerInfo->skip(1); |
67
|
|
|
|
68
|
|
|
// Add player name, encoded |
69
|
|
|
$player['name'] = utf8_encode(trim(($playerInfo->readString('"')))); |
70
|
|
|
|
71
|
|
|
// Increment |
72
|
|
|
$playerCount++; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Remove last, empty player |
76
|
|
|
array_pop($players); |
77
|
|
|
|
78
|
|
|
// Set the result to a new result instance |
79
|
|
|
$result = new Result(); |
80
|
|
|
|
81
|
|
|
// Add players |
82
|
|
|
$result->add('players', $players); |
83
|
|
|
|
84
|
|
|
// Add Playercount |
85
|
|
|
$result->add('clients', count($players)); |
86
|
|
|
|
87
|
|
|
// Clear |
88
|
|
|
unset($buffer, $playerCount, $players); |
89
|
|
|
|
90
|
|
|
return $result->fetch(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|