Advertisement
Guest User

starbound logger

a guest
Dec 15th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. <?php
  2. /**
  3. * @author Daniel Kesberg <kesberg@ebene3.com>
  4. * @copyright (c) 2013, Daniel Kesberg
  5. */
  6.  
  7. error_reporting(E_ALL);
  8. ini_set('display_errors', false);
  9.  
  10. $parseTimeStart = microtime();
  11.  
  12. // load config
  13. // Set paths.log to the full path of the log file
  14. $config = array(
  15. 'server' => array(
  16. 'hostname' => '127.0.0.1',
  17. 'port' => 21025
  18. ),
  19. 'paths' => array(
  20. 'log' => 'd:/games/Steam/steamApps/common/Starbound/starbound_server.log'
  21. )
  22. );
  23.  
  24. // read logfile
  25. $log = file_get_contents($config['paths']['log']);
  26.  
  27. // split into lines
  28. $logLines = explode("\n", $log);
  29.  
  30. // split into lines
  31. $logChatLines = explode("\n", $log);
  32.  
  33. // only keep lines with client info
  34. $logClients = array_filter($logLines, function($line) {
  35. return preg_match('/^Info:.*Client/', $line);
  36. });
  37.  
  38. // '/!Info\:\s*<([^>]{2,})>\s?(.*)!i/'
  39. // only keep lines with client info
  40. $chatStore = array_filter($logLines, function($line) {
  41. return preg_match('/^Info\:\s\s/', $line);
  42. });
  43.  
  44. // extract chat
  45.  
  46.  
  47. // extract clients
  48. $clients = array();
  49. foreach ($logClients as $line) {
  50. if (preg_match('/.*?\\\'(.*)\\\'.*?\(.*?\)(.*)/is', $line, $matches) == 1) {
  51. if (strlen($matches[1])) {
  52. $clients[$matches[1]] = trim($matches[2]);
  53. }
  54. }
  55. }
  56.  
  57.  
  58. // only keep "connected" status
  59. $clients = array_filter($clients, function($status) {
  60. return trim($status) == 'connected';
  61. });
  62.  
  63. // sort
  64. ksort($clients);
  65.  
  66. // get server version
  67. $logVersion = array_filter($logLines, function($line) {
  68. return preg_match('/^Info: Server version/', $line);
  69. });
  70.  
  71. // only look at the last line
  72. $logVersion = end($logVersion);
  73. $tmp = explode("'", $logVersion);
  74. $logVersion = $tmp[1];
  75.  
  76. // server is running ?
  77. // edit: removed shell cmd, stole fsockopen from https://gist.github.com/lagonnebula/7928214 ;)
  78. $fp = fsockopen($config['server']['hostname'], $config['server']['port'], $errno, $errstr, 30);
  79. if ($fp){
  80. $serverIsRunning = 1;
  81. fclose($fp);
  82. } else {
  83. $serverIsRunning = 0;
  84. }
  85.  
  86. // output
  87. ?>
  88. <html>
  89. <head>
  90. <title>Starbound Server Info</title>
  91. <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
  92. <style type="text/css">
  93. body {
  94. padding-top: 70px;
  95. }
  96. table > tbody > tr > td.server-status {
  97. vertical-align: middle;
  98. }
  99. </style>
  100. </head>
  101. <body>
  102. <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  103. <div class="container">
  104. <div class="navbar-header">
  105. <a class="navbar-brand" href="#">Starbound Server Info</a>
  106. </div>
  107. </div>
  108. </div>
  109.  
  110. <div class="container">
  111. <div class="row">
  112. <div class="col-md-12">
  113. <div class="panel panel-default">
  114. <div class="panel-heading"><span class="glyphicon glyphicon-globe"></span> Server</div>
  115. <div class="panel-body">
  116. <table class="table table-condensed table-bordered">
  117. <tbody>
  118. <tr>
  119. <th>Status</th>
  120. <td class="server-status">
  121. <span class="label label-<?php echo ($serverIsRunning == 1) ? 'success' : 'danger' ; ?>">
  122. <?php echo ($serverIsRunning == 1) ? 'Online' : 'Offline' ; ?>
  123. </span>
  124. </td>
  125. </tr>
  126. <tr>
  127. <th>Version</th>
  128. <td><?php echo $logVersion; ?></td>
  129. </tr>
  130. <tr>
  131. <th>IP</th>
  132. <td><?php echo 'www.colony-nyan.com'; ?></td>
  133. </tr>
  134. <tr>
  135. <th>Players Online</th>
  136. <td><?php echo count($clients); ?></td>
  137. </tr>
  138. </tbody>
  139. </table>
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. <div class="row">
  145. <div class="col-md-12">
  146. <div class="panel panel-default">
  147. <div class="panel-heading"><span class="glyphicon glyphicon-user"></span> Players</div>
  148. <div class="panel-body">
  149. <?php if (count($clients)): ?>
  150. <table class="table table-condensed table-bordered">
  151. <thead>
  152. <tr>
  153. <th>Playername</th>
  154. </tr>
  155. </thead>
  156. <tbody>
  157. <?php foreach ($clients as $client => $status): ?>
  158. <tr>
  159. <td>
  160. <?php echo $client; ?>
  161. </td>
  162. </tr>
  163. <?php endforeach; ?>
  164. </tbody>
  165. </table>
  166. <?php else: ?>
  167. No active players
  168. <?php endif; ?>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. <div class="row">
  174. <div class="col-md-12">
  175. <div class="panel panel-default">
  176. <div class="panel-heading"><span class="glyphicon glyphicon-user"></span> Chat</div>
  177. <div class="panel-body">
  178. <?php if (count($clients)): ?>
  179. <table class="table table-condensed table-bordered">
  180. <thead>
  181. <tr>
  182. <th>Current Chat</th>
  183. </tr>
  184. </thead>
  185. <tbody>
  186. <?php foreach ($chatStore as $Chats): ?>
  187. <tr>
  188. <td>
  189. <?php echo htmlspecialchars($Chats); ?>
  190. </td>
  191. </tr>
  192. <?php endforeach; ?>
  193. </tbody>
  194. </table>
  195. <?php else: ?>
  196. No active players
  197. <?php endif; ?>
  198. </div>
  199. </div>
  200. </div>
  201. </div>
  202. <div class="row">
  203. <div class="col-md-12">
  204. <span class="label label-default">
  205. Parse time: <?php echo microtime() - $parseTimeStart; ?> seconds.
  206. </span>
  207. </div>
  208. </div>
  209. </div>
  210. </body>
  211. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement