Created
March 19, 2013 19:51
-
-
Save anonymous/5199495 to your computer and use it in GitHub Desktop.
www/server/status.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo('<?xml version="1.0" encoding="ISO-8859-15"?>' . "\n"); | |
echo('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); | |
?> | |
<html> | |
<head> | |
<title>Server status</title> | |
<meta http-equiv="Refresh" content="60"/> | |
<style type="text/css"> | |
body { | |
font-family: sans-serif; | |
font-size: 8pt; | |
background-color: #cba083; | |
text-align: center; | |
margin: 0px; | |
padding: 0px; | |
font-weight: bold; | |
} | |
</style> | |
</head> | |
<body> | |
<?php | |
error_reporting(E_ALL); | |
ini_set("display_errors", "1"); | |
$datestr = ""; | |
$user_count = 0; | |
$lines = file("http://server.themanaworld.org/online.txt"); | |
$line_count = count($lines); | |
// Extract information about last update and user count from online.txt file | |
if ($lines != FALSE) { | |
foreach ($lines as $line_num => $line) { | |
if ($line_num == 0) { | |
$start = strlen('Online Players on The Mana World ('); | |
$length = strlen('04 Apr 2007 14:05:22'); | |
$datestr = substr($line, $start, $length); | |
} | |
else if ($line_num == $line_count - 1) { | |
list($user_count) = sscanf($line, "%d"); | |
if (!($user_count > 0)) { | |
$user_count = 0; | |
} | |
} | |
} | |
} | |
// When online file was updated in the last 30 seconds, assume server online | |
$update_time = strtotime($datestr); | |
if (time() - $update_time < 30) | |
{ | |
echo '<div style="color: green;">'; | |
echo('Online (<a href="http://server.themanaworld.org/online.html" target="_top" style="color: green; text-decoration: none;">' . | |
$user_count . ' players</a>)'); | |
echo '</div>'; | |
} | |
else | |
{ | |
echo '<div style="color: red;">'; | |
echo("Offline (since $datestr)"); | |
echo '</div>'; | |
} | |
echo("\n"); | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment