i'm using sqlExpress2005 + iis + php5 with php_pdo_odbc enabled (php_mssql just dies on my priv.serv.)
so i just moded simple status/statistic for use with ODBC;
this code-part can be used as module in site ;)
it shows : server status, total accounts, total chars, current online and top10 of chars (by exp);
if it useful to someone - just say thx =)
p.s. sorry for my bad english :)
PHP Code:
<?
$hostname = '127.0.0.1';
$servers = Array('DeathMatch'=>6000, 'TestServer'=>6002);
$odbclogin = 'sa'; // you can change it to any user allowed to access your DB
$odbcpass = 'pass'; // pass for your DB user
$odbcdriver = 'SQL Native Client'; // see it in odbc administration utility; example is for my sql-express2005 instance ;)
$odbc_dsn = 'game'; // just name of odbc-instance in your "system dsn" for your game-server; i use it both for matchserver and website; name of default database configured in odbc instance;
function gt($a) {
// this only for simple time formating ;)
$hours=floor($a/3600);
$mins=floor(($a-($hours*3600))/60);
return "$hours h/$mins mins";
}
$status='';
foreach($servers as $sname => $port)
{
$connection = @fsockopen($hostname, $port, $errno, $errstr, 0.003);
if(!$connection) $status = '<span class="OFFLINE">ONLINE</span>'; else $status = '<span class="ONLINE">ONLINE</span>';
$status.= $sname . ' - ' . $status . '<br />';
}
try {
$conn = new PDO("odbc:dsn=$odbc_dsn;driver=$odbcdriver", $odbclogin,$odbcpass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) { $data = "ODBC error: " . $e->getMessage(); $error=1; }
$cmd="select count(*) as total from login";
$accounts=0;
try {
$query = $conn->prepare($cmd);
$query->execute();
} catch (PDOException $e) { die("ODBC error: ".$e->getMessage()); };
if ($query->columnCount()>0) { while ($in=$query->fetch()) $accounts=$in['total'];}
$query=null;
$cmd="select top 1 * from ServerStatus";
$online=0;
try {
$query = $conn->prepare($cmd);
$query->execute();
} catch (PDOException $e) { die("ODBC error: ".$e->getMessage()); };
if ($query->columnCount()>0) { while ($in=$query->fetch()) $online=$in[1];}
$query=null;
$cmd="select count(*) as total from Character";
$chars=0;
try {
$query = $conn->prepare($cmd);
$query->execute();
} catch (PDOException $e) { die("ODBC error: ".$e->getMessage()); };
if ($query->columnCount()>0) { while ($in=$query->fetch()) $chars=$in['total'];}
$query=null;
$char=array();
$toplist='';
$cmd="select top 10 * from Character where DeleteFlag=0 order by XP desc";
$cnt=0;
try {
$query = $conn->prepare($cmd);
$query->execute();
} catch (PDOException $e) { die("ODBC error: ".$e->getMessage()); };
if ($query->columnCount()>0) {
$toplist='<table align="center" style="border:3px double #aaa;padding:3px;">
<tr><td colspan="6"><h3>TOP 10 Characters</h3></td></tr>
<tr><td>Char Name</td><td>Level</td><td>XP</td><td>Game Time</td><td>Kills</td><td>Dies</td></tr>';
while ($in=$query->fetch()) {
$char=$in;
if ($char['Sex']==0) $cl='male'; else $cl='female';
$toplist.="<tr><td class='$cl'>".$char['Name']."</td><td><b>".$char['Level']."</b></td><td>".$char['XP']."</td><td>".gt($char['PlayTime'])."</td><td>".$char['KillCount']."</td><td>".$char['DeathCount']."</td></tr>";
}
$toplist.='</table>';
}
$query=null;
$conn=null;
echo "
<style type='text/css'>
<!--
td { padding:2pt; text-align:center;}
td.male { color: blue; }
td.female { color: magenta; }
-->
</style>
<div style='padding:5pt;text-align:center;'>
<b>Server status:</b> $status<br/>
<b>Total accounts:</b> $accounts<br/>
<b>Total characters:</b> $chars<br/>
<b>Current online:</b> $online<br/>
<br/>
<br/>
".$toplist."</div>";
?>