Show Players

This script will display online players with name, Ki number and current location on the server' status page. Thanks for phpVaultManager's author and several admin's status page for ideas and formatting techniques.

This was a really quick development. Feel free to replace it with a better one.

Prerequisites

  1. Apache2/Php5/mod_php installed on your server.
  2. PEAR-DB phpb module installed (sometimes comes as a default).

Installation guide

  1. Edit PlasmaServers.ini to change server' status page URL.

WebsiteUrl=http://barkonis.dyndns.org/online

  1. Create directory DocumentRoot/online, where DocumentRoot reflects your apache2 configuration parameter.

  2. Place following index.php script into the newly created directory.
  3. Edit index.php in order to put your shard's informations.
  4. Create directory online/lib directory
  5. Place following DBsetup.php into the directory
  6. Edit DBsetup.php and change connection string to reflects your configuration.

index.php

<html>
<head>
<meta name="Expires" content="Tue, 01 Jun 1999 19:58:02 GMT">
<STYLE TYPE="text/css">
body { background-color:#EFD6A4; }
A               { color: #000000; text-decoration: none; }
A:link          { color: #76170C; text-decoration: none; font-weight: bold;}
A:visited       { color: #76170C; text-decoration: none; font-weight: bold;}
A:active        { color: #CC6600;  }
A:hover         { color: #CC6600;  }

td {font-size: 12px; font-family: trebuchet,verdana,arial; color:#000000;}
.date {font-weight: bold; font-size: 16px; color: #000000; font-family: garamond,times;}
.head {font-style: bold; font-weight: bold; font-size: 36px; color: #FFFFFF; font-family: garamond,times;}
.subhead {font-weight: bold; font-size: 14px; color: #000000; font-family: trebuchet,arial,verdana;}
.border {font-weight: bold; font-size: 24px; color: #000000; font-family: trebuchet,arial,verdana;}
.link {font-weight: bold; font-size: 12px; font-family: trebuchet,arial,verdana; text-decoration: none;}
.author {font-size: 12px; color: #000000; font-family: garamond,times;}

p { font-family: trebuchet,verdana,arial; font-size:12px; color:#000000; }
</STYLE>
<title>Welcome!</title>
</head>

<body bgcolor="#EFD6A4" text="#000000" link="#76170C" vlink="#76170C" alink="#76170C">
<font face="verdana" size="1">
<p><b>Welcome to Barkonis shard.</b>
<?php
  define(_ROOT,dirname(__FILE__));
  require_once "lib/DBsetup.php";
?>
<a name="welcome">
<br/><br/>
This server is owned by Khoufou and is running on a Shuttle Athlon64 3200+ 1GB RAM, over an 10Mb/800Kb DSL line.
<br/><br/>
There is a <a href="http://barkonis.dyndns.org/urutopia"><b>Barkonis Wiki</b></a>
only available in french language.
<br/><br/>
This server is self-backping at 5am GMT+1, so for a couple of minutes it is down.
<br/><br/>
<br/><br/>
<?php
  $numplayers = $db->getOne("SELECT count(*) FROM Nodes WHERE NodeType=23 AND Int32_1 = 1");
  if ($numplayers == "0")
    print("No players connected at this time");
  else {
    print("$numplayers players are online:<br/><br/>");
    print "<table align='center'><thead>";
    print "<tr><td align='center'>Player</td><td align='center'>Ki</td><td align='center'>Location</td></tr></thead>";
    $res =& $db->query("SELECT OwnerIdx,IString64_1,String64_1 FROM Nodes WHERE NodeType=23 AND Int32_1 = 1 ORDER BY IString64_1");
    if (DB::isError($res)) {
      print "<h1>Error: ".$res->getMessage()."</h1>";
      exit;
    }
    print "<tbody>";
    while ($row =& $res->fetchRow()) {
      if ($row['IString64_1'] != '') {
        printf ("<tr><td align='center'>%s</td><td align='center'>%d<td align='center'>%s</td></tr>",$row['IString64_1'],$row['OwnerIdx'],$row['String64_1']);
      }
    }
    print "</tbody></table>";
  }
?>
</body>
</html>

DBsetup.php

<?php
    require_once "DB.php";

    $db =& DB::connect(
        "mysql://username:password@localhost/your_vault_database_name",
        array('persistent'=>true)
    );
    if (DB::isError($db)) {
        print "<h1>Error connecting to database<h1>\n";
        exit;
    }
    $db->setFetchMode(DB_FETCHMODE_ASSOC);
?>

---

Submitted by - KhouFou

PhpScripts/ShowPlayers (last edited 2008-12-27 16:35:30 by localhost)