OpenTTDLib
[ class tree: OpenTTDLib ] [ index: OpenTTDLib ] [ all elements ]

Class: OpenTTDLib

Source Location: /includes/OpenTTDLib.php

Class Overview


OpenTTDLib a php class to query a running OpenTTD server


Author(s):

Variables

Constants

Methods



Class Details

[line 32]
OpenTTDLib a php class to query a running OpenTTD server



Tags:

author:  TrueLight <truelight@openttd.org>
author:  dihedral <dihedral@codecubes.org>
license:  GNU General Public License v2


[ Top ]


Class Variables

$_cache =  null

[line 228]



Tags:

var:  the cache object, when cacheing is enabled
access:  protected

Type:   OpenTTDLibCache


[ Top ]

$_detail =  null

[line 210]



Tags:

var:  holds the processed details from a OpenTTDLibPacket::UDP_SERVER_DETAIL_INFO packet
access:  protected

Type:   array


[ Top ]

$_has_info =

[line 234]



Tags:

var:  specifies if data is on the internal buffer
access:  protected

Type:   boolean


[ Top ]

$_info =  null

[line 204]



Tags:

var:  holds the processed information from a OpenTTDLibPacket::UDP_SERVER_RESPONSE packet
access:  protected

Type:   array


[ Top ]

$_newgrf = array()

[line 216]



Tags:

var:  holds the processed newgrf details from a OpenTTDLibPacket::UDP_SERVER_NEWGRFS packet
access:  protected

Type:   array


[ Top ]

$_newgrf_request = array()

[line 222]



Tags:

var:  id and md5sum for grf's still to be requested from the server
access:  protected

Type:   array


[ Top ]

$_packet =

[line 247]



Tags:

var:  the received packet data (@link OpenTTDLibPacket}
access:  protected

Type:   OpenTTDLibPacket


[ Top ]



Class Methods


constructor __construct [line 254]

void __construct( )

prepares the class with certain variables and values



Tags:

access:  public


[ Top ]

method checkTimeout [line 477]

boolean checkTimeout( )

check if we have timedout



Tags:

return:  false on no timeout
throws:  OpenTTDLibException if we have timedout
access:  public


[ Top ]

method clear [line 1066]

void clear( [boolean $all = false])

clears internal variables to be able to start a new query



Tags:

access:  public


Parameters:

boolean   $all   clear ALL internal data, including received packets and resetting the connection?

[ Top ]

method clearOption [line 438]

void clearOption( [mixed $option = null])

reset any previously set option - has to be called manually,

this method is not called from within the class




Tags:

access:  public


Parameters:

mixed   $option   specify an option you wish to reset, or an array of options. if null reset all set options

[ Top ]

method connect [line 268]

boolan connect( [string $host = null], [integer $port = null])

Connect to a given IP/Port



Tags:

return:  true on success
throws:  OpenTTDLibException if fsockopen fails
access:  public


Parameters:

string   $host   hostname or ip address of server to connect to
integer   $port   port the server is listening on

[ Top ]

method convertMapSet [line 1446]

mixed convertMapSet( [mixed $value = null])

converts the numbers to the appropriate mapset names and vise versa



Tags:

return:  integer if $value is string, string if $value is integer, array() if $value is null
access:  public


Parameters:

mixed   $value   number or string to be converted

[ Top ]

method convertNetLang [line 1434]

mixed convertNetLang( [mixed $value = null])

converts the numbers to the appropriate server language names and vise versa



Tags:

return:  integer if $value is string, string if $value is integer, array() if $value is null
access:  public


Parameters:

mixed   $value   number or string to be converted

[ Top ]

method convertStationType [line 1470]

mixed convertStationType( [mixed $value = null])

converts the numbers to the appropriate station type names and vise versa



Tags:

return:  integer if $value is string, string if $value is integer, array() if $value is null
access:  public


Parameters:

mixed   $value   number or string to be converted

[ Top ]

method convertVehicleType [line 1458]

mixed convertVehicleType( [mixed $value = null])

converts the numbers to the appropriate vehicle type names and vise versa



Tags:

return:  integer if $value is string, string if $value is integer, array() if $value is null
access:  public


Parameters:

mixed   $value   number or string to be converted

[ Top ]

method Date2YMD [line 1265]

array Date2YMD( integer $date)

Converts OpenTTD Date to YMD (tnx to WizKid for converting)



Tags:

return:  date in the following format: [0] = year, [1] = month [2] = day
access:  public


Parameters:

integer   $date   openttd style date

[ Top ]

method disconnect [line 303]

