PDA

View Full Version : Server Status Web Page


cubber
08-27-2008, 11:00 AM
I am looking for a simple script that I can put on a web page that will display the server's status (ie. UP or DOWN) and maybe include an uptime report.

I would also like it to display a list of currently logged in characters with level/race/class and zone info.

Does anyone have something like this currently in the works?

Thanks!

cybernine186
08-27-2008, 11:23 AM
You can use a PHP Telnet script to get that information. However you will need telnet functions turned on the eq server.

If you are familiar with PHP scripting I will post a section of code for you to use. However you will need to edit the code for what suites you. If you are not familiar with PHP I would try and find someone that is.

cubber
08-27-2008, 11:28 AM
Thanks for the reply, I am working on learning php, and currently have a basic understanding of it. I would not mind checking out the code and seeing if I can make sense of it.

To turn on the telnet function I just edit the server's xml file correct?

Thanks.

Flare83
08-27-2008, 12:23 PM
i would be interested in the php code also, if it's not too much trouble that is =).

cybernine186
08-27-2008, 04:58 PM
This is a partial code from my new EQ Editor release fixing to come out. This is built in a class, have fun. Feel free to ask questions.


Also some of the telnet code I copied from someone else, I have changed most of it but the majority is still intact.

class telnet {

// Variables
var $message = array();
var $connection;

// Connects to the World Telnet Server
function connect(){
global $cfg;

// Open Socket Connection
$this->connection = fsockopen($cfg['telnet']['address'], $cfg['telnet']['port']);

if(!$this->connection){
$this->message[] = "Error connecting to World Telnet Server";
return false;
}else{
fputs($this->connection, sprintf("%s\r", unserialize($_SESSION['EQ_EDT_USR'])));
usleep(125000);
fputs($this->connection, sprintf("%s\r", unserialize($_SESSION['EQ_EDT_PWD'])));
usleep(125000);
return true;
}
}


// Close the Telnet Connection
function close(){
fclose($this->connection);
}


// Server Uptime
function uptime(){
fputs ($this->connection, "uptime\r");
usleep(125000);

while (!feof($this->connection)){
$ret = fgets($this->connection);
if (ereg("Uptime", $ret)) {
$ret = str_replace("$user", "", $ret);
return str_replace(">", "", $ret);
break;
}
}
}


// Zone Status
function zonestatus($zone=''){
fputs ($this->connection, sprintf("zonestatus %s\r", $zone));
usleep(125000);

while(!feof($this->connection)){
$ret = fgets($this->connection);

if (ereg("$Server:", $ret)){
echo "$ret \n <br>";
}

if(ereg("avail", $ret)){
echo "$ret \n <br>";
break;
}
}
}

// Kick Character from World Server
function kick($character, $message='YOU ARE BEING KICKED FROM THE SERVER IN 4 SECONDS'){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(4);
fputs($this->connection, sprintf("kick %s\r", $character));
$this->message[] = "Character has been kicked from server";
sleep(1);
}


// Send Character a Tell
function tell($character, $message){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(1);
$this->message[] = sprintf("Message Sent to Character: %s", $character);
}


// Send Server a OOC Message
function ooc($message){
fputs($this->connection, sprintf("ooc %s\r", $message));
sleep(1);
$this->message[] = "Message sent to OOC";
}


// Broadcast Message Server Wide
function broadcast($message){
fputs($this->connection, sprintf("broadcast %s\r", $message));
sleep(1);
$this->message[] = "Broadcast Message Sent to World Server";
}


// Who/Who All
function whoall($who=''){

fputs ($this->connection, sprintf("who%s\r", $who));
usleep(125000);

while (!feof($this->connection)) {
$ret_tmp = fgets($this->connection);

if(ereg("zone", $ret_tmp)){
$ret[++$x] = $ret_tmp;
}

if(ereg("online", $ret_tmp)){
break;
}
}

// Process each line of the returned results
foreach ($ret as $key => $value) {

// Original Return
$players[$key]['original'] = $value;

// GM Status
if (preg_match("/\*.*\*/", $value, $matches)) {
$players[$key]['GM'] = trim($matches[0], "* ");
}

// Role/Anon, Level & Class
if (preg_match("/\[.*\]/", $value, $matches)) {
$tmp = explode(" ", trim($matches[0], "[] "));
if (!is_numeric($tmp[0])) {
$players[$key]['Visible'] = $tmp[0];
$players[$key]['Level'] = $tmp[1];
$players[$key]['Class'] = rtrim($tmp[2] . " " . $tmp[3], " ");
} else {
$players[$key]['Level'] = $tmp[0];
$players[$key]['Class'] = rtrim($tmp[1] . " " . $tmp[2], " ");
}
}

// Character's Name
if(preg_match("/\].*\(/", $value, $matches)){
$players[$key]['Name'] = trim($matches[0], "] (");
}

// Race
if(preg_match("/\(.*\)/", $value, $matches)){
$players[$key]['Race'] = trim($matches[0], "( )");
}

// Zone
if(preg_match("/zone:.*AccID:/", $value, $matches)){
$players[$key]['ZoneLong'] = substr($matches[0], 6, -7);
}

// Account ID
if(preg_match("/AccID:.*AccName:/", $value, $matches)){
$players[$key]['AcctID'] = substr($matches[0], 7, -9);
}

// Account Name
if(preg_match("/AccName:.*LSID:/", $value, $matches)){
$players[$key]['AcctName'] = substr($matches[0], 9, -6);
}

// Login Server ID
if(preg_match("/LSID:.*Status:/", $value, $matches)){
$players[$key]['LSID'] = substr($matches[0], 6, -8);
}

// Status
if(preg_match("/Status:.*/", $value, $matches)){
$players[$key]['Status'] = substr($matches[0], 8, 3);
}
}

// Return Player Array
return $players;
}

}

