• 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!

[PHP5][CLASS]Fast OTServ status class

kofel

Quietly
Joined
Aug 19, 2007
Messages
74
Reaction score
1
Hi!:)
I publish this shittish class for community.
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;
	}
}
?>
Here is a example:
Code:
<?
include('path/classfile.php');
$a=new Otstatus('armia.toproste.pl');
$a->update();
echo '<pre>';
var_dump($a->parse());
echo '</pre>';
?>
 
why is it fast? Did you brenchmark it? Why is it php5 dont minding the private vars? Lol.
 
Hmm... sorry that's don't be fast ;D, But i like SimpleXML and writing in objects ;P.
 
What is the purpose of this line:

include('path/classfile.php');

Thanks in advance.
 
It's supposed to be the path to the code which is in the first code block of kofels post. It includes that class so it can be used from another file.
 
Help..

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\classfile.php:39
Stack trace:
#0 C:\xampp\htdocs\classfile.php(39): SimpleXMLElement->__construct('')
#1 C:\xampp\htdocs\stats.php(6): Otstatus->parse()
#2 {main}
thrown in C:\xampp\htdocs\classfile.php on line 39
 
help, error!


Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\includes\classfile.php:39
Stack trace:
#0 C:\xampp\htdocs\includes\classfile.php(39): SimpleXMLElement->__construct('')
#1 C:\xampp\htdocs\index.php(33): Otstatus->parse()
#2 {main}
thrown in C:\xampp\htdocs\includes\classfile.php on line 39
 
The problem is you're using a 4 year old script that is outdated. Just use a script from the POT or write own classes.
 
Help..

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\classfile.php:39
Stack trace:
#0 C:\xampp\htdocs\classfile.php(39): SimpleXMLElement->__construct('')
#1 C:\xampp\htdocs\stats.php(6): Otstatus->parse()
#2 {main}
thrown in C:\xampp\htdocs\classfile.php on line 39
Did you called "update" method before parsing status info? Show me how are you using these class
 
I don't know why i can't edit my post... whatever I made little refactored code. You can found it here.

Question to moderators. Can you edit thread and add new version of code? I have forgot password to my old account ;P
 

Similar threads

Back
Top