void disconnect( )

Disconnect from the server, but only if a connection is still open



Tags:

access:  public


[ Top ]

method getCache [line 1139]

mixed getCache( )

get the cache



Tags:

return:  if the cache is not enabled, returnes null, else instance of OpenTTDLibCache
access:  public


[ Top ]

method getDetail [line 1168]

array getDetail( )

convert $this->detail and return



Tags:

return:  converted $this->detail, though same structure
tutorial:  getDetail()
access:  public


[ Top ]

method getInfo [line 1150]

array getInfo( )

Get's the info (if any) from the internal buffer



Tags:

return:  converted info from $this->info (same structure), or an empty array
tutorial:  getInfo()
access:  public


[ Top ]

method getNewGrf [line 1186]

array getNewGrf( [ $sort = false])

get the new grf details



Tags:

return:  array of returned (or cached) newgrf data (array of objects as default behaviour)
tutorial:  getNewGrf()
access:  public


Parameters:

   $sort  

[ Top ]

method getOption [line 412]

mixed getOption( string $option)

get an option previously set with OpenTTDLib::setOption() or the respective default value

check if $option is a valid option and return it's value if set, otherwise return the options default




Tags:

return:  false if an invalid option was specified, the respective value otherwise
access:  public


Parameters:


[ Top ]

method getPacket [line 1122]

mixed &getPacket( )

get the instance of OpenTTDLibPacket which is holding the received packet data



Tags:

return:  OpenTTDLibPacket if $this->packet is an instance of it, null otherwise
access:  public


[ Top ]

method hasInfo [line 1243]

boolean hasInfo( )

check there is info on the internal buffer



Tags:

return:  true if there is info on the interneal buffer
access:  public


[ Top ]

method initCache [line 325]

void initCache( [boolean $force = false])

initialize the cache, but only if OpenTTDLib::OPTION_CACHE_NEWGRF or OpenTTDLib::OPTION_CACHE_GAME is true



Tags:

access:  public


Parameters:

boolean   $force   if $this->_cache is already an instance of OpenTTDLibCache overwrite it this does not override OpenTTDLib::OPTION_CACHE_NEWGRF or OpenTTDLib::OPTION_CACHE_GAME

[ Top ]

method isConnected [line 1112]

boolan isConnected( )

Checks if a connection is available



Tags:

return:  true if a connection is available
access:  public


[ Top ]

method isLeapYear [line 1254]

boolean isLeapYear( integer $year)

calculate if $year is a leapyear



Tags:

return:  true if $year is a leapyear, false otherwise
access:  public


Parameters:

integer   $year   year to check

[ Top ]

method processPacket [line 1027]

void processPacket( )

process the packet data accoding to the packet type we received



Tags:

see:  OpenTTDLibPacket::UDP_SERVER_RESPONSE
see:  OpenTTDLibPacket::UDP_SERVER_NEWGRFS
see:  OpenTTDLibPacket::UDP_SERVER_DETAIL_INFO
throws:  OpenTTDLibException if packt is not an instance of OpenTTDLibPacket
throws:  OpenTTDLibException if packt type is unknown
access:  public
uses:  OpenTTDLibPacket


[ Top ]

method queryServer [line 1652]

boolean queryServer( [string $host = null], [integer $port = null], [array $options = array()])

provides a simple way to query a server, this method will handle the rest for you

after this method returns, you either can fetch processed response packets from the server or an error message




Tags:

return:  false if an error was encountered
tutorial:  Easy HowTo
throws:  OpenTTDLibException if query type unknown - Note: called methods also throw this exception on any error
access:  public


Parameters:

string   $host   hostname or ip address of the server
integer   $port   port number the server is listening on
array   $options   an array of option => value pairs, see OpenTTDLib::setOption()

[ Top ]

method RecvData [line 976]

void RecvData( )

Try to receive some data, on success a new OpenTTDLibPacket Object will be stored in $this->packet



Tags:

throws:  OpenTTDLibException if OpenTTDLibPacket::sizeOK() returnes false
access:  public
uses:  OpenTTDLibPacket - to handle storeing the packet and to read data from


[ Top ]

method sendPacket [line 1091]

integer sendPacket( OpenTTDLibPacket &$packet, OpenTTDLibPacket $packet)

Send a packet



Tags:

return:  number of bytes sent
throws:  OpenTTDLibException if sending data to host fails
access:  public


Parameters:

OpenTTDLibPacket   $packet  
OpenTTDLibPacket   &$packet  

[ Top ]

method setOption [line 366]

boolean setOption( mixed $option, [mixed $value = null])

