1 | <?php |
||
31 | abstract class Unreal2 extends Protocol |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * Array of packets we want to look up. |
||
36 | * Each key should correspond to a defined method in this or a parent class |
||
37 | * |
||
38 | * @type array |
||
39 | */ |
||
40 | protected $packets = [ |
||
41 | self::PACKET_DETAILS => "\x79\x00\x00\x00\x00", |
||
42 | self::PACKET_RULES => "\x79\x00\x00\x00\x01", |
||
43 | self::PACKET_PLAYERS => "\x79\x00\x00\x00\x02", |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * Use the response flag to figure out what method to run |
||
48 | * |
||
49 | * @type array |
||
50 | */ |
||
51 | protected $responses = [ |
||
52 | "\x80\x00\x00\x00\x00" => "processDetails", // 0 |
||
53 | "\x80\x00\x00\x00\x01" => "processRules", // 1 |
||
54 | "\x80\x00\x00\x00\x02" => "processPlayers", // 2 |
||
55 | ]; |
||
56 | |||
57 | /** |
||
58 | * The query protocol used to make the call |
||
59 | * |
||
60 | * @type string |
||
61 | */ |
||
62 | protected $protocol = 'unreal2'; |
||
63 | |||
64 | /** |
||
65 | * String name of this protocol class |
||
66 | * |
||
67 | * @type string |
||
68 | */ |
||
69 | protected $name = 'unreal2'; |
||
70 | |||
71 | /** |
||
72 | * Longer string name of this protocol class |
||
73 | * |
||
74 | * @type string |
||
75 | */ |
||
76 | protected $name_long = "Unreal 2"; |
||
77 | |||
78 | /** |
||
79 | * Normalize settings for this protocol |
||
80 | * |
||
81 | * @type array |
||
82 | */ |
||
83 | protected $normalize = [ |
||
84 | // General |
||
85 | 'general' => [ |
||
86 | // target => source |
||
87 | 'dedicated' => 'ServerMode', |
||
88 | 'gametype' => 'gametype', |
||
89 | 'hostname' => 'servername', |
||
90 | 'mapname' => 'mapname', |
||
91 | 'maxplayers' => 'maxplayers', |
||
92 | 'numplayers' => 'numplayers', |
||
93 | 'password' => 'password', |
||
94 | ], |
||
95 | // Individual |
||
96 | 'player' => [ |
||
97 | 'name' => 'name', |
||
98 | 'score' => 'score', |
||
99 | ], |
||
100 | ]; |
||
101 | |||
102 | /** |
||
103 | * Parse the challenge response and apply it to all the packet types |
||
104 | * |
||
105 | * @param \GameQ\Buffer $challenge_buffer |
||
106 | * |
||
107 | * @return bool |
||
108 | * @throws \GameQ\Exception\Protocol |
||
109 | */ |
||
110 | public function challengeParseAndApply(Buffer $challenge_buffer) |
||
119 | |||
120 | /** |
||
121 | * Process the response |
||
122 | * |
||
123 | * @return array |
||
124 | * @throws \GameQ\Exception\Protocol |
||
125 | */ |
||
126 | 4 | public function processResponse() |
|
165 | |||
166 | /* |
||
167 | * Internal methods |
||
168 | */ |
||
169 | |||
170 | /** |
||
171 | * Handles processing the details data into a usable format |
||
172 | * |
||
173 | * @param \GameQ\Buffer $buffer |
||
174 | * |
||
175 | * @return mixed |
||
176 | * @throws \GameQ\Exception\Protocol |
||
177 | */ |
||
178 | 2 | protected function processDetails(Buffer $buffer) |
|
179 | { |
||
180 | |||
181 | // Set the result to a new result instance |
||
182 | 2 | $result = new Result(); |
|
183 | |||
184 | 2 | $result->add('serverid', $buffer->readInt32()); // 0 |
|
185 | 2 | $result->add('serverip', $buffer->readPascalString(1)); // empty |
|
186 | 2 | $result->add('gameport', $buffer->readInt32()); |
|
187 | 2 | $result->add('queryport', $buffer->readInt32()); // 0 |
|
188 | 2 | $result->add('servername', utf8_encode($buffer->readPascalString(1))); |
|
189 | 2 | $result->add('mapname', utf8_encode($buffer->readPascalString(1))); |
|
190 | 2 | $result->add('gametype', $buffer->readPascalString(1)); |
|
191 | 2 | $result->add('numplayers', $buffer->readInt32()); |
|
192 | 2 | $result->add('maxplayers', $buffer->readInt32()); |
|
193 | 2 | $result->add('ping', $buffer->readInt32()); // 0 |
|
194 | |||
195 | 2 | unset($buffer); |
|
196 | |||
197 | 2 | return $result->fetch(); |
|
198 | } |
||
199 | |||
200 | /** |
||
201 | * Handles processing the player data into a usable format |
||
202 | * |
||
203 | * @param \GameQ\Buffer $buffer |
||
204 | * |
||
205 | * @return mixed |
||
206 | */ |
||
207 | 4 | protected function processPlayers(Buffer $buffer) |
|
233 | |||
234 | /** |
||
235 | * Handles processing the rules data into a usable format |
||
236 | * |
||
237 | * @param \GameQ\Buffer $buffer |
||
238 | * |
||
239 | * @return mixed |
||
240 | */ |
||
241 | 4 | protected function processRules(Buffer $buffer) |
|
265 | } |
||
266 |