-
Notifications
You must be signed in to change notification settings - Fork 6
/
ServerinfoFactory.php
60 lines (51 loc) · 1.6 KB
/
ServerinfoFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Promod\CoDQuery;
class ServerinfoFactory
{
private function __construct(){}
public static function generateInfo($infoResponse, $statusResponse)
{
if(!ServerinfoFactory::startsWith($statusResponse, str_repeat(chr(255), 4).'statusResponse'))
{
return;
}
if(!ServerinfoFactory::startsWith($infoResponse, str_repeat(chr(255), 4).'infoResponse'))
{
return;
}
$players = explode("\n", $statusResponse);
$longInfo = explode('\\', $players[1]);
$players = array_slice($players, 2, count($players)-3);
$shortInfo = explode('\\', $infoResponse);
$data = [];
for($i=1,$cnt=count($longInfo);$i<$cnt;++$i)
{
$data[$longInfo[$i]] = $longInfo[++$i];
}
$longInfo = $data;
$data = [];
for($i=1,$cnt=count($shortInfo);$i<$cnt;++$i)
{
$data[$shortInfo[$i]] = $shortInfo[++$i];
}
$shortInfo = $data;
switch($longInfo['gamename'])
{
case 'Call of Duty':
case 'CoD:United Offensive':
case 'Call of Duty 2':
case 'Call of Duty 4':
case 'Call of Duty: World at War':
var_dump($shortInfo);
var_dump($longInfo);
var_dump($players);
return TRUE;
default:
die("Unknown game: ".$longInfo['gamename']);
}
}
private static function startsWith($haystack, $needle)
{
return substr($haystack, 0, strlen($needle)) === $needle;
}
}