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.funcs.php
executable file
·79 lines (64 loc) · 1.56 KB
/
whitelist.funcs.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
<?php
$numPlayersKickedURL = 'numPlayersKicked';
function getServerJSON($jsonURL)
{
if (file_exists($jsonURL))
return json_decode(file_get_contents($jsonURL));
else die("$jsonURL missing");
}
function getServerInfo($jsonURL, $string)
{
$jsonData = getServerJSON($jsonURL);
foreach ($jsonData as $key => $object) {
if ($object->abbv == $string) {
return $object;
}
}
return False;
}
function getWhitelist($whitelistURL)
{
$whitelistString = trim(file_get_contents($whitelistURL));
return preg_split('/\s+/s', $whitelistString);
}
function getNumPlayersKicked()
{
global $numPlayersKickedURL;
if (!file_exists($numPlayersKickedURL)) {
return 0;
} else {
return intval(file_get_contents($numPlayersKickedURL));
}
}
function setNumPlayersKicked($number)
{
global $numPlayersKickedURL;
touch($numPlayersKickedURL);
file_put_contents($numPlayersKickedURL, $number);
}
function whitelistKick_set_lastrun($serverAbbv)
{
$filename = "whitelistKick_$serverAbbv";
touch($filename);
file_put_contents($filename, time());
}
function whitelistKick_get_lastrun($serverAbbv)
{
$filename = "whitelistKick_$serverAbbv";
if (!file_exists($filename)) {
return False;
} else return file_get_contents($filename);
}
function whitelistKick_init($serverAbbv, $cooldownSeconds)
{
/* Sufficient time has passed, continue */
$oldTime = intval(whitelistKick_get_lastrun($serverAbbv));
if ((time() - $oldTime) > $cooldownSeconds)
{
whitelistKick_set_lastrun($serverAbbv);
return True;
}
/* We're only allowed to run once in a while */
else return False;
}
?>