Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Daniel Kesberg <kesberg@ebene3.com>
- * @copyright (c) 2013, Daniel Kesberg
- */
- error_reporting(E_ALL);
- ini_set('display_errors', false);
- $parseTimeStart = microtime();
- // load config
- // Set paths.log to the full path of the log file
- $config = array(
- 'server' => array(
- 'hostname' => '127.0.0.1',
- 'port' => 21025
- ),
- 'paths' => array(
- 'log' => 'd:/games/Steam/steamApps/common/Starbound/starbound_server.log',
- 'config' => 'd:/games/Steam/steamApps/common/Starbound/starbound.config'
- )
- );
- // read logfile
- $log = file_get_contents($config['paths']['log']);
- // read configfile
- $conf = file_get_contents($config['paths']['config']);
- // split into lines
- $logLines = explode("\n", $log);
- $confLines = explode("\n", $conf);
- // get server version
- $confMax = array_filter($confLines, function($line) {
- return preg_match('/maxPlayers/', $line);
- });
- // only look at the last line
- $confMax = end($confMax);
- $tmp = explode(': ', $confMax);
- $tmp2 = str_replace(',',' ',$tmp);
- $confMax = $tmp2[1];
- // only keep lines with client info
- $logClients = array_filter($logLines, function($line) {
- return preg_match('/^Info:.*Client/', $line);
- });
- // '/!Info\:\s*<([^>]{2,})>\s?(.*)!i/'
- // only keep lines with client info
- $chats = array_filter($logLines, function($line) {
- return preg_match('/^Info\:\s\s/', $line);
- });
- // extract clients
- $clients = array();
- foreach ($logClients as $line) {
- if (preg_match('/.*?\\\'(.*)\\\'.*?\(.*?\)(.*)/is', $line, $matches) == 1) {
- if (strlen($matches[1])) {
- $clients[$matches[1]] = trim($matches[2]);
- }
- }
- }
- // only keep "connected" status
- $clients = array_filter($clients, function($status) {
- return trim($status) == 'connected';
- });
- // sort
- ksort($clients);
- // get server version
- $logVersion = array_filter($logLines, function($line) {
- return preg_match('/^Info: Server version/', $line);
- });
- // only look at the last line
- $logVersion = end($logVersion);
- $tmp = explode("'", $logVersion);
- $logVersion = $tmp[1];
- // server is running ?
- // edit: removed shell cmd, stole fsockopen from https://gist.github.com/lagonnebula/7928214 ;)
- $fp = fsockopen($config['server']['hostname'], $config['server']['port'], $errno, $errstr, 30);
- if ($fp){
- $serverIsRunning = 1;
- fclose($fp);
- } else {
- $serverIsRunning = 0;
- }
- // output
- ?>
- <?php
- function removePrefix(array $input) {
- $return = array();
- foreach ($input as $key => $value) {
- if (strpos($key, 'Info' ) === 0)
- $key = substr($key, 4);
- if (is_array($value))
- $value = removePrefix($value);
- $return[$key] = $value;
- }
- return $return;
- }
- $chats = removePrefix($chats);
- ?>
- <html>
- <head>
- <title>Starbound Server Info</title>
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
- <style type="text/css">
- body {
- padding-top: 70px;
- }
- table > tbody > tr > td.server-status {
- vertical-align: middle;
- }
- </style>
- <script>
- window.onload=function() {
- var elem = document.getElementById('users');
- var elem = document.getElementById('chat');
- elem.scrollTop = elem.scrollHeight;
- };
- </script>
- <META HTTP-EQUIV=Refresh CONTENT="30">
- </head>
- <body>
- <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
- <div class="container">
- <div class="navbar-header">
- <a class="navbar-brand" href="#">Starbound Server Info</a>
- </div>
- </div>
- </div>
- <div class="container">
- <div class="row">
- <div class="col-md-12">
- <div class="panel panel-default">
- <div class="panel-heading"><span class="glyphicon glyphicon-globe"></span> Server</div>
- <div class="panel-body">
- <table class="table table-condensed table-bordered">
- <tbody>
- <tr>
- <th>Status</th>
- <td class="server-status">
- <span class="label label-<?php echo ($serverIsRunning == 1) ? 'success' : 'danger' ; ?>">
- <?php echo ($serverIsRunning == 1) ? 'Online' : 'Offline' ;?>
- <?php if($serverIsRunning == 0) { ?>
- <script>
- // alert('hello');
- // or
- //window.open("http://colony-nyan.com/warn.html","alert","width=320,height=50");
- // or any type of script you want to run
- </script>
- <?php } ?>
- </span>
- </td>
- </tr>
- <tr>
- <th>Version</th>
- <td><?php echo $logVersion; ?></td>
- </tr>
- <tr>
- <th>IP</th>
- <td><?php echo 'www.colony-nyan.com'; ?></td>
- </tr>
- <tr>
- <th>Players Online</th>
- <td><?php echo count($clients),'/',$confMax; ?></td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <div class="panel panel-default" style="float:left;width:300;">
- <div class="panel-heading"><span class="glyphicon glyphicon-user"></span> Players</div>
- <div class="panel-body" style="height:400px;overflow:auto;overflow-y:scroll;" id="users">
- <?php if (count($clients)): ?>
- <table class="table table-condensed table-bordered">
- <thead>
- </thead>
- <tbody>
- <?php foreach ($clients as $client => $status): ?>
- <tr>
- <td>
- <?php echo htmlspecialchars($client); ?>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php else: ?>
- No active players
- <?php endif; ?>
- </div>
- </div>
- <div class="panel panel-default">
- <div class="panel-heading">   <span class="glyphicon glyphicon-user"></span> Chat</div>
- <div class="panel-body" style="height:400px;overflow:auto;overflow-y:scroll;" id="chat">
- <?php if (count($chats)): ?>
- <table class="table table-condensed table-bordered">
- <thead>
- </thead>
- <tbody>
- <?php foreach ($chats as $Convo): ?>
- <tr>
- <td>
- <?php echo htmlspecialchars($Convo); ?>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php else: ?>
- No active chats
- <?php endif; ?>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <span class="label label-default">
- Parse time: <?php echo microtime() - $parseTimeStart; ?> seconds.
- </span>
- </div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement