Advertisement
Guest User

update - server info finder

a guest
Dec 15th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 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. // only keep lines with client info
  31. $logClients = array_filter($logLines, function($line) {
  32. return preg_match('/^Info:.*Client/', $line);
  33. });
  34.  
  35. // extract clients
  36. $clients = array();
  37. foreach ($logClients as $line) {
  38. if (preg_match('/.*?\\\'(.*)\\\'.*?\(.*?\)(.*)/is', $line, $matches) == 1) {
  39. if (strlen($matches[1])) {
  40. $clients[$matches[1]] = trim($matches[2]);
  41. }
  42. }
  43. }
  44.  
  45. // only keep "connected" status
  46. $clients = array_filter($clients, function($status) {
  47. return trim($status) == 'connected';
  48. });
  49.  
  50. // sort
  51. ksort($clients);
  52.  
  53. // get server version
  54. $logVersion = array_filter($logLines, function($line) {
  55. return preg_match('/^Info: Server version/', $line);
  56. });
  57.  
  58. // only look at the last line
  59. $logVersion = end($logVersion);
  60. $tmp = explode("'", $logVersion);
  61. $logVersion = $tmp[1];
  62.  
  63. // server is running ?
  64. // edit: removed shell cmd, stole fsockopen from https://gist.github.com/lagonnebula/7928214 ;)
  65. $fp = fsockopen($config['server']['hostname'], $config['server']['port'], $errno, $errstr, 30);
  66. if ($fp){
  67. $serverIsRunning = 1;
  68. fclose($fp);
  69. } else {
  70. $serverIsRunning = 0;
  71. }
  72.  
  73. // output
  74. ?>
  75. <html>
  76. <head>
  77. <title>Starbound Server Info</title>
  78. <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
  79. <style type="text/css">
  80. body {
  81. padding-top: 70px;
  82. }
  83. table > tbody > tr > td.server-status {
  84. vertical-align: middle;
  85. }
  86. </style>
  87. </head>
  88. <body>
  89. <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  90. <div class="container">
  91. <div class="navbar-header">
  92. <a class="navbar-brand" href="#">Starbound Server Info</a>
  93. </div>
  94. </div>
  95. </div>
  96.  
  97. <div class="container">
  98. <div class="row">
  99. <div class="col-md-12">
  100. <div class="panel panel-default">
  101. <div class="panel-heading"><span class="glyphicon glyphicon-globe"></span> Server</div>
  102. <div class="panel-body">
  103. <table class="table table-condensed table-bordered">
  104. <tbody>
  105. <tr>
  106. <th>Status</th>
  107. <td class="server-status">
  108. <span class="label label-<?php echo ($serverIsRunning == 1) ? 'success' : 'danger' ; ?>">
  109. <?php echo ($serverIsRunning == 1) ? 'Online' : 'Offline' ; ?>
  110. </span>
  111. </td>
  112. </tr>
  113. <tr>
  114. <th>Version</th>
  115. <td><?php echo $logVersion; ?></td>
  116. </tr>
  117. <tr>
  118. <th>IP</th>
  119. <td><?php echo 'www.colony-nyan.com'; ?></td>
  120. </tr>
  121. <tr>
  122. <th>Players Online</th>
  123. <td><?php echo count($clients); ?></td>
  124. </tr>
  125. </tbody>
  126. </table>
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. <div class="row">
  132. <div class="col-md-12">
  133. <div class="panel panel-default">
  134. <div class="panel-heading"><span class="glyphicon glyphicon-user"></span> Players</div>
  135. <div class="panel-body">
  136. <?php if (count($clients)): ?>
  137. <table class="table table-condensed table-bordered">
  138. <thead>
  139. <tr>
  140. <th>Playername</th>
  141. </tr>
  142. </thead>
  143. <tbody>
  144. <?php foreach ($clients as $client => $status): ?>
  145. <tr>
  146. <td>
  147. <?php echo $client; ?>
  148. </td>
  149. </tr>
  150. <?php endforeach; ?>
  151. </tbody>
  152. </table>
  153. <?php else: ?>
  154. No active players
  155. <?php endif; ?>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. <div class="row">
  161. <div class="col-md-12">
  162. <span class="label label-default">
  163. Parse time: <?php echo microtime() - $parseTimeStart; ?> seconds.
  164. </span>
  165. </div>
  166. </div>
  167. </div>
  168. </body>
  169. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement