slightly improved HTML server list

This commit is contained in:
Tom Reynolds 2012-08-06 00:15:32 +00:00
parent 93db1912e8
commit 74f2b25752
2 changed files with 124 additions and 85 deletions

View File

@ -5,16 +5,21 @@
if ( !defined('INCLUSION_PERMITTED') || ( defined('INCLUSION_PERMITTED') && INCLUSION_PERMITTED !== true ) ) { die( 'This file must not be invoked directly.' ); } if ( !defined('INCLUSION_PERMITTED') || ( defined('INCLUSION_PERMITTED') && INCLUSION_PERMITTED !== true ) ) { die( 'This file must not be invoked directly.' ); }
define( 'PRODUCT_NAME', 'MegaGlest' );
define( 'MYSQL_HOST', '127.0.0.1' ); define( 'MYSQL_HOST', '127.0.0.1' );
define( 'MYSQL_DATABASE', 'glest' ); define( 'MYSQL_DATABASE', 'glest' );
define( 'MYSQL_USER', 'root' ); define( 'MYSQL_USER', 'root' );
define( 'MYSQL_PASSWORD', 'your_pwd' ); define( 'MYSQL_PASSWORD', 'your_pwd' );
// Allow using persistent MYSQL database server connections // Allow using persistent MYSQL database server connections
// This _can_ improve performance remarkably but _can_ also break stuff completely, so read up: // This _can_ improve performance remarkably but _can_ also break stuff completely, so read up:
// http://php.net/manual/function.mysql-pconnect.php // http://php.net/manual/function.mysql-pconnect.php
// http://php.net/manual/features.persistent-connections.php // http://php.net/manual/features.persistent-connections.php
define( 'MYSQL_LINK_PERSIST', false ); define( 'MYSQL_LINK_PERSIST', false );
// How many recently seen servers to store // How many recently seen servers to store
define( 'MAX_RECENT_SERVERS', 5 ); define( 'MAX_RECENT_SERVERS', 5 );
define( 'DEFAULT_COUNTRY', '?' );
define( 'DEFAULT_COUNTRY', '??' );
?> ?>

View File

