This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
whitelist-stats.php
92 lines (67 loc) · 2.07 KB
/
whitelist-stats.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
$jsonFile = 'servers.json';
$whitelistURL = 'http://example.com/whitelist';
require 'whitelist.funcs.php';
require 'rcon.funcs.php';
// Get server counts
$jsonData = getServerJSON($jsonFile);
$totalServers = 0;
$totalPlayerSlots = 0;
foreach ($jsonData as $key => $server) {
if ($server->enabled === False) {
continue;
}
$totalServers++;
$clientSequenceNr = 0;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, $server->ip, $server->port);
socket_set_nonblock($socket);
if ($socket === False) {
echo "$server->name: could not open socket. Skipped.\n";
continue;
}
if ($socket !== False) {
$response = rconCommand($socket, 'login.hashed');
if ($response[0] != 'OK') {
echo "$server->name: could not login. Skipped.\n";
socket_close($socket);
continue;
}
$response = rconCommand($socket, 'login.hashed ' . generatePasswordHash($response[1], $server->password));
switch ($response[0]) {
case 'OK':
break;
case 'PasswordNotSet':
echo "$server->name: password not set on server. Skipped.\n";
socket_close($socket);
continue 2;
break;
case 'InvalidArguments':
echo "$server->name: on login: InvalidArguments. Skipped.\n";
socket_close($socket);
continue 2;
break;
default:
echo "$server->name: on login: unexpected output. Skipped.\n";
socket_close($socket);
continue 2;
break;
}
// Get max players of server
$response = rconCommand($socket, 'vars.maxPlayers');
if ($response[0] != 'OK') {
echo "$server->name: on maxPlayers: server error. Skipped.\n";
socket_close($socket);
continue;
}
$totalPlayerSlots += intval($response[1]);
rconCommand($socket, 'logout');
}
socket_close($socket);
}
// Whitelist count
$totalWhitelisted = count(getWhitelist($whitelistURL));
// Non-whitelisted players kicked count
$totalPlayersKicked = getNumPubbiesKicked();
echo "There are $totalWhitelisted whitelisted, $totalPlayerSlots slots on $totalServers servers, and $totalPlayersKicked non-whitelisted players kicked.\n";
?>