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
|
|
|
* Unreal Tournament 3 Protocol Class |
26
|
|
|
* |
27
|
|
|
* Note: The response from UT3 appears to not be consistent. Many times packets are incomplete or there are extra |
28
|
|
|
* "echoes" in the responses. This may cause issues like odd characters showing up in the keys for the player and team |
29
|
|
|
* array responses. Not sure much can be done about it. |
30
|
|
|
* |
31
|
|
|
* @author Austin Bischoff <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
class Ut3 extends Gamespy3 |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* String name of this protocol class |
38
|
|
|
* |
39
|
|
|
* @type string |
40
|
|
|
*/ |
41
|
|
|
protected $name = 'ut3'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Longer string name of this protocol class |
45
|
|
|
* |
46
|
|
|
* @type string |
47
|
|
|
*/ |
48
|
|
|
protected $name_long = "Unreal Tournament 3"; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Normalize settings for this protocol |
52
|
|
|
* |
53
|
|
|
* @type array |
54
|
|
|
*/ |
55
|
|
|
protected $normalize = [ |
56
|
|
|
// General |
57
|
|
|
'general' => [ |
58
|
|
|
'dedicated' => 'bIsDedicated', |
59
|
|
|
'hostname' => 'hostname', |
60
|
|
|
'numplayers' => 'numplayers', |
61
|
|
|
], |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Overload the response process so we can make some changes |
66
|
|
|
* |
67
|
|
|
* @return \GameQ\Result |
|
|
|
|
68
|
|
|
*/ |
69
|
1 |
|
public function processResponse() |
70
|
|
|
{ |
71
|
|
|
|
72
|
|
|
// Grab the result from the parent |
73
|
|
|
/** @type \GameQ\Result $result */ |
74
|
1 |
|
$result = parent::processResponse(); |
75
|
|
|
|
76
|
|
|
// Move some stuff around |
77
|
1 |
|
$this->renameResult($result, 'OwningPlayerName', 'hostname'); |
|
|
|
|
78
|
1 |
|
$this->renameResult($result, 'p1073741825', 'mapname'); |
79
|
1 |
|
$this->renameResult($result, 'p1073741826', 'gametype'); |
80
|
1 |
|
$this->renameResult($result, 'p1073741827', 'servername'); |
81
|
1 |
|
$this->renameResult($result, 'p1073741828', 'custom_mutators'); |
82
|
1 |
|
$this->renameResult($result, 'gamemode', 'open'); |
83
|
1 |
|
$this->renameResult($result, 's32779', 'gamemode'); |
84
|
1 |
|
$this->renameResult($result, 's0', 'bot_skill'); |
85
|
1 |
|
$this->renameResult($result, 's6', 'pure_server'); |
86
|
1 |
|
$this->renameResult($result, 's7', 'password'); |
87
|
1 |
|
$this->renameResult($result, 's8', 'vs_bots'); |
88
|
1 |
|
$this->renameResult($result, 's10', 'force_respawn'); |
89
|
1 |
|
$this->renameResult($result, 'p268435704', 'frag_limit'); |
90
|
1 |
|
$this->renameResult($result, 'p268435705', 'time_limit'); |
91
|
1 |
|
$this->renameResult($result, 'p268435703', 'numbots'); |
92
|
1 |
|
$this->renameResult($result, 'p268435717', 'stock_mutators'); |
93
|
|
|
|
94
|
|
|
// Put custom mutators into an array |
95
|
1 |
|
if (isset($result['custom_mutators'])) { |
96
|
1 |
|
$result['custom_mutators'] = explode("\x1c", $result['custom_mutators']); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// Delete some unknown stuff |
100
|
1 |
|
$this->deleteResult($result, [ 's1', 's9', 's11', 's12', 's13', 's14' ]); |
101
|
|
|
|
102
|
|
|
// Return the result |
103
|
1 |
|
return $result; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Dirty hack to rename result entries into something more useful |
108
|
|
|
* |
109
|
|
|
* @param array $result |
110
|
|
|
* @param string $old |
111
|
|
|
* @param string $new |
112
|
|
|
*/ |
113
|
1 |
|
protected function renameResult(array &$result, $old, $new) |
114
|
|
|
{ |
115
|
|
|
|
116
|
|
|
// Check to see if the old item is there |
117
|
1 |
|
if (isset($result[$old])) { |
118
|
1 |
|
$result[$new] = $result[$old]; |
119
|
1 |
|
unset($result[$old]); |
120
|
|
|
} |
121
|
1 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Dirty hack to delete result items |
125
|
|
|
* |
126
|
|
|
* @param array $result |
127
|
|
|
* @param array $array |
128
|
|
|
*/ |
129
|
1 |
|
protected function deleteResult(array &$result, array $array) |
130
|
|
|
{ |
131
|
|
|
|
132
|
1 |
|
foreach ($array as $key) { |
133
|
1 |
|
unset($result[$key]); |
134
|
|
|
} |
135
|
1 |
|
} |
136
|
|
|
} |
137
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.