2010-07-27 15:14:58 +00:00
< ? php
2012-08-02 00:57:28 +00:00
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke and Tom Reynolds
// The Megaglest Team, under GNU GPL v3.0
// ==============================================================
2010-07-27 15:14:58 +00:00
define ( 'INCLUSION_PERMITTED' , true );
2012-08-06 00:15:32 +00:00
2010-07-27 15:14:58 +00:00
require_once ( 'config.php' );
require_once ( 'functions.php' );
define ( 'DB_LINK' , db_connect () );
2012-08-06 00:15:32 +00:00
// allow for automatic refreshing in web browser by appending '?refresh=VALUE', where VALUE is a numeric value in seconds.
2012-12-15 22:02:10 +00:00
if ( isset ( $_GET [ 'refresh' ] ) ) { define ( 'REFRESH_INTERVAL' , ( int ) $_GET [ 'refresh' ] ); } else { define ( 'REFRESH_INTERVAL' , '' ); }
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// allow for filtering by gameserver version
2012-12-15 22:02:10 +00:00
if ( isset ( $_GET [ 'version' ] ) ) { define ( 'FILTER_VERSION' , $_GET [ 'version' ] ); } else { define ( 'FILTER_VERSION' , '' ); }
2012-08-07 19:19:06 +00:00
2012-12-15 22:02:10 +00:00
if ( isset ( $_GET [ 'mgg_host' ] ) ) { define ( 'MGG_HOST' , $_GET [ 'mgg_host' ] ); } else { define ( 'MGG_HOST' , '' ); }
if ( isset ( $_GET [ 'mgg_port' ] ) ) { define ( 'MGG_PORT' , $_GET [ 'mgg_port' ] ); } else { define ( 'MGG_PORT' , '' ); }
2012-08-10 01:52:16 +00:00
if ( MGG_HOST != '' ) {
$body = MGG_HOST . ':' . MGG_PORT ;
header ( 'Content-Type: application/x-megaglest-gameserver; charset=utf-8' );
header ( 'Content-Disposition: attachment; filename="megaglest_gameserver.mgg' );
header ( 'Content-Length: ' . strlen ( $body ));
header ( 'Accept-Ranges: bytes' );
echo $body ;
exit ;
}
2010-07-27 15:14:58 +00:00
// consider replacing this by a cron job
2011-01-26 19:13:10 +00:00
cleanupServerList ();
2010-07-27 15:14:58 +00:00
2013-11-01 15:42:19 +00:00
$servers_in_db = mysql_query ( '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;' );
2010-07-27 15:14:58 +00:00
$all_servers = array ();
while ( $server = mysql_fetch_array ( $servers_in_db ) )
{
array_push ( $all_servers , $server );
}
unset ( $servers_in_db );
unset ( $server );
db_disconnect ( DB_LINK );
unset ( $linkid );
// Representation starts here
header ( 'Content-Type: text/html; charset=utf-8' );
2012-08-06 00:15:32 +00:00
if ( REFRESH_INTERVAL != 0 ) {
2012-08-07 19:19:06 +00:00
if ( REFRESH_INTERVAL <= 10 ) {
2012-08-10 01:52:16 +00:00
header ( 'Refresh: 10' );
2012-08-07 19:19:06 +00:00
} else {
header ( 'Refresh: ' . REFRESH_INTERVAL );
}
2012-08-06 00:15:32 +00:00
}
2012-08-07 02:31:08 +00:00
echo '<!DOCTYPE HTML>' . PHP_EOL ;
2012-08-06 00:15:32 +00:00
echo '<html>' . PHP_EOL ;
2012-08-07 02:05:28 +00:00
echo ' <head>' . PHP_EOL ;
2012-08-07 02:31:08 +00:00
echo ' <meta charset="UTF-8" />' . PHP_EOL ;
2012-08-07 02:05:28 +00:00
echo ' <title>' . htmlspecialchars ( PRODUCT_NAME ) . ' gameservers</title>' . PHP_EOL ;
echo ' <link rel="stylesheet" type="text/css" href="style/screen.css" />' . PHP_EOL ;
2013-10-13 01:44:27 +00:00
echo ' <link rel="shortcut icon" type="image/x-icon" href="images/' . htmlspecialchars ( strtolower ( PRODUCT_NAME ) ) . '.ico" />' . PHP_EOL ;
2012-08-07 02:05:28 +00:00
echo ' </head>' . PHP_EOL ;
echo ' <body>' . PHP_EOL ;
2013-04-06 17:50:49 +00:00
echo ' <h1><a href="' . htmlspecialchars ( PRODUCT_URL ) . '">' . htmlspecialchars ( PRODUCT_NAME ) . '</a> gameservers</h1>' . PHP_EOL ;
2012-08-07 02:05:28 +00:00
echo ' <table>' . PHP_EOL ;
echo ' <tr>' . PHP_EOL ;
echo ' <th title="glestVersion">Version</th>' . PHP_EOL ;
echo ' <th title="status">Status</th>' . PHP_EOL ;
2013-11-01 15:42:19 +00:00
echo ' <th title="gameDuration">Game Duration</th>' . PHP_EOL ;
2012-08-07 02:05:28 +00:00
echo ' <th title="country">Country</th>' . PHP_EOL ;
echo ' <th title="serverTitle">Title</th>' . PHP_EOL ;
echo ' <th title="tech">Techtree</th>' . PHP_EOL ;
echo ' <th title="connectedClients">Network players</th>' . PHP_EOL ;
echo ' <th title="networkSlots">Network slots</th>' . PHP_EOL ;
echo ' <th title="activeSlots">Total slots</th>' . PHP_EOL ;
echo ' <th title="map">Map</th>' . PHP_EOL ;
echo ' <th title="tileset">Tileset</th>' . PHP_EOL ;
echo ' <th title="ip">IPv4 address</th>' . PHP_EOL ;
echo ' <th title="externalServerPort">Game protocol port</th>' . PHP_EOL ;
echo ' <th title="platform">Platform</th>' . PHP_EOL ;
echo ' <th title="binaryCompileDate">Build date</th>' . PHP_EOL ;
echo ' </tr>' . PHP_EOL ;
2010-07-27 15:14:58 +00:00
2013-10-31 09:49:23 +00:00
$games_with_stats = 0 ;
2010-07-27 15:14:58 +00:00
foreach ( $all_servers as $server )
{
2012-08-07 19:19:06 +00:00
# Filter by version if requested
2013-10-12 23:55:32 +00:00
if ( FILTER_VERSION == $server [ 'glestVersion' ] or FILTER_VERSION == '' )
2012-08-07 19:19:06 +00:00
{
echo " \t \t \t " . '<tr>' . PHP_EOL ;
2011-01-25 07:41:12 +00:00
2012-08-07 19:19:06 +00:00
// glestVersion
2013-04-06 17:50:49 +00:00
printf ( " \t \t \t \t <td><a href= \" ?version=%s \" rel= \" nofollow \" >%s</a></td>%s " , htmlspecialchars ( $server [ 'glestVersion' ], ENT_QUOTES ), htmlspecialchars ( $server [ 'glestVersion' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// status
$status_code = $server [ 'status' ];
if ( $status_code == 0 )
2011-01-25 07:41:12 +00:00
{
2012-08-07 19:19:06 +00:00
$gameFull = ( $server [ 'networkSlots' ] <= $server [ 'connectedClients' ] );
if ( $gameFull == true )
{
$status_code = 1 ;
}
2011-01-25 07:41:12 +00:00
}
2012-08-07 19:19:06 +00:00
switch ( $status_code )
{
case 0 :
$status_title = 'waiting for players' ;
$status_class = 'waiting_for_players' ;
break ;
case 1 :
$status_title = 'game full, pending start' ;
$status_class = 'game_full_pending_start' ;
break ;
case 2 :
$status_title = 'in progress' ;
$status_class = 'in_progress' ;
break ;
case 3 :
$status_title = 'finished' ;
$status_class = 'finished' ;
break ;
default :
$status_title = 'unknown' ;
$status_class = 'unknown' ;
2012-08-06 00:15:32 +00:00
}
2013-10-31 03:34:28 +00:00
2013-10-31 04:00:26 +00:00
if (( $status_code == 2 || $status_code == 3 ) && $server [ 'gameUUID' ] != " " )
2013-10-31 03:34:28 +00:00
{
2013-10-31 09:49:23 +00:00
$games_with_stats ++ ;
printf ( " \t \t \t \t <td title= \" %s \" class= \" %s \" ><a id= \" gameStats_%d \" href= \" # \" gameuuid= \" %s \" >%s</a> " , $server [ 'status' ], $status_class , $games_with_stats , $server [ 'gameUUID' ], htmlspecialchars ( $status_title , ENT_QUOTES ) );
printf ( " </td>%s " , PHP_EOL );
2013-10-31 03:34:28 +00:00
}
else
{
printf ( " \t \t \t \t <td title= \" %s \" class= \" %s \" >%s</td>%s " , $server [ 'status' ], $status_class , htmlspecialchars ( $status_title , ENT_QUOTES ), PHP_EOL );
}
2012-08-07 19:19:06 +00:00
2013-11-01 15:42:19 +00:00
// Game Stats
$gameDuration = $server [ 'framesToCalculatePlaytime' ];
$gameDuration = getTimeString ( $gameDuration );
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $gameDuration , ENT_QUOTES ), PHP_EOL );
2012-08-07 19:19:06 +00:00
// country
if ( $server [ 'country' ] !== '' ) {
$flagfile = 'flags/' . strtolower ( $server [ 'country' ] ) . '.png' ;
if ( file_exists ( $flagfile ) ) {
printf ( " \t \t \t \t <td><img src= \" %s \" title= \" %s \" alt= \" %s country flag \" /></td>%s " , $flagfile , $server [ 'country' ], $server [ 'country' ], PHP_EOL );
} else {
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'country' ], ENT_QUOTES ), PHP_EOL );
}
}
else {
printf ( " \t \t \t \t <td>unknown</td>%s " , PHP_EOL );
}
// serverTitle
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'serverTitle' ], ENT_QUOTES ), PHP_EOL );
// tech
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'tech' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// connectedClients
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'connectedClients' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// networkSlots
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'networkSlots' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// activeSlots
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'activeSlots' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// map
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'map' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// tileset
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'tileset' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// ip
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'ip' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// externalServerPort
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'externalServerPort' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// platform
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'platform' ], ENT_QUOTES ), PHP_EOL );
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
// binaryCompileDate
printf ( " \t \t \t \t <td>%s</td>%s " , htmlspecialchars ( $server [ 'binaryCompileDate' ], ENT_QUOTES ), PHP_EOL );
echo " \t \t \t " . '</tr>' . PHP_EOL ;
2013-10-31 09:49:23 +00:00
if (( $status_code == 2 || $status_code == 3 ) && $server [ 'gameUUID' ] != " " )
{
//echo "\t\t\t" . '<tr>' . PHP_EOL;
printf ( " \t \t \t \t <tr width='100%%' class='fullyhide' id='content_row_%s'>%s " , $server [ 'gameUUID' ], PHP_EOL );
printf ( " <td width='100%%' colspan='100'></td>%s " , PHP_EOL );
echo " \t \t \t " . '</tr>' . PHP_EOL ;
}
2012-08-07 19:19:06 +00:00
}
}
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
echo ' </table>' . PHP_EOL ;
2012-08-06 00:15:32 +00:00
2012-08-07 19:19:06 +00:00
echo ' <p>' . PHP_EOL ;
echo ' <br />' . PHP_EOL ;
echo ' </p>' . PHP_EOL ;
2011-01-25 07:41:12 +00:00
2013-10-31 09:49:23 +00:00
echo ' <script language="javascript" type="text/javascript" src="scripts/utils.js"></script>' . PHP_EOL ;
2012-08-07 19:19:06 +00:00
if ( FILTER_VERSION != '' )
{
echo " \t \t <p>Filters active:</p> " . PHP_EOL ;
echo " \t \t <ul> " . PHP_EOL ;
2013-04-06 17:50:49 +00:00
printf ( " \t \t \t <li>Version <a href= \" ? \" rel= \" nofollow \" >%s</a></li>%s " , htmlspecialchars ( FILTER_VERSION , ENT_QUOTES ), PHP_EOL );
2012-08-07 19:19:06 +00:00
echo " \t \t </ul> " . PHP_EOL ;
2010-07-27 15:14:58 +00:00
}
2012-08-07 19:19:06 +00:00
echo ' <p>Usage:</p>' . PHP_EOL ;
echo ' <ul>' . PHP_EOL ;
2013-04-06 17:50:49 +00:00
echo ' <li>You can have this page auto <a href="?refresh=60" rel="nofollow">refresh every 60 seconds</a> by appending <code>?refresh=60</code> to the URL. Minimum refresh time is 10 seconds.</li>' . PHP_EOL ;
2012-08-07 19:19:06 +00:00
echo ' <li>The parameters used by the masterserver API will display when you move your mouse pointer over any of the table headings.</li>' . PHP_EOL ;
echo ' </ul>' . PHP_EOL ;
2013-10-13 01:44:27 +00:00
echo ' <script src="scripts/json2.js"></script>' . PHP_EOL ;
echo ' <script src="scripts/desktop_notifications.js"></script>' . PHP_EOL ;
2012-08-07 19:19:06 +00:00
echo ' </body>' . PHP_EOL ;
echo '</html>' . PHP_EOL ;
2010-07-27 15:14:58 +00:00
unset ( $all_servers );
unset ( $server );
?>