• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Status reporting (on.off/ppl)

kornholi

Administrator
Staff member
Administrator
Joined
May 28, 2007
Messages
1,018
Reaction score
64
Location
Chicago, USA
Well many people asked for this so I'm just taking this out of my tfscms, although I didnt use my brain to write it, but it should work..

Code:
<?php

/**
 * @author Kornholijo
 * @copyright 2007
 * @license GPL
 */

/* TODO: Maybe use domdoc to parse info? */
class Status
{
	var $hostname, $port;
	
	var $online = 0, $xmlstr;
	
	var $players, $playerspeak, $playersmax, $monsters;
	
	var $uptime_h, $uptime_m; 
	
	function Status($hostname = "localhost", $port = 7171)
	{
		$this->hostname = $hostname;
		$this->port = $port;
		$this->update();
		
	}
	function update()
	{
		$fp = @fsockopen($this->hostname, $this->port, $errno, $errstr, 3);
		if ($fp)
		{
			fwrite($fp, chr(6).chr(0).chr(255).chr(255).'info');
			
			while(!feof($fp))
				$this->xmlstr .= fgets($fp, 32);
				
			preg_match('/players online="(\d+)" max="(\d+)" peak="(\d+)"/', $this->xmlstr, $regexTmp);
			
			$this->players 	   = $regexTmp[1];
			$this->playersmax  = $regexTmp[2];
			$this->playerspeak = $regexTmp[3]; 
			
			preg_match('/monsters total="(\d+)"/', $this->xmlstr, $regexTmp);
			
			$this->monsters = $regexTmp[1];
			
			preg_match('/uptime="(\d+)"/', $this->xmlstr, $regexTmp); 
			
			$this->uptime_h = floor($regexTmp[1] / 3600); 
			$this->uptime_m = floor(($regexTmp[1] - $this->uptime_h * 3600) / 60); 
			
			$this->online = 1;
		} else {
			$this->online = 0;
		}
	}
}

$test = new Status("localhost", 7171);
echo $test->online.' are onlain FPD(((((FILHAHOS PUTA DEDDEDED))))) CeiVBOTen bekus hav munstrer manisS ==== '.$test->monsters;
?>

Sorry for the noob-alike testing :mad:...
 
Hmm... code is not clean and written for php4?
I preferre SimpleXML and PHP5.
Here is better class:
Code:
<?
//* Made by Kofel ([email protected])
//* Under GPL
//* Writed in PHP5 and used SimpleXML

class Otstatus
{
	private $OTS=array();
	private $info=array();
	public function __construct($ip,$port=7171)
	{
		$this->OTS['IP']=$ip;
		$this->OTS['PORT']=$port;
		
	}
	public function update()
	{
		$socketHandler=fsockopen($this->OTS['IP'], $this->OTS['PORT'], $errno, $errstr, 1);
		if(!$socketHandler)
		{
			return 0;
		}
		else
		{
			$tmp;
			$info = chr(6).chr(0).chr(255).chr(255).'info'; 
			fwrite($socketHandler, $info);
			while (!feof($socketHandler))
			{ 
				$tmp .= fgets($socketHandler, 1024);
			} 
			fclose($socketHandler);
			$this->info=$tmp;
			return 1;
		}
	}
	public function parse()
	{
			$xml=new SimpleXMLElement($this->info);
			$tmp=array();
			$tmp['serverinfo']['uptime']=(int)$xml->serverinfo->attributes()->uptime;
			$tmp['serverinfo']['ip']=(string)$xml->serverinfo->attributes()->ip;
			$tmp['serverinfo']['name']=(string)$xml->serverinfo->attributes()->servername;
			$tmp['serverinfo']['port']=(int)$xml->serverinfo->attributes()->port;
			$tmp['serverinfo']['location']=(string)$xml->serverinfo->attributes()->location;
			$tmp['serverinfo']['site']=(string)$xml->serverinfo->attributes()->url;
			$tmp['serverinfo']['server']=(string)$xml->serverinfo->attributes()->server;
			$tmp['serverinfo']['version']=(int)$xml->serverinfo->attributes()->version;
			$tmp['serverinfo']['client']=(int)$xml->serverinfo->attributes()->client;
			$tmp['owner']['name']=(string)$xml->owner->attributes()->name;
			$tmp['owner']['email']=(string)$xml->owner->attributes()->email;
			$tmp['players']['online']=(int)$xml->players->attributes()->online;
			$tmp['players']['max']=(int)$xml->players->attributes()->max;
			$tmp['players']['peak']=(int)$xml->players->attributes()->peak;
			$tmp['monsters']['total']=(int)$xml->monsters->attributes()->total;
			$tmp['map']['name']=(string)$xml->map->attributes()->name;
			$tmp['map']['author']=(string)$xml->map->attributes()->author;
			$tmp['map']['width']=(int)$xml->map->attributes()->width;
			$tmp['map']['height']=(int)$xml->map->attributes()->height;
			$tmp['motd']=(string)$xml->motd;
			return $tmp;
	}
}
?>
This is a example to use:
Code:
$a=new Otstatus('armia.toproste.pl');
$a->update();
echo '<pre>';
var_dump($a->parse());
echo '</pre>';

