kofel
Quietly
- Joined
- Aug 19, 2007
- Messages
- 74
- Reaction score
- 1
Hi!
I publish this shittish class for community.
Here is a example:
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;
}
}
?>
Code:
<?
include('path/classfile.php');
$a=new Otstatus('armia.toproste.pl');
$a->update();
echo '<pre>';
var_dump($a->parse());
echo '</pre>';
?>