From afa2cc520aca85ae25a29d0fd29bf42e7f359c38 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 31 Oct 2013 03:34:28 +0000 Subject: [PATCH] - added game statistics for completed games --- source/masterserver/functions.php | 21 +++ source/masterserver/showGameStats.php | 208 ++++++++++++++++++++++++++ source/masterserver/showServers.php | 10 +- 3 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 source/masterserver/showGameStats.php diff --git a/source/masterserver/functions.php b/source/masterserver/functions.php index 22e7051d..f3420d40 100644 --- a/source/masterserver/functions.php +++ b/source/masterserver/functions.php @@ -84,4 +84,25 @@ mysql_query( "UPDATE recent_servers SET name='$serverTitle', players='$players' WHERE id=$id LIMIT 1"); } + function getTimeString($frames) { + $framesleft = $frames; + $updateFps = 40.0; + + $hours = ( int )$frames / ( float )$updateFps / 3600.0; + $framesleft = $framesleft - $hours * 3600 * $updateFps; + $minutes = ( int )$framesleft / ( float )$updateFps / 60.0; + $framesleft = $framesleft - $minutes * 60 * $updateFps; + $seconds = ( int )$framesleft / ( float )$updateFps; + + $hourstr = strval(( int )$hours); + if($hours < 10) $hourstr = "0" . $hourstr; + + $minutestr = strval(( int )$minutes); + if($minutes < 10) $minutestr = "0" . $minutestr; + + $secondstr = strval(( int )$seconds); + if($seconds < 10) $secondstr = "0" . $secondstr; + + return $hourstr . ":" . $minutestr . ":" . $secondstr; + } ?> diff --git a/source/masterserver/showGameStats.php b/source/masterserver/showGameStats.php new file mode 100644 index 00000000..d6c4ff31 --- /dev/null +++ b/source/masterserver/showGameStats.php @@ -0,0 +1,208 @@ +' . PHP_EOL; + echo '' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . htmlspecialchars( PRODUCT_NAME ) . ' game stats' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo '

' . htmlspecialchars( PRODUCT_NAME ) . ' game stats

' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + echo ' ' . PHP_EOL; + + // get stats for a specific game + $gameUUID = ""; + if ( isset( $_GET['gameUUID'] ) ) + { + $gameUUID = (string) clean_str( $_GET['gameUUID'] ); + + //printf( "Game UUID = %s\n", htmlspecialchars( $gameUUID, ENT_QUOTES ), PHP_EOL ); + + define( 'DB_LINK', db_connect() ); + // consider replacing this by a cron job + cleanupServerList(); + + $whereClause = 'gameUUID=\'' . mysql_real_escape_string( $gameUUID ) . '\';'; + + $stats_in_db = mysql_query( 'SELECT * FROM glestgamestats WHERE ' . $whereClause); + $all_stats = array(); + while ( $stats = mysql_fetch_array( $stats_in_db ) ) + { + array_push( $all_stats, $stats ); + } + unset( $stats_in_db ); + unset( $stats ); + + $player_stats_in_db = mysql_query( 'SELECT * FROM glestgameplayerstats WHERE ' . $whereClause); + $all_player_stats = array(); + while ( $player_stats = mysql_fetch_array( $player_stats_in_db ) ) + { + array_push( $all_player_stats, $player_stats ); + } + unset( $player_stats_in_db ); + unset( $player_stats ); + + db_disconnect( DB_LINK ); + unset( $linkid ); + + foreach( $all_stats as $stats ) + { + echo "\t\t\t" . '' . PHP_EOL; + + // Game Stats + $gameDuration = $stats['framesToCalculatePlaytime']; + $gameDuration = getTimeString($gameDuration); + + printf( "\t\t\t\t%s", htmlspecialchars( $gameDuration, ENT_QUOTES ), PHP_EOL ); + + printf( "\t\t\t\t%s", htmlspecialchars( $stats['maxConcurrentUnitCount'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $stats['totalEndGameConcurrentUnitCount'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $stats['isHeadlessServer'], ENT_QUOTES ), PHP_EOL ); + + echo "\t\t\t" . '' . PHP_EOL; + + // Player stats for Game + echo "\t\t\t" . '' . PHP_EOL; + + echo '
Game DurationMaximum Concurrent UnitsTotal Units at EndHeadless Server
%s%s%s%s
' . 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; + echo ' ' . PHP_EOL; + + foreach( $all_player_stats as $player_stats ) + { + echo "\t\t\t" . '' . PHP_EOL; + + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['factionIndex'], ENT_QUOTES ), PHP_EOL ); + + $controlType = $player_stats['controlType']; + switch ( $controlType ) + { + case 0: + $controlTypeTitle = "Closed"; + break; + case 1: + $controlTypeTitle = "CPU Easy"; + break; + case 2: + $controlTypeTitle = "CPU"; + break; + case 3: + $controlTypeTitle = "CPU Ultra"; + break; + case 4: + $controlTypeTitle = "CPU Mega"; + break; + case 5: + $controlTypeTitle = "Network Player"; + break; + case 6: + $controlTypeTitle = "Network Unassigned"; + break; + case 7: + $controlTypeTitle = "Human Host"; + break; + case 8: + $controlTypeTitle = "Network CPU Easy"; + break; + case 9: + $controlTypeTitle = "Network CPU"; + break; + case 10: + $controlTypeTitle = "Network CPU Ultra"; + break; + case 11: + $controlTypeTitle = "Network CPU Mega"; + break; + default: + $controlTypeTitle = 'unknown'; + } + + printf( "\t\t\t\t%s", htmlspecialchars( $controlTypeTitle, ENT_QUOTES ), PHP_EOL ); + + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['resourceMultiplier'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['factionTypeName'], ENT_QUOTES ), PHP_EOL ); + + $personalityType = $player_stats['personalityType']; + switch ( $personalityType ) + { + case 0: + $personalityType = "Normal"; + break; + case 1: + $personalityType = "Observer"; + break; + default: + $personalityType = 'unknown'; + } + + printf( "\t\t\t\t%s", htmlspecialchars( $personalityType, ENT_QUOTES ), PHP_EOL ); + + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['teamIndex'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['wonGame'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['killCount'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['enemyKillCount'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['deathCount'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['unitsProducedCount'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['resourceHarvestedCount'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['playerName'], ENT_QUOTES ), PHP_EOL ); + printf( "\t\t\t\t%s", htmlspecialchars( $player_stats['quitBeforeGameEnd'], ENT_QUOTES ), PHP_EOL ); + + $quitTime = $stats['quitTime']; + $quitTime = getTimeString($quitTime); + + printf( "\t\t\t\t%s", htmlspecialchars( $quitTime, ENT_QUOTES ), PHP_EOL ); + + echo "\t\t\t" . '' . PHP_EOL; + } + + unset( $all_player_stats ); + unset( $player_stats ); + } + + unset( $all_stats ); + unset( $stats ); + } + + echo '
Faction IndexPlayer TypeResource MultiplierFaction TypePersonality TypeTeamWinnerKillsEnemy KillsDeathsUnits ProducedResources HarvestedPlayer NameQuit Before Game EndedQuit Time
%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s
' . PHP_EOL; + + echo '

' . PHP_EOL; + echo '
' . PHP_EOL; + echo '

' . PHP_EOL; + + echo ' ' . PHP_EOL; + echo '' . PHP_EOL; +?> diff --git a/source/masterserver/showServers.php b/source/masterserver/showServers.php index ca3fac87..bc962e28 100644 --- a/source/masterserver/showServers.php +++ b/source/masterserver/showServers.php @@ -122,7 +122,15 @@ $status_title = 'unknown'; $status_class = 'unknown'; } - printf( "\t\t\t\t%s%s", $server['status'], $status_class, htmlspecialchars( $status_title, ENT_QUOTES ), PHP_EOL ); + + if ($status_code == 3 && $server['gameUUID'] != "") + { + printf( "\t\t\t\t%s%s", $server['status'], $status_class, $server['gameUUID'], htmlspecialchars( $status_title, ENT_QUOTES ), PHP_EOL ); + } + else + { + printf( "\t\t\t\t%s%s", $server['status'], $status_class, htmlspecialchars( $status_title, ENT_QUOTES ), PHP_EOL ); + } // country if ( $server['country'] !== '' ) {