@ -4,11 +4,14 @@
// ============================================================== // ==============================================================
define( 'INCLUSION_PERMITTED', true ); define( 'INCLUSION_PERMITTED', true );
require_once( 'config.php' ); require_once( 'config.php' );
require_once( 'functions.php' ); require_once( 'functions.php' );
define( 'DB_LINK', db_connect() ); define( 'DB_LINK', db_connect() );
// allow for automatic refreshing in web browser by appending '?refresh=VALUE', where VALUE is a numeric value in seconds.
define( 'REFRESH_INTERVAL', (int) $_GET['refresh'] );
// consider replacing this by a cron job // consider replacing this by a cron job
cleanupServerList(); cleanupServerList();
@ -26,103 +29,134 @@
// Representation starts here // Representation starts here
header( 'Content-Type: text/html; charset=utf-8' ); header( 'Content-Type: text/html; charset=utf-8' );
echo <<<END if ( REFRESH_INTERVAL != 0 ) {
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> header( 'Refresh: ' . REFRESH_INTERVAL );
<html> }
<head> echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' . PHP_EOL;
<title>MegaGlest gameservers</title> echo '<html>' . PHP_EOL;
<style type="text/css"> echo '<head>' . PHP_EOL;
body { echo ' <title>' . htmlspecialchars( PRODUCT_NAME ) . ' gameservers</title>' . PHP_EOL;
} echo ' <style type="text/css">' . PHP_EOL;
echo ' body {' . PHP_EOL;
table { echo ' }' . PHP_EOL;
width: 100%; echo '' . PHP_EOL;
border: 2px solid black; echo ' table {' . PHP_EOL;
} echo ' width: 100%;' . PHP_EOL;
echo ' border: 2px solid black;' . PHP_EOL;
th, td { echo ' }' . PHP_EOL;
width: 300; echo '' . PHP_EOL;
border: 1px solid black; echo ' th, td { ' . PHP_EOL;
text-align: left; echo ' width: 300;' . PHP_EOL;
} echo ' border: 1px solid black;' . PHP_EOL;
</style> echo ' text-align: left;' . PHP_EOL;
</head> echo ' }' . PHP_EOL;
<body> echo ' </style>' . PHP_EOL;
<table> echo '</head>' . PHP_EOL;
<tr> echo '<body>' . PHP_EOL;
<th>glestVersion</th> echo ' <table>' . PHP_EOL;
<th>platform</th> echo ' <tr>' . PHP_EOL;
<th>binaryCompileDate</th> echo ' <th title="glestVersion">Version</th>' . PHP_EOL;
<th>serverTitle</th> echo ' <th title="status">Status</th>' . PHP_EOL;
<th>ip</th> echo ' <th title="country">Country</th>' . PHP_EOL;
<th>tech</th> echo ' <th title="serverTitle">Title</th>' . PHP_EOL;
<th>map</th> echo ' <th title="tech">Techtree</th>' . PHP_EOL;
<th>tileset</th> echo ' <th title="connectedClients">Network players</th>' . PHP_EOL;
<th>activeSlots</th> echo ' <th title="networkSlots">Network slots</th>' . PHP_EOL;
<th>networkSlots</th> echo ' <th title="activeSlots">Total slots</th>' . PHP_EOL;
<th>connectedClients</th> echo ' <th title="map">Map</th>' . PHP_EOL;
<th>externalServerPort</th> echo ' <th title="tileset">Tileset</th>' . PHP_EOL;
<th>country</th> echo ' <th title="ip">IPv4 address</th>' . PHP_EOL;
<th>status</th> echo ' <th title="externalServerPort">Game protocol port</th>' . PHP_EOL;
</tr> echo ' <th title="platform">Platform</th>' . PHP_EOL;
echo ' <th title="binaryCompileDate">Build date</th>' . PHP_EOL;
END; echo ' </tr>' . PHP_EOL;
foreach( $all_servers as $server ) foreach( $all_servers as $server )
{ {
//array_walk( $server, 'htmlspecialchars', 'ENT_QUOTES' );
echo "\t\t\t" . '<tr>' . PHP_EOL; echo "\t\t\t" . '<tr>' . PHP_EOL;
echo "\t\t\t\t<td>" . htmlspecialchars( $server['glestVersion'], ENT_QUOTES ) . '</td>' . PHP_EOL;
echo "\t\t\t\t<td>" . htmlspecialchars( $server['platform'], ENT_QUOTES ) . '</td>' . PHP_EOL; // glestVersion
echo "\t\t\t\t<td>" . htmlspecialchars( $server['binaryCompileDate'], ENT_QUOTES ) . '</td>' . PHP_EOL; printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['glestVersion'], ENT_QUOTES ), PHP_EOL );
echo "\t\t\t\t<td>" . htmlspecialchars( $server['serverTitle'], ENT_QUOTES ) . '</td>' . PHP_EOL;
echo "\t\t\t\t<td>" . htmlspecialchars( $server['ip'], ENT_QUOTES ) . '</td>' . PHP_EOL; // status
echo "\t\t\t\t<td>" . htmlspecialchars( $server['tech'], ENT_QUOTES ) . '</td>' . PHP_EOL; $status_code = $server['status'];
echo "\t\t\t\t<td>" . htmlspecialchars( $server['map'], ENT_QUOTES ) . '</td>' . PHP_EOL; if ( $status_code == 0)
echo "\t\t\t\t<td>" . htmlspecialchars( $server['tileset'], ENT_QUOTES ) . '</td>' . PHP_EOL; {
echo "\t\t\t\t<td>" . htmlspecialchars( $server['activeSlots'], ENT_QUOTES ) . '</td>' . PHP_EOL; $gameFull = ( $server['networkSlots'] <= $server['connectedClients'] );
echo "\t\t\t\t<td>" . htmlspecialchars( $server['networkSlots'], ENT_QUOTES ) . '</td>' . PHP_EOL; if ( $gameFull == true )
echo "\t\t\t\t<td>" . htmlspecialchars( $server['connectedClients'], ENT_QUOTES ) . '</td>' . PHP_EOL; {
echo "\t\t\t\t<td>" . htmlspecialchars( $server['externalServerPort'], ENT_QUOTES ) . '</td>' . PHP_EOL; $status_code = 1;
}
}
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';
}
printf( "\t\t\t\t<td class=\"%s\">%s</td>%s", $status_class, htmlspecialchars( $status_title, ENT_QUOTES ), PHP_EOL );
// country
if ( $server['country'] !== '' ) { if ( $server['country'] !== '' ) {
$flagfile = 'flags/' . strtolower( $server['country'] ).'.png'; $flagfile = 'flags/' . strtolower( $server['country'] ).'.png';
if ( file_exists( $flagfile ) ) { if ( file_exists( $flagfile ) ) {
echo "\t\t\t\t<td>" . '<img src="' . $flagfile . '" title="' . $server['country'] . '" alt="' . $server['country'] . ' country flag" />' . '</td>' . PHP_EOL; printf( "\t\t\t\t<td><img src=\"%s\" title=\"%s\" alt=\"%s country flag\" /></td>", $flagfile, $server['country'], $server['country'], PHP_EOL );
} else { } else {
echo "\t\t\t\t<td>" . 'unknown' . '</td>' . PHP_EOL; printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['country'], ENT_QUOTES ), PHP_EOL );
} }
} }
else { else {
echo "\t\t\t\t<td>" . htmlspecialchars( $server['country'], ENT_QUOTES ) . '</td>' . PHP_EOL; printf( "\t\t\t\t<td>unknown</td>%s", PHP_EOL );
} }
$calculatedStatus = $server['status']; // serverTitle
if($calculatedStatus == 0) printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['serverTitle'], ENT_QUOTES ), PHP_EOL );
{
$gameFull = ($server['networkSlots'] <= $server['connectedClients']);
if($gameFull == true)
{
$calculatedStatus = 1;
}
}
switch($calculatedStatus) // tech
{ printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['tech'], ENT_QUOTES ), PHP_EOL );
case 0:
echo "\t\t\t\t<td>" . htmlspecialchars( "waiting for players", ENT_QUOTES ) . '</td>' . PHP_EOL; // connectedClients
break; printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['connectedClients'], ENT_QUOTES ), PHP_EOL );
case 1:
echo "\t\t\t\t<td>" . htmlspecialchars( "game full, pending start", ENT_QUOTES ) . '</td>' . PHP_EOL; // networkSlots
break; printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['networkSlots'], ENT_QUOTES ), PHP_EOL );
case 2:
echo "\t\t\t\t<td>" . htmlspecialchars( "in progress", ENT_QUOTES ) . '</td>' . PHP_EOL; // activeSlots
break; printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['activeSlots'], ENT_QUOTES ), PHP_EOL );
case 3:
echo "\t\t\t\t<td>" . htmlspecialchars( "finished", ENT_QUOTES ) . '</td>' . PHP_EOL; // map
break; printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['map'], ENT_QUOTES ), PHP_EOL );
default:
echo "\t\t\t\t<td>" . htmlspecialchars( "unknown: " . $server['status'], ENT_QUOTES ) . '</td>' . PHP_EOL; // tileset
} printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['tileset'], ENT_QUOTES ), PHP_EOL );
// ip
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['ip'], ENT_QUOTES ), PHP_EOL );
// externalServerPort
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['externalServerPort'], ENT_QUOTES ), PHP_EOL );
// platform
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['platform'], ENT_QUOTES ), PHP_EOL );
// binaryCompileDate
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $server['binaryCompileDate'], ENT_QUOTES ), PHP_EOL );
echo "\t\t\t" . '</tr>' . PHP_EOL; echo "\t\t\t" . '</tr>' . PHP_EOL;
} }