cubber
08-29-2008, 08:55 AM
Thanks for posting the code, seems I just get a blank page though when I load it. Currently the only things I changed were I added the php code tags, and I changed the 'address' to my eqemu server's local IP address and 'port' to '9000'. I enabled telnet in the eqemu xml config file and restarted the server. When I telnet to the server using a command prompt in windows I am able to connect and issue commands like status and who all.

I must be missing something... any ideas?

cybernine186
08-29-2008, 06:58 PM
Yea, LOTS....

This is a php class that you must call and then call each function you want performed, also you need to input your username/password.

Replace

$this->connection = fsockopen($cfg['telnet']['address'], $cfg['telnet']['port']);

with

$this->connection = fsockopen('your server ip address', 9000);

9000 is the default port, change it to match what your server's is.

Also change

fputs($this->connection, sprintf("%s\r", unserialize($_SESSION['EQ_EDT_USR'])));

and

fputs($this->connection, sprintf("%s\r", unserialize($_SESSION['EQ_EDT_PWD'])));

and replace the
unserialize($_SESSION'EQ_EDT_USR']) and unserialize($_SESSION['EQ_EDT_PWD'])


with your EQ EMU Username and Password.. This checks the account table in the database. Make sure your username and password is like this:


fputs($this->connection, sprintf("%s\r", 'username'));
fputs($this->connection, sprintf("%s\r", 'password'));


After that you need to call the class and then the functions below the script.

Example:


<?php
class telnet {

// Variables
var $message = array();
var $connection;

// Connects to the World Telnet Server
function connect(){
global $cfg;

// Open Socket Connection
$this->connection = fsockopen('127.0.0.1', 9000);

if(!$this->connection){
$this->message[] = "Error connecting to World Telnet Server";
return false;
}else{
fputs($this->connection, sprintf("%s\r", 'username'));
usleep(125000);
fputs($this->connection, sprintf("%s\r", 'password'));
usleep(125000);
return true;
}
}


// Close the Telnet Connection
function close(){
fclose($this->connection);
}


// Server Uptime
function uptime(){
fputs ($this->connection, "uptime\r");
usleep(125000);

while (!feof($this->connection)){
$ret = fgets($this->connection);
if (ereg("Uptime", $ret)) {
$ret = str_replace("$user", "", $ret);
return str_replace(">", "", $ret);
break;
}
}
}


// Zone Status
function zonestatus($zone=''){
fputs ($this->connection, sprintf("zonestatus %s\r", $zone));
usleep(125000);

while(!feof($this->connection)){
$ret = fgets($this->connection);

if (ereg("$Server:", $ret)){
echo "$ret \n <br>";
}

if(ereg("avail", $ret)){
echo "$ret \n <br>";
break;
}
}
}

// Kick Character from World Server
function kick($character, $message='YOU ARE BEING KICKED FROM THE SERVER IN 4 SECONDS'){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(4);
fputs($this->connection, sprintf("kick %s\r", $character));
$this->message[] = "Character has been kicked from server";
sleep(1);
}


// Send Character a Tell
function tell($character, $message){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(1);
$this->message[] = sprintf("Message Sent to Character: %s", $character);
}


// Send Server a OOC Message
function ooc($message){
fputs($this->connection, sprintf("ooc %s\r", $message));
sleep(1);
$this->message[] = "Message sent to OOC";
}


// Broadcast Message Server Wide
function broadcast($message){
fputs($this->connection, sprintf("broadcast %s\r", $message));
sleep(1);
$this->message[] = "Broadcast Message Sent to World Server";
}


// Who/Who All
function whoall($who=''){

fputs ($this->connection, sprintf("who%s\r", $who));
usleep(125000);

while (!feof($this->connection)) {
$ret_tmp = fgets($this->connection);

if(ereg("zone", $ret_tmp)){
$ret[++$x] = $ret_tmp;
}

if(ereg("online", $ret_tmp)){
break;
}
}

// Process each line of the returned results
foreach ($ret as $key => $value) {

// Original Return
$players[$key]['original'] = $value;

// GM Status
if (preg_match("/\*.*\*/", $value, $matches)) {
$players[$key]['GM'] = trim($matches[0], "* ");
}

// Role/Anon, Level & Class
if (preg_match("/\[.*\]/", $value, $matches)) {
$tmp = explode(" ", trim($matches[0], "[] "));
if (!is_numeric($tmp[0])) {
$players[$key]['Visible'] = $tmp[0];
$players[$key]['Level'] = $tmp[1];
$players[$key]['Class'] = rtrim($tmp[2] . " " . $tmp[3], " ");
} else {
$players[$key]['Level'] = $tmp[0];
$players[$key]['Class'] = rtrim($tmp[1] . " " . $tmp[2], " ");
}
}

// Character's Name
if(preg_match("/\].*\(/", $value, $matches)){
$players[$key]['Name'] = trim($matches[0], "] (");
}

// Race
if(preg_match("/\(.*\)/", $value, $matches)){
$players[$key]['Race'] = trim($matches[0], "( )");
}

// Zone
if(preg_match("/zone:.*AccID:/", $value, $matches)){
$players[$key]['ZoneLong'] = substr($matches[0], 6, -7);
}

// Account ID
if(preg_match("/AccID:.*AccName:/", $value, $matches)){
$players[$key]['AcctID'] = substr($matches[0], 7, -9);
}

// Account Name
if(preg_match("/AccName:.*LSID:/", $value, $matches)){
$players[$key]['AcctName'] = substr($matches[0], 9, -6);
}

// Login Server ID
if(preg_match("/LSID:.*Status:/", $value, $matches)){
$players[$key]['LSID'] = substr($matches[0], 6, -8);
}

// Status
if(preg_match("/Status:.*/", $value, $matches)){
$players[$key]['Status'] = substr($matches[0], 8, 3);
}
}

// Return Player Array
return $players;
}

}


$telnet = new telnet;
$telnet->connect();
$telnet->broadcast('This is a test message from your GM Please sign out NOW!');
$telnet->close();
?>


