POT
POT
POT
Main menu

Download

Forum

SVN

Prev Next

Server online status

This tutorial will describe how to test server status with POT.

Table of Contents

Server status class

POT contains special class to work with OTServ informational protocols. It is named OTS_ServerInfo. It associates it's instance to server connection and provides methods to retrive status information.

Sending request

OTS_ServerInfo class contains status() method which sends 'info' packet to OTS and handles results. It returns object of class OTS_InfoRespond which provides access methods for all OTServ respond info. It will return false if server is offline. Here is a simple example of this method usage:

  1. <?php
  2.  
  3. // to not repeat all that stuff
  4. include('quickstart.php');
  5.  
  6. // server and port
  7. $server '127.0.0.1';
  8. $port 7171;
  9.  
  10. // queries server of status info
  11. $info new OTS_ServerInfo($server$port);
  12. $status $info->status();
  13.  
  14. // offline
  15. if(!$status)
  16. {
  17.     echo 'Server '$server' is offline.'"\n";
  18. }
  19. // displays various info
  20. else
  21. {
  22.     echo 'Server name: '$status->getName()"\n";
  23.     echo 'Server owner: '$status->getOwner()"\n";
  24.     echo 'Players online: '$status->getOnlinePlayers()"\n";
  25.     echo 'Maximum allowed number of players: '$status->getMaxPlayers()"\n";
  26.     echo 'Required client version: '$status->getClientVersion()"\n";
  27.     echo 'All monsters: '$status->getMonstersCount()"\n";
  28.     echo 'Server message: '$status->getMOTD()"\n";
  29. }
  30.  
  31. ?>

DOM way

In case you would want to use this method for some non-SVN server which contains custom fields in respond packet you can still use it. OTS_InfoRespond class is child of DOMDocument class and doesn't overwrite it's interface neither behaviour in any way. Returned object is standard DOM document so you can work with it in standard DOM-way.

Binary protocol

Many people don't know that OTServ actualy provides two information protocol and use only XML-based one. Second one was for a long time redundant so it was ommited in POT. But lastly it was extended and provides very powerful features. In the end it provides all features that XML-based protocol.

Online players list

It is possible (eventualy) to retrive list of online players using binary protocol. You can do that using OTS_ServerInfo::players():

  1. <?php
  2.  
  3. // to not repeat all that stuff
  4. include('quickstart.php');
  5.  
  6. // server and port
  7. $server '127.0.0.1';
  8. $port 7171;
  9.  
  10. // queries server of status info
  11. $info new OTS_ServerInfo($server$port);
  12. $status $info->info(OTS_ServerStatus::REQUEST_BASIC_SERVER_INFO OTS_ServerStatus::REQUEST_OWNER_SERVER_INFO OTS_ServerStatus::REQUEST_MISC_SERVER_INFO OTS_ServerStatus::REQUEST_PLAYERS_INFO OTS_ServerStatus::REQUEST_MAP_INFO);
  13.  
  14. // offline
  15. if(!$status)
  16. {
  17.     echo 'Server '$server' is offline.'"\n";
  18. }
  19. // displays various info
  20. else
  21. {
  22.     echo 'Server name: '$status->getName()"\n";
  23.     echo 'Server owner: '$status->getOwner()"\n";
  24.     echo 'Players online: '$status->getOnlinePlayers()"\n";
  25.     echo 'Maximum allowed number of players: '$status->getMaxPlayers()"\n";
  26.     echo 'Server message: '$status->getMOTD()"\n";
  27. }
  28.  
  29. // checks if given player is online
  30. if$info->playerStatus('Hurz') )
  31. {
  32.     echo 'Hurz is online'"\n";
  33. }
  34. else
  35. {
  36.     echo 'Hurz is offline'"\n";
  37. }
  38.  
  39. // list online players
  40. foreach$info->players(as $player => $level)
  41. {
  42.     echo 'Player: '$player' at level '$level"\n";
  43. }
  44.  
  45. ?>

Online players list

As you can see it is also possible to simply check state of single character. It doesn't require huge list, just responds single byte that represents player status.


Prev Up Next
Additional routines Additional routines POT in depth