• 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] OTServer Info

rena.to

TibiaKing Co-founder
Joined
Jul 20, 2010
Messages
57
Reaction score
9
Location
Brasil
Hi guys, came here to post a useful tool, made with <3 from Renato Ribeiro, Gabriel Pedro and Ranieri Althoff

Checkout the project page: http://renatorib.github.io/otinfo/

Otinfo allows you gets information from the server using sockets.

Usage
:rolleyes: 1. The first, you should include the class

Code:
include('otinfo.php');

:) 2. Next, you instantiate the variable
Code:
$server = new Otinfo('shadowcores.twifysoft.net');
Here the second parameter is optional. He is set to 7171 by default, if the switch port is not 7171
Code:
$server = new Otinfo('shadowcores.twifysoft.net', 7172);

;) 3. Finally run the execute method and got all the information
Note
that returns false if it does not connect to the server, then we will check
Code:
if ($server->execute()) {
echo 'Players online: ', $server->players['online'], '<br />';
echo 'Server location: ', $server->serverinfo['location'], '<br />';
echo 'Client version: ', $server->serverinfo['client'] , '<br />';
//these are just a few examples
} else {
echo 'Server offline';
//if execute() returns false, the server are offline
}

Cache
The class caches the information from the servers for a time of 120 seconds (default), if you want to change the time alter otinfo.php
Code:
private static $cache = 180; //seconds you want

All the example code
PHP:
<?php
include('otinfo.php');
$server = new Otinfo('shadowcores.twifysoft.net');
if ($server->execute()) {
echo 'Players online: ', $server->players['online'], '<br />';
echo 'Server location: ', $server->serverinfo['location'], '<br />';
echo 'Client version: ', $server->serverinfo['client'] , '<br />';
//these are just a few examples
} else {
echo 'Server offline';
//if execute() returns false, the server are offline
}


Download
You can download from my github repository, here: https://github.com/renatorib/otinfo
If you want to contribute, we accept pull requests :D
 
Last edited:
Nice code, I think in method "parseFromXml" You can add one more foreach loop, to avoid repeating same code :)

Code:
$atributes_array = array('serverinfo', 'owner', 'players', 'monsters', 'map', 'rates');

foreach ($atributes_array as $atribute_name){
    if (isset($array->$atribute_name)) {
        foreach ($array->$atribute_name->attributes() as $index => $value) {
            $this->attributes[$atribute_name][$index] = (string)$value;
        }
    }
}
 
Hello hellboy,
Really is a good idea for dry.
you can give a pull request with these changes? I'm a little out of time

thanks for suggestion ;)
 
Back
Top