or you can call more than 1 function before the session is closed.
$telnet = new telnet;
$telnet->connect();
$telnet->broadcast('This is a test message from your GM Please sign out NOW!');
$telnet->kick('icantplayeq', 'I DONT LIKE YOU SO IM KICKING YOU');
$telnet->close();

cubber
09-04-2008, 12:02 PM
I made all the edits that you suggested and still end up with a blank page.

Here is my page called index.php

<?php
class telnet {

// Variables
var $message = array();
var $connection;

// Connects to the World Telnet Server
function connect(){
global $cfg;

// Open Socket Connection
$this->connection = fsockopen('192.168.2.6', 9000);

if(!$this->connection){
$this->message[] = "Error connecting to World Telnet Server";
return false;
}else{
fputs($this->connection, sprintf("%s\r", 'my-user-name'));
usleep(125000);
fputs($this->connection, sprintf("%s\r", 'my-password'));
usleep(125000);
return true;
}
}


// Close the Telnet Connection
function close(){
fclose($this->connection);
}


// Server Uptime
function uptime(){
fputs ($this->connection, "uptime\r");
usleep(125000);

while (!feof($this->connection)){
$ret = fgets($this->connection);
if (ereg("Uptime", $ret)) {
$ret = str_replace("$user", "", $ret);
return str_replace(">", "", $ret);
break;
}
}
}


// Zone Status
function zonestatus($zone=''){
fputs ($this->connection, sprintf("zonestatus %s\r", $zone));
usleep(125000);

while(!feof($this->connection)){
$ret = fgets($this->connection);

if (ereg("$Server:", $ret)){
echo "$ret \n <br>";
}

if(ereg("avail", $ret)){
echo "$ret \n <br>";
break;
}
}
}

// Kick Character from World Server
function kick($character, $message='YOU ARE BEING KICKED FROM THE SERVER IN 4 SECONDS'){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(4);
fputs($this->connection, sprintf("kick %s\r", $character));
$this->message[] = "Character has been kicked from server";
sleep(1);
}


// Send Character a Tell
function tell($character, $message){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(1);
$this->message[] = sprintf("Message Sent to Character: %s", $character);
}


// Send Server a OOC Message
function ooc($message){
fputs($this->connection, sprintf("ooc %s\r", $message));
sleep(1);
$this->message[] = "Message sent to OOC";
}


// Broadcast Message Server Wide
function broadcast($message){
fputs($this->connection, sprintf("broadcast %s\r", $message));
sleep(1);
$this->message[] = "Broadcast Message Sent to World Server";
}


// Who/Who All
function whoall($who=''){

fputs ($this->connection, sprintf("who%s\r", $who));
usleep(125000);

while (!feof($this->connection)) {
$ret_tmp = fgets($this->connection);

if(ereg("zone", $ret_tmp)){
$ret[++$x] = $ret_tmp;
}

if(ereg("online", $ret_tmp)){
break;
}
}

// Process each line of the returned results
foreach ($ret as $key => $value) {

// Original Return
$players[$key]['original'] = $value;

// GM Status
if (preg_match("/\*.*\*/", $value, $matches)) {
$players[$key]['GM'] = trim($matches[0], "* ");
}

// Role/Anon, Level & Class
if (preg_match("/\[.*\]/", $value, $matches)) {
$tmp = explode(" ", trim($matches[0], "[] "));
if (!is_numeric($tmp[0])) {
$players[$key]['Visible'] = $tmp[0];
$players[$key]['Level'] = $tmp[1];
$players[$key]['Class'] = rtrim($tmp[2] . " " . $tmp[3], " ");
} else {
$players[$key]['Level'] = $tmp[0];
$players[$key]['Class'] = rtrim($tmp[1] . " " . $tmp[2], " ");
}
}

// Character's Name
if(preg_match("/\].*\(/", $value, $matches)){
$players[$key]['Name'] = trim($matches[0], "] (");
}

// Race
if(preg_match("/\(.*\)/", $value, $matches)){
$players[$key]['Race'] = trim($matches[0], "( )");
}

// Zone
if(preg_match("/zone:.*AccID:/", $value, $matches)){
$players[$key]['ZoneLong'] = substr($matches[0], 6, -7);
}

// Account ID
if(preg_match("/AccID:.*AccName:/", $value, $matches)){
$players[$key]['AcctID'] = substr($matches[0], 7, -9);
}

// Account Name
if(preg_match("/AccName:.*LSID:/", $value, $matches)){
$players[$key]['AcctName'] = substr($matches[0], 9, -6);
}

// Login Server ID
if(preg_match("/LSID:.*Status:/", $value, $matches)){
$players[$key]['LSID'] = substr($matches[0], 6, -8);
}

// Status
if(preg_match("/Status:.*/", $value, $matches)){
$players[$key]['Status'] = substr($matches[0], 8, 3);
}
}

// Return Player Array
return $players;
}

}

$telnet = new telnet;
$telnet->connect();
$telnet->broadcast('This is a test message from the GM Please sign out NOW!');
$telnet->close();
?>

cybernine186
09-04-2008, 06:01 PM
You are supposed to end up with a blank page.... There is nothing that is supposed to print out on the screen. All that I gave you is basically the "back end" of a program/script.

The real question is did it work for you? It should have, next time log in to the server and then run this script once more and see if it shows up in EQ...

Also you might be missing something in PHP or apache or something..


Look in your error logs to see if this script had an error.

Yeormom
09-11-2008, 11:54 AM
Thanks for the contribution cybernine186.

cubber
09-18-2008, 01:37 PM
I have been trying to figure out how I go about using this "back end" script to display the server status on a web page but keep coming up blank. Do you mind shedding some insight on how this would be accomplished. I would guess that I would need to call this script within the webpage somehow to have it display the data.

I am still new to PHP. Like I said before I would only like to display server status, uptime, and a list of currently logged in characters with lvl/class info.

Thanks again.

