From 74f2b257520e785f84febffd3c61ebcc9224392c Mon Sep 17 00:00:00 2001 From: Tom Reynolds Date: Mon, 6 Aug 2012 00:15:32 +0000 Subject: [PATCH] slightly improved HTML server list --- source/masterserver/config.php | 7 +- source/masterserver/showServers.php | 202 ++++++++++++++++------------ 2 files changed, 124 insertions(+), 85 deletions(-) diff --git a/source/masterserver/config.php b/source/masterserver/config.php index bf73de03..1971cf5c 100644 --- a/source/masterserver/config.php +++ b/source/masterserver/config.php @@ -5,16 +5,21 @@ 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_DATABASE', 'glest' ); define( 'MYSQL_USER', 'root' ); define( 'MYSQL_PASSWORD', 'your_pwd' ); + // Allow using persistent MYSQL database server connections // 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/features.persistent-connections.php define( 'MYSQL_LINK_PERSIST', false ); + // How many recently seen servers to store define( 'MAX_RECENT_SERVERS', 5 ); - define( 'DEFAULT_COUNTRY', '?' ); + + define( 'DEFAULT_COUNTRY', '??' ); ?> diff --git a/source/masterserver/showServers.php b/source/masterserver/showServers.php index 09dd3e3a..ed312bdf 100644 --- a/source/masterserver/showServers.php +++ b/source/masterserver/showServers.php @@ -4,11 +4,14 @@ // ============================================================== define( 'INCLUSION_PERMITTED', true ); + require_once( 'config.php' ); require_once( 'functions.php' ); - 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 cleanupServerList(); @@ -26,103 +29,134 @@ // Representation starts here header( 'Content-Type: text/html; charset=utf-8' ); -echo << - - - MegaGlest gameservers - - - - - - - - - - - - - - - - - - - - - -END; + if ( REFRESH_INTERVAL != 0 ) { + header( 'Refresh: ' . REFRESH_INTERVAL ); + } + echo '' . PHP_EOL; + echo '' . PHP_EOL; + echo '' . PHP_EOL; + echo ' ' . htmlspecialchars( PRODUCT_NAME ) . ' gameservers' . PHP_EOL; + echo ' ' . PHP_EOL; + echo '' . PHP_EOL; + echo '' . PHP_EOL; + echo '
glestVersionplatformbinaryCompileDateserverTitleiptechmaptilesetactiveSlotsnetworkSlotsconnectedClientsexternalServerPortcountrystatus
' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; foreach( $all_servers as $server ) { - //array_walk( $server, 'htmlspecialchars', 'ENT_QUOTES' ); echo "\t\t\t" . '' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; - echo "\t\t\t\t' . PHP_EOL; + + // glestVersion + printf( "\t\t\t\t%s", htmlspecialchars( $server['glestVersion'], ENT_QUOTES ), PHP_EOL ); + + // status + $status_code = $server['status']; + if ( $status_code == 0) + { + $gameFull = ( $server['networkSlots'] <= $server['connectedClients'] ); + if ( $gameFull == true ) + { + $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%s", $status_class, htmlspecialchars( $status_title, ENT_QUOTES ), PHP_EOL ); + + // country if ( $server['country'] !== '' ) { $flagfile = 'flags/' . strtolower( $server['country'] ).'.png'; if ( file_exists( $flagfile ) ) { - echo "\t\t\t\t' . PHP_EOL; + printf( "\t\t\t\t", $flagfile, $server['country'], $server['country'], PHP_EOL ); } else { - echo "\t\t\t\t' . PHP_EOL; + printf( "\t\t\t\t%s", htmlspecialchars( $server['country'], ENT_QUOTES ), PHP_EOL ); } } else { - echo "\t\t\t\t' . PHP_EOL; + printf( "\t\t\t\t%s", PHP_EOL ); } - $calculatedStatus = $server['status']; - if($calculatedStatus == 0) - { - $gameFull = ($server['networkSlots'] <= $server['connectedClients']); - if($gameFull == true) - { - $calculatedStatus = 1; - } - } + // serverTitle + printf( "\t\t\t\t%s", htmlspecialchars( $server['serverTitle'], ENT_QUOTES ), PHP_EOL ); - switch($calculatedStatus) - { - case 0: - echo "\t\t\t\t' . PHP_EOL; - break; - case 1: - echo "\t\t\t\t' . PHP_EOL; - break; - case 2: - echo "\t\t\t\t' . PHP_EOL; - break; - case 3: - echo "\t\t\t\t' . PHP_EOL; - break; - default: - echo "\t\t\t\t' . PHP_EOL; - } + // tech + printf( "\t\t\t\t%s", htmlspecialchars( $server['tech'], ENT_QUOTES ), PHP_EOL ); + + // connectedClients + printf( "\t\t\t\t%s", htmlspecialchars( $server['connectedClients'], ENT_QUOTES ), PHP_EOL ); + + // networkSlots + printf( "\t\t\t\t%s", htmlspecialchars( $server['networkSlots'], ENT_QUOTES ), PHP_EOL ); + + // activeSlots + printf( "\t\t\t\t%s", htmlspecialchars( $server['activeSlots'], ENT_QUOTES ), PHP_EOL ); + + // map + printf( "\t\t\t\t%s", htmlspecialchars( $server['map'], ENT_QUOTES ), PHP_EOL ); + + // tileset + printf( "\t\t\t\t%s", htmlspecialchars( $server['tileset'], ENT_QUOTES ), PHP_EOL ); + + // ip + printf( "\t\t\t\t%s", htmlspecialchars( $server['ip'], ENT_QUOTES ), PHP_EOL ); + + // externalServerPort + printf( "\t\t\t\t%s", htmlspecialchars( $server['externalServerPort'], ENT_QUOTES ), PHP_EOL ); + + // platform + printf( "\t\t\t\t%s", htmlspecialchars( $server['platform'], ENT_QUOTES ), PHP_EOL ); + + // binaryCompileDate + printf( "\t\t\t\t%s", htmlspecialchars( $server['binaryCompileDate'], ENT_QUOTES ), PHP_EOL ); echo "\t\t\t" . '' . PHP_EOL; }
VersionStatusCountryTitleTechtreeNetwork playersNetwork slotsTotal slotsMapTilesetIPv4 addressGame protocol portPlatformBuild date
" . htmlspecialchars( $server['glestVersion'], ENT_QUOTES ) . '" . htmlspecialchars( $server['platform'], ENT_QUOTES ) . '" . htmlspecialchars( $server['binaryCompileDate'], ENT_QUOTES ) . '" . htmlspecialchars( $server['serverTitle'], ENT_QUOTES ) . '" . htmlspecialchars( $server['ip'], ENT_QUOTES ) . '" . htmlspecialchars( $server['tech'], ENT_QUOTES ) . '" . htmlspecialchars( $server['map'], ENT_QUOTES ) . '" . htmlspecialchars( $server['tileset'], ENT_QUOTES ) . '" . htmlspecialchars( $server['activeSlots'], ENT_QUOTES ) . '" . htmlspecialchars( $server['networkSlots'], ENT_QUOTES ) . '" . htmlspecialchars( $server['connectedClients'], ENT_QUOTES ) . '" . htmlspecialchars( $server['externalServerPort'], ENT_QUOTES ) . '%s%s" . '' . $server['country'] . ' country flag' . '\"%s" . 'unknown' . '%s" . htmlspecialchars( $server['country'], ENT_QUOTES ) . 'unknown%s" . htmlspecialchars( "waiting for players", ENT_QUOTES ) . '" . htmlspecialchars( "game full, pending start", ENT_QUOTES ) . '" . htmlspecialchars( "in progress", ENT_QUOTES ) . '" . htmlspecialchars( "finished", ENT_QUOTES ) . '" . htmlspecialchars( "unknown: " . $server['status'], ENT_QUOTES ) . '%s%s%s%s%s%s%s%s%s%s