-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathshowServersJson.php
38 lines (29 loc) · 1.34 KB
/
showServersJson.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
<?php
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke and Tom Reynolds
// The MegaGlest Team, under GNU GPL v3.0
// ==============================================================
define( 'INCLUSION_PERMITTED', true );
require_once( 'registry.php' );
require_once( 'config.php' );
require_once( 'functions.php' );
define( 'DB_LINK', db_connect() );
// consider replacing this by a cron job
cleanupServerList();
$servers_in_db = mysqli_query( Registry::$mysqliLink, 'SELECT a.*,b.framesToCalculatePlaytime FROM glestserver a LEFT JOIN glestgamestats b ON a.gameUUID = b.gameUUID WHERE status <> 3 OR (status = 3 AND a.lasttime > DATE_add(NOW(), INTERVAL - ' . MAX_HOURS_OLD_GAMES . ' hour)) ORDER BY status, a.lasttime DESC, connectedClients > 0 DESC, (networkSlots - connectedClients), ip DESC;' );
$all_servers = array();
while ( $server = mysqli_fetch_array( $servers_in_db ) )
{
// Game Stats
$rowIndex = count($all_servers);
$gameDuration = $server["framesToCalculatePlaytime"];
$server["gameDuration"] = getTimeString($gameDuration);
array_push( $all_servers, $server );
}
unset( $servers_in_db );
unset( $server );
db_disconnect( Registry::$mysqliLink );
unset( $linkid );
header('Content-type: application/json');
echo json_encode($all_servers);
unset( $all_servers );
?>