spoon
09-18-2008, 02:27 PM
I have been trying to figure out how I go about using this "back end" script to display the server status on a web page but keep coming up blank. Do you mind shedding some insight on how this would be accomplished. I would guess that I would need to call this script within the webpage somehow to have it display the data.

I am still new to PHP. Like I said before I would only like to display server status, uptime, and a list of currently logged in characters with lvl/class info.

Thanks again.

You might try something like:

$telnet = new telnet;
if($telnet->connect() ) {
// We are connected... yay!
echo "<h1>Server is <span style='background-color:green;'>UP</h1><p>" . $telnet->uptime() . "</p>";
} else {
// OH NOS!
echo "<h1>Server is <span style='background-color:red;'>DOWN</h1><p>" . $telnet->message[0] ."</p>";
}

spoon
09-18-2008, 02:58 PM
saw you wanted the players on as well:

<?php
$telnet = new telnet;
if($telnet->connect() ) {
// We are connected... yay!
echo "<h1>Server is <span style='background-color:green;'>UP</span></h1>";
echo "<p>" . $telnet->uptime() . "</p>";
echo "<table><tr><td>Name</td><td>Zone</td></tr>";
$players = $telnet->whoall();
foreach( array_keys($players) as $key) {
echo "<tr><td>" . $players[$key]['Name'] . "</td><td>" . $players[$key]['ZoneLong'] . "</td><tr>";
}
echo "</table>";
} else {
// OH NOS!
echo "<h1>Server is <span style='background-color:red;'>DOWN</span></h1><p>" . $telnet->message[0] ."</p>";
}
?>

cubber
09-18-2008, 03:18 PM
Spoon,

Thank you for that it looks perfect, but I am having issues integrating it. I tried to use the top part of the above script for the connection and authentication but it errored out at the beginning of your script. Here is what it looks like, I am sure I am doing something wrong.

