Customizing SMF > SMF Coding Discussion
i don't know how to put java script
Orangine:
just put it inside index.template.php of your current theme
The Craw:
--- Quote from: Orangine on July 24, 2012, 12:23:31 PM ---just put it inside index.template.php of your current theme
--- End quote ---
Probably not a good idea, considering what that actually is.
I'm guessing that he didn't write that, being that he doesn't know what kind of code it is. Which is why I asked for the resource/tutorial he was going by, so that we may advise accordingly.
Sorck:
I've just thrown together a bit of code which might do what you're looking for. I've not tested it at all and it certainly isn't as well-formed as it could be but I've tried to include a way to reduce the load on your server. The second bit of code says whether or not the server is active. If the data is old then AJAX is used to reload the server data.
IMO a minutely cron would be a better way to go but that would be harder to setup.
Be aware that the code is not tested and is in no way guaranteed to work. (It'll also still take a little bit of though on your behalf as to where to put these bits of code).
]BTW, I've hard--coaded things in here that would be best obtained through some other method (e.g. $modSettings) but I don't have the time to add all of that to the code.
--- Code: (/reload.php) ---<?php
// load SMF
require_once('SSI.php');
// check the cache
$cache = cache_get_data('mc_server_status');
if(!$cache || $cache['time'] < (time()-60) ) {
mc_refresh();
} else {
die('Hacking attempt...');
}
function mc_refresh() {
error_reporting(E_ERROR);
$fp = fsockopen('cenacraftserver.zapto.org', 25565, $errno, $errstr, 1);
if (!$fp) {
$status = false;
} else {
$status = true;
fclose($fp);
}
cache_put_data('mc_server_status', array('status' => $status, 'time' => time()), 240);
}
?>
--- End code ---
--- Code: (This will need to go where you want your MC server status to be displayed) ---$status = cache_get_data('mc_server_status');
echo $status ? ($status['status'] ? 'Online' : 'Offline') : 'Unknown';
if(!$status || $status['time'] < (time()-60))
echo '<script type="text/javascript"><!-- // --><![CDATA[
getXMLDocument(\'reload.php\', function(a,b){});
// ]]></script>';
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version