-
Notifications
You must be signed in to change notification settings - Fork 0
/
arbitterHelper.php
73 lines (67 loc) · 2.07 KB
/
arbitterHelper.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
<?php
// this is used to delete dead gameservers.
include_once "./config/config.php";
try {
$pdo = new PDO(
"mysql:host=" . config['database']['host'] . ";dbname=" . config['database']['database'],
config['database']['user'],
config['database']['password'],
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
} catch (PDOException) {
header('Content-Type: application/json');
exit(json_encode(['error' => "true", "message" => "Database Error. Please Contact Administrator"])); //$e->getMessage()
}
function isPortInUse(int $Port) : bool
{
exec('netstat -a -n -o | find "' . $Port . '"', $output);
if (empty($output))
{
return false;
} else {
return true;
}
}
function killRcc(int $port)
{
exec('wmic process where name=\'RCCService.exe\' get processid, commandline', $output);
$args = '-console ' . $port;
foreach ($output as $arrayLn)
{
if (preg_match('/(\d+)$/', $arrayLn, $matches)) {
if (strpos($arrayLn, $args) !== false)
{
$pid = $matches[1];
exec("taskkill /PID $pid /F");
}
}
}
}
while (true)
{
echo "[Main] Checking For Servers\n";
$stmt = $pdo->prepare('SELECT * FROM `jobs`');
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rowCount = $stmt->rowCount();
if ($rowCount > 0)
{
echo "[Job Checker] " . $rowCount . " Servers Found\n";
foreach ($rows as $row)
{
if (!isPortInUse($row["port"]))
{
Sleep(4);
$port = $row["port"];
killRcc($port);
$stmt = $pdo->prepare('DELETE FROM `jobs` WHERE `port` = :port');
$stmt->bindParam(":port", $port, PDO::PARAM_INT);
$stmt->execute();
echo "[Job Deleter] Deleted 1 Broken Server(s)\n";
}
}
} else {
echo "[Job Checker] No Running Servers Found\n";
}
Sleep(5);
}