checks if the option to be set is valid, if not it is ignored

if $option is an array the method will itterate over the $key=>$value pairs where $key will be treated as if it were $option. the key of the array should be one of OpenTTDLib::OPTION_CONVERT_MAPSET, OpenTTDLib::OPTION_CONVERT_NETLANG, OpenTTDLib::OPTION_CONVERT_VEHICLETYPE, OpenTTDLib::OPTION_CONVERT_STATIONTYPE, OpenTTDLib::OPTION_QUERYTYPE, OpenTTDLib::OPTION_TIMEOUT

$value is typecased to be the same type as the respective OpenTTDLib::OPTION_DEFAULT constant




Tags:

return:  false if any specified option was invalid
access:  public


Parameters:

mixed   $option   string or array holding the separate options
mixed   $value   respective value to $option or null/omitted if $option is an array()

[ Top ]

method startTimer [line 466]

void startTimer( )

start the internal timer for checking if a timeout has occured



Tags:

access:  public


[ Top ]

method updateCache [line 341]

void updateCache( )

save the cache to it's file, if options are set, and $this->_cache is an instance of OpenTTDLibCache



Tags:

access:  public


[ Top ]


Class Constants

OPTION_CACHE_FILE =  'CACHE_FILE'

[line 60]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_CACHE_GAME =  'CACHE_GAME'

[line 59]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_CACHE_NEWGRF =  'CACHE_NEWGRF'

[line 58]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_CACHE_UPDATE =  'CACHE_UPDATE'

[line 61]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_CONVERT_MAPSET =  'CONVERT_MAPSET'

[line 51]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_CONVERT_NETLANG =  'CONVERT_NETLANG'

[line 52]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_CONVERT_STATIONTYPE =  'CONVERT_STATIONTYPE'

[line 54]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_CONVERT_VEHICLETYPE =  'CONVERT_VEHICLETYPE'

[line 53]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_DEFAULT_CACHE_FILE =  'cache.xml'

[line 80]

respective default values to the options


[ Top ]

OPTION_DEFAULT_CACHE_GAME =  false

[line 79]

respective default values to the options


[ Top ]

OPTION_DEFAULT_CACHE_NEWGRF =  true

[line 78]

respective default values to the options


[ Top ]

OPTION_DEFAULT_CACHE_UPDATE =  true

[line 81]

respective default values to the options


[ Top ]

OPTION_DEFAULT_CONVERT_MAPSET =  false

[line 71]

respective default values to the options


[ Top ]

OPTION_DEFAULT_CONVERT_NETLANG =  false

[line 72]

respective default values to the options


[ Top ]

OPTION_DEFAULT_CONVERT_STATIONTYPE =  false

[line 74]

respective default values to the options


[ Top ]

OPTION_DEFAULT_CONVERT_VEHICLETYPE =  false

[line 73]

respective default values to the options


[ Top ]

OPTION_DEFAULT_NEWGRF_MAX_REQUEST =  10

[line 76]

respective default values to the options


[ Top ]

OPTION_DEFAULT_QUERYTYPE =  self::QUERYTYPE_ALL

[line 84]

respective default values to the options


[ Top ]

OPTION_DEFAULT_RETURNTYPE =  self::RETURNTYPE_OBJECT

[line 83]

respective default values to the options


[ Top ]

OPTION_DEFAULT_TIMEOUT =  5

[line 85]

respective default values to the options


[ Top ]

OPTION_NEWGRF_MAX_REQUEST =  'NEWGRF_MAX_REQUEST'

[line 56]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_QUERYTYPE =  'QUERYTYPE'

[line 64]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_RETURNTYPE =  'RETURNTYPE'

[line 63]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

OPTION_TIMEOUT =  'TIMEOUT'

[line 65]

Option constants, use with OpenTTDLib::setOption() and OpenTTDLib::getOption()


[ Top ]

QUERYTYPE_ALL =  0

[line 38]

Query Method



Tags:


[ Top ]

QUERYTYPE_DETAIL =  2

[line 40]

Query Method



Tags:


[ Top ]

QUERYTYPE_INFO =  1

[line 39]

Query Method



Tags:


[ Top ]

QUERYTYPE_NEWGRF =  3

[line 41]

Query Method



Tags:


[ Top ]

RETURNTYPE_ARRAY =  0

[line 44]


[ Top ]

RETURNTYPE_OBJECT =  1

[line 45]


[ Top ]



Documentation generated on Wed, 29 Apr 2009 23:33:49 +0200 by phpDocumentor 1.4.2