- added game statistics for completed games

This commit is contained in:
Mark Vejvoda 2013-10-31 03:34:28 +00:00
parent dfb11de241
commit afa2cc520a
3 changed files with 238 additions and 1 deletions

View File

@ -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;
}
?>

View File

@ -0,0 +1,208 @@
<?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( 'config.php' );
require_once( 'functions.php' );
// Representation starts here
header( 'Content-Type: text/html; charset=utf-8' );
echo '<!DOCTYPE HTML>' . PHP_EOL;
echo '<html>' . PHP_EOL;
echo ' <head>' . PHP_EOL;
echo ' <meta charset="UTF-8" />' . PHP_EOL;
echo ' <title>' . htmlspecialchars( PRODUCT_NAME ) . ' game stats</title>' . PHP_EOL;
echo ' <link rel="stylesheet" type="text/css" href="style/screen.css" />' . PHP_EOL;
echo ' <link rel="shortcut icon" type="image/x-icon" href="images/' . htmlspecialchars( strtolower( PRODUCT_NAME ) ) . '.ico" />' . PHP_EOL;
echo ' </head>' . PHP_EOL;
echo ' <body>' . PHP_EOL;
echo ' <h1><a href="' . htmlspecialchars( PRODUCT_URL ) . '">' . htmlspecialchars( PRODUCT_NAME ) . '</a> game stats</h1>' . PHP_EOL;
echo ' <table>' . PHP_EOL;
echo ' <tr>' . PHP_EOL;
echo ' <th title="gameDuration">Game Duration</th>' . PHP_EOL;
echo ' <th title="maxConcurrentUnitCount">Maximum Concurrent Units</th>' . PHP_EOL;
echo ' <th title="totalEndGameConcurrentUnitCount">Total Units at End</th>' . PHP_EOL;
echo ' <th title="isHeadlessServer">Headless Server</th>' . PHP_EOL;
echo ' </tr>' . 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" . '<tr>' . PHP_EOL;
// Game Stats
$gameDuration = $stats['framesToCalculatePlaytime'];
$gameDuration = getTimeString($gameDuration);
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $gameDuration, ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $stats['maxConcurrentUnitCount'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $stats['totalEndGameConcurrentUnitCount'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $stats['isHeadlessServer'], ENT_QUOTES ), PHP_EOL );
echo "\t\t\t" . '</tr>' . PHP_EOL;
// Player stats for Game
echo "\t\t\t" . '<tr>' . PHP_EOL;
echo ' <table>' . PHP_EOL;
echo ' <tr>' . PHP_EOL;
echo ' <th title="factionIndex">Faction Index</th>' . PHP_EOL;
echo ' <th title="controlType">Player Type</th>' . PHP_EOL;
echo ' <th title="resourceMultiplier">Resource Multiplier</th>' . PHP_EOL;
echo ' <th title="factionTypeName">Faction Type</th>' . PHP_EOL;
echo ' <th title="personalityType">Personality Type</th>' . PHP_EOL;
echo ' <th title="teamIndex">Team</th>' . PHP_EOL;
echo ' <th title="wonGame">Winner</th>' . PHP_EOL;
echo ' <th title="killCount">Kills</th>' . PHP_EOL;
echo ' <th title="enemyKillCount">Enemy Kills</th>' . PHP_EOL;
echo ' <th title="deathCount">Deaths</th>' . PHP_EOL;
echo ' <th title="unitsProducedCount">Units Produced</th>' . PHP_EOL;
echo ' <th title="resourceHarvestedCount">Resources Harvested</th>' . PHP_EOL;
echo ' <th title="playerName">Player Name</th>' . PHP_EOL;
echo ' <th title="quitBeforeGameEnd">Quit Before Game Ended</th>' . PHP_EOL;
echo ' <th title="quitTime">Quit Time</th>' . PHP_EOL;
echo ' </tr>' . PHP_EOL;
foreach( $all_player_stats as $player_stats )
{
echo "\t\t\t" . '<tr>' . PHP_EOL;
printf( "\t\t\t\t<td>%s</td>%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<td>%s</td>%s", htmlspecialchars( $controlTypeTitle, ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['resourceMultiplier'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%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<td>%s</td>%s", htmlspecialchars( $personalityType, ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['teamIndex'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['wonGame'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['killCount'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['enemyKillCount'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['deathCount'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['unitsProducedCount'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['resourceHarvestedCount'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['playerName'], ENT_QUOTES ), PHP_EOL );
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $player_stats['quitBeforeGameEnd'], ENT_QUOTES ), PHP_EOL );
$quitTime = $stats['quitTime'];
$quitTime = getTimeString($quitTime);
printf( "\t\t\t\t<td>%s</td>%s", htmlspecialchars( $quitTime, ENT_QUOTES ), PHP_EOL );
echo "\t\t\t" . '</tr>' . PHP_EOL;
}
unset( $all_player_stats );
unset( $player_stats );
}
unset( $all_stats );
unset( $stats );
}
echo ' </table>' . PHP_EOL;
echo ' <p>' . PHP_EOL;
echo ' <br />' . PHP_EOL;
echo ' </p>' . PHP_EOL;
echo ' </body>' . PHP_EOL;
echo '</html>' . PHP_EOL;
?>

View File

@ -122,7 +122,15 @@
$status_title = 'unknown';
$status_class = 'unknown';
}
printf( "\t\t\t\t<td title=\"%s\" class=\"%s\">%s</td>%s", $server['status'], $status_class, htmlspecialchars( $status_title, ENT_QUOTES ), PHP_EOL );
if ($status_code == 3 && $server['gameUUID'] != "")
{
printf( "\t\t\t\t<td title=\"%s\" class=\"%s\"><a href='showGameStats.php?gameUUID=%s'>%s</a></td>%s", $server['status'], $status_class, $server['gameUUID'], htmlspecialchars( $status_title, ENT_QUOTES ), PHP_EOL );
}
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 );
}
// country
if ( $server['country'] !== '' ) {