[PHP] OTServer Info

Discussion in 'Web-development' started by rena.to, May 5, 2014.

  1. rena.to

    rena.to TibiaKing Co-founder

    Joined:
    Jul 20, 2010
    Messages:
    57
    Likes Received:
    8
    Best Answers:
    0
    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 (Text):
    1. include('otinfo.php');
    :) 2. Next, you instantiate the variable
    Code (Text):
    1. $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 (Text):
    1. $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 (Text):
    1.  
    2. if ($server->execute()) {
    3. echo 'Players online: ', $server->players['online'], '<br />';
    4. echo 'Server location: ', $server->serverinfo['location'], '<br />';
    5. echo 'Client version: ', $server->serverinfo['client'] , '<br />';
    6. //these are just a few examples
    7. } else {
    8. echo 'Server offline';
    9. //if execute() returns false, the server are offline
    10. }
    11.  
    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 (Text):
    1. private static $cache = 180; //seconds you want
    All the example code
    PHP:
    1. <?php
    2. include('otinfo.php');
    3. $server = new Otinfo('shadowcores.twifysoft.net');
    4. if ($server->execute()) {
    5. echo 'Players online: ', $server->players['online'], '<br />';
    6. echo 'Server location: ', $server->serverinfo['location'], '<br />';
    7. echo 'Client version: ', $server->serverinfo['client'] , '<br />';
    8. //these are just a few examples
    9. } else {
    10. echo 'Server offline';
    11. //if execute() returns false, the server are offline
    12. }
    13.  

    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: Aug 3, 2014
    Amiroslo likes this.
  2. hellboy

    hellboy Active Member

    Joined:
    Apr 6, 2008
    Messages:
    351
    Likes Received:
    48
    Best Answers:
    1
    Nice code, I think in method "parseFromXml" You can add one more foreach loop, to avoid repeating same code :)

    Code (Text):
    1.  
    2. $atributes_array = array('serverinfo', 'owner', 'players', 'monsters', 'map', 'rates');
    3.  
    4. foreach ($atributes_array as $atribute_name){
    5.     if (isset($array->$atribute_name)) {
    6.         foreach ($array->$atribute_name->attributes() as $index => $value) {
    7.             $this->attributes[$atribute_name][$index] = (string)$value;
    8.         }
    9.     }
    10. }
    11.  
     
  3. rena.to

    rena.to TibiaKing Co-founder

    Joined:
    Jul 20, 2010
    Messages:
    57
    Likes Received:
    8
    Best Answers:
    0
    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 ;)
     
  4. hellboy

    hellboy Active Member

    Joined:
    Apr 6, 2008
    Messages:
    351
    Likes Received:
    48
    Best Answers:
    1
    I will try, but I'm not very familliar with Git Repo :D
     
  5. hellboy

    hellboy Active Member

    Joined:
    Apr 6, 2008
    Messages:
    351
    Likes Received:
    48
    Best Answers:
    1
  6. God Kenos

    God Kenos Tibia-FUN.net

    Joined:
    Jul 13, 2014
    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Thank you, really useful script.
     
  7. rena.to

    rena.to TibiaKing Co-founder

    Joined:
    Jul 20, 2010
    Messages:
    57
    Likes Received:
    8
    Best Answers:
    0
  8. Keno

    Keno <php print_r("bye"); ?>

    Joined:
    Oct 29, 2012
    Messages:
    55
    Likes Received:
    5
    Best Answers:
    0
    Dont work..
     
  9. rena.to

    rena.to TibiaKing Co-founder

    Joined:
    Jul 20, 2010
    Messages:
    57
    Likes Received:
    8
    Best Answers:
    0

Share This Page

Loading...