POT
POT
POT
Main menu

Download

Forum

SVN

Prev Next

Additional routines

This tutorial describes some additional routines that might be useful for you.

Table of Contents

Toolbox

Toolbox in toolbox - in POT there is additional class called OTS_Toolbox. It contains some additional static methods that can help you developing OTServ-related applications. Baiscly there are two very simple methods.

First of them is experienceForLevel() - it calculates how many experience points are needed to advance to given experience level. As second parameter you can optionaly pass current experience points so the method will then return only remaining part of result.

Second method is levelForExperience() - it is reversed previous method which calculates which level player with given amount of experience points has. Note that this method unfortunately is not purely mathematical - in PHP there are no complex numbers (using complex number classes for this purpose would only complacate situation and even slow it down and use much more resources) which are needed to solve 3rd level polynomial equations.

Binary toolbox

There are also some routines to operate on binary numbers representation. They are not useful in OTServ however as PHP is very tolerant about variables there is a need to use some additional operations to force PHP to treat values as it should in binary operations. OTS_BinaryTools class contains some methods to make some bitwise operations possible in PHP but they won't be described as they are not OTServ-related and used only for internal encryption purposes. You can see class documentation for list of them and try them out.


Banning

Another feature of POT, which is rather quite important for OTServ is bans support. Bans can apply to players, accounts and IP numbers. Account and player classes contains ban(), unban() and isBanned() methods useage of which is clear. A bit more difficult work is with IP bans. First of all, IP bans are done using both IP number and maks bits to define entire classes of IP numbers. Second thing: there is no abstraction for IP number - IP bans are handled by POT class.

To ban IP you have to use banIP(), to unban - unbanIP(), to check if particular IP is banned - isIPBanned() and to get list of bans - bannedIPs(). banIP() and unbanIP() can get masks as additional parameters, but it won't be described as it's more advanced - if you kwno what masks are then you will know how to use it. By default masks are set to empty masks so those methods will work only with single IP address which you give them. bannedIPs() check given IP so it checks all masked ranges - it means you don't have to worry about masks using this method, this method will simply give you a boolean answer if IP is banned or not.

Toolbox class contains also two useful methods to create already filtered lists of accounts and players that are banned: bannedPlayers() and bannedAccounts().

Display drivers

Next, quite exotic POT feature are display drivers. This toolkit contains two interfaces which you can implement: IOTS_Display for database-based resources and IOTS_DataDisplay for non-database resources. You can assign instances of such interfaces to global POT scope using setDisplayDriver() for IOTS_Display instance and setDataDisplayDriver() for IOTS_DataDisplay. It will change behaviours of objects that contains __toString() magic method (most of list, DAO and single resource representation classes). After attempt to output any of such objects directly to output, or using them as string variables, they will call display driver's method and can return content which you want to display for them. It can be used for example to create templates engine by biding it on low-level with POT objects basing on pure PHP magic calls.

OTServ now stores some meta information about database in `schema_info` table. Currently it is only a database schema version, but it is suitable for further extended use. POT gives you easy access to all settings using getSchemaInfo() method:

  1. <?php
  2.  
  3. // to not repeat all that stuff
  4. include('quickstart.php');
  5.  
  6. // fetches schema info
  7. $info $ots->getSchemaInfo();
  8.  
  9. // displays database version
  10. echo 'Your database structure version is: '$info['version'];
  11.  
  12. ?>

Prev Up Next
OTAdmin client POT Server online status