forked from Ingimarsson/status.minecraft.is
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery
executable file
·83 lines (63 loc) · 2.29 KB
/
query
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
#!/usr/bin/env php
<?php
$include_path = "/home/binni/minecraft.is/";
set_include_path(get_include_path().PATH_SEPARATOR.$include_path);
require("lib/MinecraftQuery.class.php");
require("src/database.class.php");
require("src/log.class.php");
require("config.php");
$log = new log($include_path."query.log");
$log->write("Minequery cron script initiated.");
$mysql = new database(
sprintf('mysql:host=%s;dbname=%s',
$config['mysql']['host'],
$config['mysql']['dbname']
),
$config['mysql']['username'],
$config['mysql']['password'],
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$minecraft = new MinecraftQuery();
$servers = $mysql->fetchall("SELECT id, ip, port FROM minequery_servers;");
foreach($servers as $server){
try {
$minecraft->Connect($server['ip'], $server['port']);
} catch(Exception $e) {
$log->write("MinecraftQuery returned exception for server ".$server['ip']);
continue;
}
$info = $minecraft->GetInfo();
$players = $minecraft->GetPlayers();
$mysql->execute("INSERT INTO minequery(server_id, server_motd, server_version, server_players, server_max_players, server_gamemode, server_software) VALUES(?, ?, ?, ?, ?, ?, ?);",
array(
$server['id'],
utf8_encode($info['HostName']),
$info['Version'],
$info['Players'],
$info['MaxPlayers'],
$info['GameType'],
$info['Software']
)
);
$status_id = $mysql->fetch("SELECT id FROM minequery WHERE server_id=? ORDER BY date DESC LIMIT 1;", array($server['id']))['id'];
foreach($players as $player){
$mysql->execute("INSERT INTO minequery_players(server_id, server_status_id, player) VALUES(?, ?, ?);",
array(
$server['id'],
$status_id,
$player
)
);
}
foreach($info['Plugins'] as $plugin){
$mysql->execute("INSERT INTO minequery_plugins(server_id, server_status_id, plugin) VALUES(?, ?, ?);",
array(
$server['id'],
$status_id,
$plugin
)
);
}
$log->write("Logging successful for server ".$server['ip']);
}
$log->write("Minequery cron script finished");
?>