Jump to content

Live Stats MySQL Query


votick

Recommended Posts

I would like to display the total number of players online accross the total number of game servers running.

 

 

So far I can display the total number of players online but I can't seem to get back the total number of servers running.

 

E.g. I want to have on my site "## players are online across ## servers. "

 

Is anyone able to help?

 

EDIT: I've done it now works a treat :p

Edited by votick
Link to comment
Share on other sites

  • 2 weeks later...
  • 7 months later...
  • 1 month later...
  • 3 weeks later...

Hi ,

TCAdmin provides some help create a file index.html or what ever name you want it to be

and play around with this code.

 

<b>Get a List of Configured Games and Voice Servers<br>
</b><font size="2">Required info:<br>
- Standard information</font><form action="http://127.0.0.1:8880/billingapi.aspx" method=post>
<table border="1" id="table1" style="border-collapse: collapse" bordercolordark="#000000" bordercolorlight="#C0C0C0">
	<tr>
		<td colspan="2" align="center"><b>Standard Information</b></td>
		<td> </td>
		<td><font size="2">This information is always required</font></td>
	</tr>
	<tr>
		<td>Admin:</td>
		<td> <input value="admin" name="tcadmin_username"></td>
		<td> </td>
		<td><font size="2">The admin account for the control panel</font></td>
	</tr>
	<tr>
		<td>Password:</td>
		<td> <input value="password" name="tcadmin_password"></td>
		<td> </td>
		<td><font size="2">The admin password</font></td>
	</tr>
	<tr>
		<td>Function:</td>
		<td> <select size="1" name="function">
		<option value="GetSupportedGames" selected>Get Supported Game Servers
		</option>
		<option value="GetSupportedVoiceServers">Get Supported Voice Servers
		</option>
		</select></td>
		<td> </td>
		<td><font size="2">The command that TCAdmin will execute</font></td>
	</tr>
	<tr>
		<td>Response Type:</td>
		<td><select size="1" name="response_type">
		<option value="xml" selected>XML</option>
		<option value="text">Text</option>
		</select></td>
		<td> </td>
		<td><font size="2">The type of response that will be sent by TCAdmin.</font></td>
	</tr>
	<tr>
		<td colspan="2"> </td>
		<td> </td>
		<td> </td>
	</tr>
	<tr>
		<td colspan="4" align="center">
<input type="submit" value="Submit"></td>
	</tr>
</table>
 </form>

Link to comment
Share on other sites

  • 1 month later...

Here is an edited version from long ago to display total player online out of how many slots and how many servers are online.

 

Database Query File include.php:

<?php

ini_set('precision', 5);

$link = mysql_connect('LOCALHOST', 'DATABASE_USER', 'DATABASE PASSWORD');
if (!$link) {
die('Not connected : ' . mysql_error());
}


$db_selected = mysql_select_db('DATABASE_NAME', $link);
if (!$db_selected) {
die ('Can\'t Find DB : ' . mysql_error());
}

//Query Stuff

$active = mysql_query("SELECT SUM(online) FROM  tc_game_service_live_stats");
$act = mysql_result($active, 0);
$totalslots = mysql_query("SELECT SUM(slots) FROM  tc_game_services");
$tsc = mysql_result($totalslots, 0);
$totalplayers = mysql_query("select sum(players) from tc_game_service_live_stats");
$po = mysql_result($totalplayers, 0);
?>

 

Don't forget to include the above file where ever your going to display the info.

<?php include 'include.php'; ?>

 

Display Queried Info:

<p>Players Online: <?php echo $po; ?>/<?php echo $tsc; ?></p>
	<p>Servers Online: <?php echo $act; ?></p>

 

There is so much more info that can be queried, per server or as a whole.

 

kx7htGn.png

Link to comment
Share on other sites

Here is a more detailed table of most of the items that can be queried.

 

<?php
$con=mysqli_connect('HOST', 'DB_USER', 'DB_PASS', 'tcadmin');
// Check connection
if (mysqli_connect_errno())
 {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

$result = mysqli_query($con,"SELECT * from tc_game_service_live_stats") or die(mysqli_error($con));


echo "<table border='1' style='background-color:gray';>
<tr>
<th>Colored Name</th>
<th>Name</th>
<th>Memory Used</th>
<th>CPU Usage (%)</th>
<th>Service ID</th>
<th>Process ID</th>
<th>Current Map</th>
<th>Online?</th>
<th>Players Online</th>
<th>Game Type</th>
<th>Game (Mod)</th>
<th>Queried Last</th>
</tr>";
while($row = mysqli_fetch_array($result))
 {
 $test = $row['memory'] /1024 /1024;
 $format = number_format($test,0); 
 echo "<tr>";
 echo "<td>" . $row['html_name'] . "</td>";
 echo "<td>" . $row['name'] . "</td>";
 echo "<td>" . $format .  " MB</td>";
 echo "<td>" . $row['cpu'] . "</td>";
 echo "<td>" . $row['service_id'] . "</td>";
 echo "<td>" . $row['pid'] . "</td>";
 echo "<td>" . $row['map'] . "</td>";
 echo "<td>"; if ($row['online'] == '1') {echo "Online";} else echo "Offline"; echo "</td>";
 echo "<td>" . $row['players'] .  "/" . $row['max_players'] . "</td>";
 echo "<td>" . $row['game_type'] . "</td>";
 echo "<td>" . $row['game'] . "</td>";
 echo "<td>" . $row['query_time'] . "</td>";
 echo "</tr>";
 }
echo "</table>";

mysqli_close($con);
?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use