Yours,
Kofel.
 
Last edited:
@Kornholijo, this script works perfectly with TFS?

How can I install this script on my page? What include I need to put on?
 
in the Kornholijo script, how to get the
location
administrator name
and administrator email
also:
$something->monsters does not work in forgotten!
 
i cannot get eather to work....


Frist script i get this...
Code:
1 are onlain FPD(((((FILHAHOS PUTA DEDDEDED))))) CeiVBOTen bekus hav munstrer manisS ====

No idea why the script is going to it.. i know you can edit it though... any ideas?




Second Script i get nothing to show up at all...
I put it in a php script and went to it.. nothing happened.. then i tryed editing it and still couldnt get anything to show up... i really want a stinking online script... i cant even get nicaw or swela online scripts to work!!! help!
 
hmm, wrong ip? try print_r($test);


oh and yeah, mine script said theres 1 people on the server.
 
#UpUp
Fix.
PHP:
<?php

/**
 * @author Kornholijo
 * @copyright 2007
 * @license GPL
 */

/* TODO: Maybe use domdoc to parse info? */
class Status
{
	var $hostname, $port;
	
	var $online = 0, $xmlstr;
	
	var $players, $playerspeak, $playersmax, $monsters;
	
	var $uptime_h, $uptime_m; 
	
	function Status($hostname = "localhost", $port = 7171)
	{
		$this->hostname = $hostname;
		$this->port = $port;
		$this->update();
		
	}
	function update()
	{
		$fp = @fsockopen($this->hostname, $this->port, $errno, $errstr, 3);
		if ($fp)
		{
			fwrite($fp, chr(6).chr(0).chr(255).chr(255).'info');
			
			while(!feof($fp))
				$this->xmlstr .= fgets($fp, 32);
				
			preg_match('/players online="(\d+)" max="(\d+)" peak="(\d+)"/', $this->xmlstr, $regexTmp);
			
			$this->players 	   = $regexTmp[1];
			$this->playersmax  = $regexTmp[2];
			$this->playerspeak = $regexTmp[3]; 
			
			preg_match('/monsters total="(\d+)"/', $this->xmlstr, $regexTmp);
			
			$this->monsters = $regexTmp[1];
			
			preg_match('/uptime="(\d+)"/', $this->xmlstr, $regexTmp); 
			
			$this->uptime_h = floor($regexTmp[1] / 3600); 
			$this->uptime_m = floor(($regexTmp[1] - $this->uptime_h * 3600) / 60); 
			
			$this->online = 1;
		} else {
			$this->online = 0;
		}
	}
}

$test = new Status("localhost", 7171);
echo $test->online == 1 ? '.online.' : '.offline.' FPD(((((FILHAHOS PUTA DEDDEDED))))) CeiVBOTen bekus hav munstrer manisS ==== '.$test->monsters;
 
This is what I'm getting:

1 are onlain FPD(((((FILHAHOS PUTA DEDDEDED))))) CeiVBOTen bekus hav munstrer manisS ==== 13589

No clue what the last numbers are since I don't understand anything from that that language,... are those monsters or should they be players or... ?

Thanks
 
Back
Top