<?php
class telnet {

// Variables
var $message = array();
var $connection;

// Connects to the World Telnet Server
function connect(){
global $cfg;

// Open Socket Connection
$this->connection = fsockopen('192.168.0.4', 9000);

if(!$this->connection){
$this->message[] = "Error connecting to World Telnet Server";
return false;
}else{
fputs($this->connection, sprintf("%s\r", 'username'));
usleep(125000);
fputs($this->connection, sprintf("%s\r", 'password'));
usleep(125000);
return true;
}
}

$telnet = new telnet;
if($telnet->connect() ) {
// We are connected... yay!
echo "<h1>Server is <span style='background-color:green;'>UP</span></h1>";
echo "<p>" . $telnet->uptime() . "</p>";
echo "<table><tr><td>Name</td><td>Zone</td></tr>";
$players = $telnet->whoall();
foreach( array_keys($players) as $key) {
echo "<tr><td>" . $players[$key]['Name'] . "</td><td>" . $players[$key]['ZoneLong'] . "</td><tr>";
}
echo "</table>";
} else {
// OH NOS!
echo "<h1>Server is <span style='background-color:red;'>DOWN</span></h1><p>" . $telnet->message[0] ."</p>";
}
?>


And the error i get if I run php eqstatus.php from a command line on the server.

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /var/www/localhost/htdocs/game-servers/eq/status/eqstatus.php on line 27

spoon
09-18-2008, 03:30 PM
You have a couple syntax errors. You didn't close out the class and were missing a required function in that class. Here is a more complete file. Don't forget to change the USER_NAME and PASSWORD.

<?php

class telnet {

// Variables
var $message = array();
var $connection;

// Connects to the World Telnet Server
function connect(){

// Open Socket Connection
$this->connection = fsockopen('127.0.0.1', 9000);

if(!$this->connection){
$this->message[] = "Error connecting to World Telnet Server";
return false;
}else{
fputs($this->connection, sprintf("%s\r", 'USER_NAME'));
usleep(125000);
fputs($this->connection, sprintf("%s\r", 'PASSWORD'));
usleep(125000);
return true;
}
}


// Close the Telnet Connection
function close(){
fclose($this->connection);
}


// Server Uptime
function uptime(){
fputs ($this->connection, "uptime\r");
usleep(125000);

while (!feof($this->connection)){
$ret = fgets($this->connection);
if (ereg("Uptime", $ret)) {
$ret = str_replace("$user", "", $ret);
return str_replace(">", "", $ret);
break;
}
}
}


// Zone Status
function zonestatus($zone=''){
fputs ($this->connection, sprintf("zonestatus %s\r", $zone));
usleep(125000);

while(!feof($this->connection)){
$ret = fgets($this->connection);

if (ereg("$Server:", $ret)){
echo "$ret \n <br>";
}

if(ereg("avail", $ret)){
echo "$ret \n <br>";
break;
}
}
}

// Kick Character from World Server
function kick($character, $message='YOU ARE BEING KICKED FROM THE SERVER IN 4 SECONDS'){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(4);
fputs($this->connection, sprintf("kick %s\r", $character));
$this->message[] = "Character has been kicked from server";
sleep(1);
}


// Send Character a Tell
function tell($character, $message){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(1);
$this->message[] = sprintf("Message Sent to Character: %s", $character);
}


// Send Server a OOC Message
function ooc($message){
fputs($this->connection, sprintf("ooc %s\r", $message));
sleep(1);
$this->message[] = "Message sent to OOC";
}


// Broadcast Message Server Wide
function broadcast($message){
fputs($this->connection, sprintf("broadcast %s\r", $message));
sleep(1);
$this->message[] = "Broadcast Message Sent to World Server";
}


// Who/Who All
function whoall($who=''){

fputs ($this->connection, sprintf("who%s\r", $who));
usleep(125000);

while (!feof($this->connection)) {
$ret_tmp = fgets($this->connection);

if(ereg("zone", $ret_tmp)){
$ret[++$x] = $ret_tmp;
}

if(ereg("online", $ret_tmp)){
break;
}
}

// Process each line of the returned results
foreach ($ret as $key => $value) {

// Original Return
$players[$key]['original'] = $value;

// GM Status
if (preg_match("/\*.*\*/", $value, $matches)) {
$players[$key]['GM'] = trim($matches[0], "* ");
}

// Role/Anon, Level & Class
if (preg_match("/\[.*\]/", $value, $matches)) {
$tmp = explode(" ", trim($matches[0], "[] "));
if (!is_numeric($tmp[0])) {
$players[$key]['Visible'] = $tmp[0];
$players[$key]['Level'] = $tmp[1];
$players[$key]['Class'] = rtrim($tmp[2] . " " . $tmp[3], " ");
} else {
$players[$key]['Level'] = $tmp[0];
$players[$key]['Class'] = rtrim($tmp[1] . " " . $tmp[2], " ");
}
}

// Character's Name
if(preg_match("/\].*\(/", $value, $matches)){
$players[$key]['Name'] = trim($matches[0], "] (");
}

// Race
if(preg_match("/\(.*\)/", $value, $matches)){
$players[$key]['Race'] = trim($matches[0], "( )");
}

// Zone
if(preg_match("/zone:.*AccID:/", $value, $matches)){
$players[$key]['ZoneLong'] = substr($matches[0], 6, -7);
}

// Account ID
if(preg_match("/AccID:.*AccName:/", $value, $matches)){
$players[$key]['AcctID'] = substr($matches[0], 7, -9);
}

// Account Name
if(preg_match("/AccName:.*LSID:/", $value, $matches)){
$players[$key]['AcctName'] = substr($matches[0], 9, -6);
}

// Login Server ID
if(preg_match("/LSID:.*Status:/", $value, $matches)){
$players[$key]['LSID'] = substr($matches[0], 6, -8);
}

// Status
if(preg_match("/Status:.*/", $value, $matches)){
$players[$key]['Status'] = substr($matches[0], 8, 3);
}
}

// Return Player Array
return $players;
}

}

$telnet = new telnet;
if($telnet->connect() ) {
// We are connected... yay!
echo "<h1>Server is <span style='background-color:green;'>UP</span></h1>";
echo "<p>" . $telnet->uptime() . "</p>";
echo "<table><tr><td>Name</td><td>Zone</td></tr>";
$players = $telnet->whoall();
foreach( array_keys($players) as $key) {
echo "<tr><td>" . $players[$key]['Name'] . "</td><td>" . $players[$key]['ZoneLong'] . "</td><tr>";
}
echo "</table>";
} else {
// OH NOS!
echo "<h1>Server is <span style='background-color:red;'>DOWN</span></h1><p>" . $telnet->message[0] ."</p>";
}
?>

cubber
09-18-2008, 03:38 PM
oooo closer... but still some errors. I used exactly what you posted but changed the IP address and the username / password. Here is what I get when I browse to the page.

Server is UP

USER_NAME uptime Worldserver Uptime: 01d 06h 00m 47s

Warning: Invalid argument supplied for foreach() in /var/www/localhost/htdocs/game-servers/eq/status/eqstatus.php on line 122

Warning: array_keys() [function.array-keys]: The first argument should be an array in /var/www/localhost/htdocs/game-servers/eq/status/eqstatus.php on line 194

Warning: Invalid argument supplied for foreach() in /var/www/localhost/htdocs/game-servers/eq/status/eqstatus.php on line 194
Name Zone

It actually displays the username on the page. Where I put USER_NAME. It is however displaying the UP and uptime correctly.

Note: I can't log in a character for a few hours till I get home. So can't test that yet.

spoon
09-18-2008, 03:52 PM
Are there any players on your server right now?

give me a sec and I'll add a case for if there is nobody one and it wont list those warnings

cubber
09-18-2008, 03:53 PM
no players at the moment.

spoon
09-18-2008, 04:01 PM
updated:

added check on line 121-3
added check on line 189
added class and level to player table


<?php

class telnet {

// Variables
var $message = array();
var $connection;

// Connects to the World Telnet Server
function connect(){

// Open Socket Connection
$this->connection = fsockopen('127.0.0.1', 9000);

if(!$this->connection){
$this->message[] = "Error connecting to World Telnet Server";
return false;
}else{
fputs($this->connection, sprintf("%s\r", 'USER_NAME'));
usleep(125000);
fputs($this->connection, sprintf("%s\r", 'PASSWORD'));
usleep(125000);
return true;
}
}


// Close the Telnet Connection
function close(){
fclose($this->connection);
}


// Server Uptime
function uptime(){
fputs ($this->connection, "uptime\r");
usleep(125000);

while (!feof($this->connection)){
$ret = fgets($this->connection);
if (ereg("Uptime", $ret)) {
$ret = str_replace("$user", "", $ret);
return str_replace(">", "", $ret);
break;
}
}
}


// Zone Status
function zonestatus($zone=''){
fputs ($this->connection, sprintf("zonestatus %s\r", $zone));
usleep(125000);

while(!feof($this->connection)){
$ret = fgets($this->connection);

if (ereg("$Server:", $ret)){
echo "$ret \n <br>";
}

if(ereg("avail", $ret)){
echo "$ret \n <br>";
break;
}
}
}

// Kick Character from World Server
function kick($character, $message='YOU ARE BEING KICKED FROM THE SERVER IN 4 SECONDS'){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(4);
fputs($this->connection, sprintf("kick %s\r", $character));
$this->message[] = "Character has been kicked from server";
sleep(1);
}


// Send Character a Tell
function tell($character, $message){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(1);
$this->message[] = sprintf("Message Sent to Character: %s", $character);
}


// Send Server a OOC Message
function ooc($message){
fputs($this->connection, sprintf("ooc %s\r", $message));
sleep(1);
$this->message[] = "Message sent to OOC";
}


// Broadcast Message Server Wide
function broadcast($message){
fputs($this->connection, sprintf("broadcast %s\r", $message));
sleep(1);
$this->message[] = "Broadcast Message Sent to World Server";
}


// Who/Who All
function whoall($who=''){

fputs ($this->connection, sprintf("who%s\r", $who));
usleep(125000);

while (!feof($this->connection)) {
$ret_tmp = fgets($this->connection);

if(ereg("zone", $ret_tmp)){
$ret[++$x] = $ret_tmp;
}

if(ereg("online", $ret_tmp)){
break;
}
}

if( !is_array($ret) ) {
return;
}

// Process each line of the returned results
foreach ($ret as $key => $value) {

// Original Return
$players[$key]['original'] = $value;

// GM Status
if (preg_match("/\*.*\*/", $value, $matches)) {
$players[$key]['GM'] = trim($matches[0], "* ");
}

// Role/Anon, Level & Class
if (preg_match("/\[.*\]/", $value, $matches)) {
$tmp = explode(" ", trim($matches[0], "[] "));
if (!is_numeric($tmp[0])) {
$players[$key]['Visible'] = $tmp[0];
$players[$key]['Level'] = $tmp[1];
$players[$key]['Class'] = rtrim($tmp[2] . " " . $tmp[3], " ");
} else {
$players[$key]['Level'] = $tmp[0];
$players[$key]['Class'] = rtrim($tmp[1] . " " . $tmp[2], " ");
}
}

// Character's Name
if(preg_match("/\].*\(/", $value, $matches)){
$players[$key]['Name'] = trim($matches[0], "] (");
}

// Race
if(preg_match("/\(.*\)/", $value, $matches)){
$players[$key]['Race'] = trim($matches[0], "( )");
}

// Zone
if(preg_match("/zone:.*AccID:/", $value, $matches)){
$players[$key]['ZoneLong'] = substr($matches[0], 6, -7);
}

// Account ID
if(preg_match("/AccID:.*AccName:/", $value, $matches)){
$players[$key]['AcctID'] = substr($matches[0], 7, -9);
}

// Account Name
if(preg_match("/AccName:.*LSID:/", $value, $matches)){
$players[$key]['AcctName'] = substr($matches[0], 9, -6);
}

// Login Server ID
if(preg_match("/LSID:.*Status:/", $value, $matches)){
$players[$key]['LSID'] = substr($matches[0], 6, -8);
}

// Status
if(preg_match("/Status:.*/", $value, $matches)){
$players[$key]['Status'] = substr($matches[0], 8, 3);
}
}

// Return Player Array
return $players;
}

}
Class

$telnet = new telnet;
if($telnet->connect() ) {
// We are connected... yay!
echo "<h1>Server is <span style='background-color:green;'>UP</span></h1>";
echo "<p>" . $telnet->uptime() . "</p>";
$players = $telnet->whoall();
if( is_array($players) ) {
echo "<table><tr><td>Name</td><td>Class</td><td>Level</td><td>Zone</td></tr>";
foreach( array_keys($players) as $key) {
echo "<tr><td>" . $players[$key]['Name'] . "</td>";
echo "<td>" . $players[$key]['Class']. "</td>";
echo "<td>" . $players[$key]['Level']. "</td>";
echo "<td>" . $players[$key]['ZoneLong']. "</td><tr>";
}
echo "</table>";
} else {
echo "<p>Nobody is on</p>";
}

} else {
// OH NOS!
echo "<h1>Server is <span style='background-color:red;'>DOWN</span></h1><p>" . $telnet->message[0] ."</p>";
}
?>

cubber
09-18-2008, 04:09 PM
nope just a big:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in /var/www/localhost/htdocs/game-servers/eq/status/eqstatus.php on line 192

On the page. Not getting any of the uptime stuff now either. When I put it in gedit the colors of some of the text is not right. Something may not be closed right? I dunno, like I said I am just finishing up learning html and starting to move into php.

spoon
09-18-2008, 04:12 PM
nope just a big:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in /var/www/localhost/htdocs/game-servers/eq/status/eqstatus.php on line 192

On the page. Not getting any of the uptime stuff now either.

Oups! somehow "Class" made its way onto line 192. Removed:


<?php

class telnet {

// Variables
var $message = array();
var $connection;

// Connects to the World Telnet Server
function connect(){

// Open Socket Connection
$this->connection = fsockopen('127.0.0.1', 9000);

if(!$this->connection){
$this->message[] = "Error connecting to World Telnet Server";
return false;
}else{
fputs($this->connection, sprintf("%s\r", 'USER_NAME'));
usleep(125000);
fputs($this->connection, sprintf("%s\r", 'PASSWORD'));
usleep(125000);
return true;
}
}


// Close the Telnet Connection
function close(){
fclose($this->connection);
}


// Server Uptime
function uptime(){
fputs ($this->connection, "uptime\r");
usleep(125000);

while (!feof($this->connection)){
$ret = fgets($this->connection);
if (ereg("Uptime", $ret)) {
$ret = str_replace("$user", "", $ret);
return str_replace(">", "", $ret);
break;
}
}
}


// Zone Status
function zonestatus($zone=''){
fputs ($this->connection, sprintf("zonestatus %s\r", $zone));
usleep(125000);

while(!feof($this->connection)){
$ret = fgets($this->connection);

if (ereg("$Server:", $ret)){
echo "$ret \n <br>";
}

if(ereg("avail", $ret)){
echo "$ret \n <br>";
break;
}
}
}

// Kick Character from World Server
function kick($character, $message='YOU ARE BEING KICKED FROM THE SERVER IN 4 SECONDS'){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(4);
fputs($this->connection, sprintf("kick %s\r", $character));
$this->message[] = "Character has been kicked from server";
sleep(1);
}


// Send Character a Tell
function tell($character, $message){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(1);
$this->message[] = sprintf("Message Sent to Character: %s", $character);
}


// Send Server a OOC Message
function ooc($message){
fputs($this->connection, sprintf("ooc %s\r", $message));
sleep(1);
$this->message[] = "Message sent to OOC";
}


// Broadcast Message Server Wide
function broadcast($message){
fputs($this->connection, sprintf("broadcast %s\r", $message));
sleep(1);
$this->message[] = "Broadcast Message Sent to World Server";
}


// Who/Who All
function whoall($who=''){

fputs ($this->connection, sprintf("who%s\r", $who));
usleep(125000);

while (!feof($this->connection)) {
$ret_tmp = fgets($this->connection);

if(ereg("zone", $ret_tmp)){
$ret[++$x] = $ret_tmp;
}

if(ereg("online", $ret_tmp)){
break;
}
}

if( !is_array($ret) ) {
return;
}

// Process each line of the returned results
foreach ($ret as $key => $value) {

// Original Return
$players[$key]['original'] = $value;

// GM Status
if (preg_match("/\*.*\*/", $value, $matches)) {
$players[$key]['GM'] = trim($matches[0], "* ");
}

// Role/Anon, Level & Class
if (preg_match("/\[.*\]/", $value, $matches)) {
$tmp = explode(" ", trim($matches[0], "[] "));
if (!is_numeric($tmp[0])) {
$players[$key]['Visible'] = $tmp[0];
$players[$key]['Level'] = $tmp[1];
$players[$key]['Class'] = rtrim($tmp[2] . " " . $tmp[3], " ");
} else {
$players[$key]['Level'] = $tmp[0];
$players[$key]['Class'] = rtrim($tmp[1] . " " . $tmp[2], " ");
}
}

// Character's Name
if(preg_match("/\].*\(/", $value, $matches)){
$players[$key]['Name'] = trim($matches[0], "] (");
}

// Race
if(preg_match("/\(.*\)/", $value, $matches)){
$players[$key]['Race'] = trim($matches[0], "( )");
}

// Zone
if(preg_match("/zone:.*AccID:/", $value, $matches)){
$players[$key]['ZoneLong'] = substr($matches[0], 6, -7);
}

// Account ID
if(preg_match("/AccID:.*AccName:/", $value, $matches)){
$players[$key]['AcctID'] = substr($matches[0], 7, -9);
}

// Account Name
if(preg_match("/AccName:.*LSID:/", $value, $matches)){
$players[$key]['AcctName'] = substr($matches[0], 9, -6);
}

// Login Server ID
if(preg_match("/LSID:.*Status:/", $value, $matches)){
$players[$key]['LSID'] = substr($matches[0], 6, -8);
}

// Status
if(preg_match("/Status:.*/", $value, $matches)){
$players[$key]['Status'] = substr($matches[0], 8, 3);
}
}

// Return Player Array
return $players;
}

}

$telnet = new telnet;
if($telnet->connect() ) {
// We are connected... yay!
echo "<h1>Server is <span style='background-color:green;'>UP</span></h1>";
echo "<p>" . $telnet->uptime() . "</p>";
$players = $telnet->whoall();
if( is_array($players) ) {
echo "<table><tr><td>Name</td><td>Class</td><td>Level</td><td>Zone</td></tr>";
foreach( array_keys($players) as $key) {
echo "<tr><td>" . $players[$key]['Name'] . "</td>";
echo "<td>" . $players[$key]['Class']. "</td>";
echo "<td>" . $players[$key]['Level']. "</td>";
echo "<td>" . $players[$key]['ZoneLong']. "</td><tr>";
}
echo "</table>";
} else {
echo "<p>Nobody is on</p>";
}

} else {
// OH NOS!
echo "<h1>Server is <span style='background-color:red;'>DOWN</span></h1><p>" . $telnet->message[0] ."</p>";
}
?>

cubber
09-18-2008, 04:17 PM
Very nice! Cant wait to go home and log on to test! Only one thing I see that could be a security risk though is that the username used to establish the telnet connection is displayed before the uptime report:

Server is ONLINE

TELNET-USERNAME uptime Worldserver Uptime: 01d 06h 39m 52s

Nobody is online

How can it be hidden?

spoon
09-18-2008, 04:33 PM
Very nice! Cant wait to go home and log on to test! Only one thing I see that could be a security risk though is that the username used to establish the telnet connection is displayed before the uptime report:

Server is ONLINE

TELNET-USERNAME uptime Worldserver Uptime: 01d 06h 39m 52s

Nobody is online

How can it be hidden?

Haven't properly tested the regex, but try this:

<?php

class telnet {

// Variables
var $message = array();
var $connection;

// Connects to the World Telnet Server
function connect(){

// Open Socket Connection
$this->connection = fsockopen('127.0.0.1', 9000);

if(!$this->connection){
$this->message[] = "Error connecting to World Telnet Server";
return false;
}else{
fputs($this->connection, sprintf("%s\r", 'USER_NAME'));
usleep(125000);
fputs($this->connection, sprintf("%s\r", 'PASSWORD'));
usleep(125000);
return true;
}
}


// Close the Telnet Connection
function close(){
fclose($this->connection);
}


// Server Uptime
function uptime(){
fputs ($this->connection, "uptime\r");
usleep(125000);

while (!feof($this->connection)){
$ret = fgets($this->connection);
if (ereg("Uptime", $ret)) {
$ret = str_replace("$user", "", $ret);
return str_replace(">", "", $ret);
break;
}
}
}


// Zone Status
function zonestatus($zone=''){
fputs ($this->connection, sprintf("zonestatus %s\r", $zone));
usleep(125000);

while(!feof($this->connection)){
$ret = fgets($this->connection);

if (ereg("$Server:", $ret)){
echo "$ret \n <br>";
}

if(ereg("avail", $ret)){
echo "$ret \n <br>";
break;
}
}
}

// Kick Character from World Server
function kick($character, $message='YOU ARE BEING KICKED FROM THE SERVER IN 4 SECONDS'){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(4);
fputs($this->connection, sprintf("kick %s\r", $character));
$this->message[] = "Character has been kicked from server";
sleep(1);
}


// Send Character a Tell
function tell($character, $message){
fputs($this->connection, sprintf("tell %s %s\r", $character, $message));
sleep(1);
$this->message[] = sprintf("Message Sent to Character: %s", $character);
}


// Send Server a OOC Message
function ooc($message){
fputs($this->connection, sprintf("ooc %s\r", $message));
sleep(1);
$this->message[] = "Message sent to OOC";
}


// Broadcast Message Server Wide
function broadcast($message){
fputs($this->connection, sprintf("broadcast %s\r", $message));
sleep(1);
$this->message[] = "Broadcast Message Sent to World Server";
}


// Who/Who All
function whoall($who=''){

fputs ($this->connection, sprintf("who%s\r", $who));
usleep(125000);

while (!feof($this->connection)) {
$ret_tmp = fgets($this->connection);

if(ereg("zone", $ret_tmp)){
$ret[++$x] = $ret_tmp;
}

if(ereg("online", $ret_tmp)){
break;
}
}

if( !is_array($ret) ) {
return;
}

// Process each line of the returned results
foreach ($ret as $key => $value) {

// Original Return
$players[$key]['original'] = $value;

// GM Status
if (preg_match("/\*.*\*/", $value, $matches)) {
$players[$key]['GM'] = trim($matches[0], "* ");
}

// Role/Anon, Level & Class
if (preg_match("/\[.*\]/", $value, $matches)) {
$tmp = explode(" ", trim($matches[0], "[] "));
if (!is_numeric($tmp[0])) {
$players[$key]['Visible'] = $tmp[0];
$players[$key]['Level'] = $tmp[1];
$players[$key]['Class'] = rtrim($tmp[2] . " " . $tmp[3], " ");
} else {
$players[$key]['Level'] = $tmp[0];
$players[$key]['Class'] = rtrim($tmp[1] . " " . $tmp[2], " ");
}
}

// Character's Name
if(preg_match("/\].*\(/", $value, $matches)){
$players[$key]['Name'] = trim($matches[0], "] (");
}

// Race
if(preg_match("/\(.*\)/", $value, $matches)){
$players[$key]['Race'] = trim($matches[0], "( )");
}

// Zone
if(preg_match("/zone:.*AccID:/", $value, $matches)){
$players[$key]['ZoneLong'] = substr($matches[0], 6, -7);
}

// Account ID
if(preg_match("/AccID:.*AccName:/", $value, $matches)){
$players[$key]['AcctID'] = substr($matches[0], 7, -9);
}

// Account Name
if(preg_match("/AccName:.*LSID:/", $value, $matches)){
$players[$key]['AcctName'] = substr($matches[0], 9, -6);
}

// Login Server ID
if(preg_match("/LSID:.*Status:/", $value, $matches)){
$players[$key]['LSID'] = substr($matches[0], 6, -8);
}

// Status
if(preg_match("/Status:.*/", $value, $matches)){
$players[$key]['Status'] = substr($matches[0], 8, 3);
}
}

// Return Player Array
return $players;
}

}

$telnet = new telnet;
if($telnet->connect() ) {
// We are connected... yay!
echo "<h1>Server is <span style='background-color:green;'>UP</span></h1>";
$uptime = $telnet->uptime();
$uptime = preg_replace( '/^.*:/','' , $uptime );
echo "<p> Uptime: " . $uptime . "</p>";
$players = $telnet->whoall();
if( is_array($players) ) {
echo "<table><tr><td>Name</td><td>Class</td><td>Level</td><td>Zone</td></tr>";
foreach( array_keys($players) as $key) {
echo "<tr><td>" . $players[$key]['Name'] . "</td>";
echo "<td>" . $players[$key]['Class']. "</td>";
echo "<td>" . $players[$key]['Level']. "</td>";
echo "<td>" . $players[$key]['ZoneLong']. "</td><tr>";
}
echo "</table>";
} else {
echo "<p>Nobody is on</p>";
}

} else {
// OH NOS!
echo "<h1>Server is <span style='background-color:red;'>DOWN</span></h1><p>" . $telnet->message[0] ."</p>";
}
?>

cubber
09-18-2008, 04:45 PM
Perfect! Now I get :

The EverQuest Server is ONLINE

Uptime: 01d 07h 07m 53s

Nobody is online

after a bit of text modification of course. I also linked the page to my site's css stylesheet and it blends in nicely! Final test report will be in a couple hours after I get home and log in. Thanks a bunch!

spoon
09-18-2008, 04:55 PM
Perfect! Now I get :

The EverQuest Server is ONLINE

Uptime: 01d 07h 07m 53s

Nobody is online

after a bit of text modification of course. I also linked the page to my site's css stylesheet and it blends in nicely! Final test report will be in a couple hours after I get home and log in. Thanks a bunch!

Good to hear. The true test will be to see if the player info gets displayed properly. I don't have a server to test it on, so please let me know how it goes.

Thanks,
spoon

cubber
09-18-2008, 05:48 PM
You the man!

Player Online:

The EverQuest Server is ONLINE

Uptime: 01d 08h 11m 58s
Name Class Level Zone
Shaggy Disciple 51 nexus

Player Zoning:

The EverQuest Server is ONLINE

Uptime: 01d 08h 14m 35s
Name Class Level Zone
Shaggy (Unknown) zone: Unknown 0 (null)


Player Zoned:

The EverQuest Server is ONLINE

Uptime: 01d 08h 15m 55s
Name Class Level Zone
Shaggy Disciple 51 netherbian

cybernine186
09-22-2008, 01:29 PM
Nice work...

erde
10-03-2008, 02:22 PM
I have started today to create a status server page. Its based on the one used on ascent wow servers.

current version http://codejunk.de/eq/test.xml

cubber
10-03-2008, 03:04 PM
Nice, does it list character names when they are online? Right now I am looking at it and no one is online it just shows the zone info.

erde
10-03-2008, 03:21 PM
The page is not finished yet. It will display all characters when they are online.
I will post the source when its finished!

erde
10-04-2008, 07:56 AM
live page from my server (http://codejunk.de/eq/stats.xml)
static test page with one player online (http://codejunk.de/eq/test.xml)