Class Valve_RCON

Description

Valve RCON Class

Synopsis:

General Usage:

  1.  include('valve_rcon.php');
  2.  $r new Valve_RCON('secret''121.45.193.22'27015Valve_RCON::PROTO_SOURCE);
  3.  $r->connect();
  4.  $r->authenticate();
  5.  print $r->execute('status');
  6.  print $r->execute('kick user');
  7.  $->disconnect();

Traditional Lazy Usage:

  1.  include('valve_rcon.php');
  2.  $r new Valve_RCON('secret''121.45.193.22'27015Valve_RCON::PROTO_SOURCE);
  3.  print $r->execute('status');

Note: Traditional usage has performance penalties over multiple commands.

  • author: Shannon Wynter (http://fremnet.net/contact)
  • version: 1.0.0
  • copyright: Copyright (c) 2008, Shannon Wynter (Fremnet)
  • license: GPL 2.0 or greater

Located in /valve_rcon.php (line 65)


	
			
Class Constant Summary
Method Summary
Valve_RCON __construct ([string $password = ''], [string $host = '127.0.0.1'], [integer $port = 27015], [integer $protocol = self::PROTO_SOURCE])
array assemble_packets (array $packets)
void authenticate ()
string classic_read ([boolean $strip_first = true])
integer classic_timeout ([ $timout = null], integer $timeout)
void classic_write (string $string)
void connect ()
void disconnect ()
string execute (string $command)
string host ([string $host = null])
integer port ([integer $port = null])
integer protocol ([integer $protocol = null])
string smart_udp_read ()
array socket_timeout ([integer $timeout_seconds = null], [ $timeout_microseconds = null], integer $timeout_mircoseconds)
array source_read ([integer $expected_id = null], [integer $expected_packets = null])
integer source_write (integer $serverdata, [string $string1 = ''], [string $string2 = ''])
Methods
Constructor __construct (line 133)

Class Constructor

  • access: public
Valve_RCON __construct ([string $password = ''], [string $host = '127.0.0.1'], [integer $port = 27015], [integer $protocol = self::PROTO_SOURCE])
  • string $password: ('' ) The password to connect to the server with
  • string $host: ('127.0.0.1' ) The host to connect to
  • integer $port: (27015 ) The port to connect on
  • integer $protocol: (PROTO_SOURCE) The protocol to use
assemble_packets (line 384)

Assemble Packets

By default source packets are not very useful. If you pass an array of them to this function it will do it's best to aggrogate the packets into one concise response.

Return array structure

  1.  array(
  2.     'Request ID' => array(
  3.         'id'       => 'Request ID',
  4.         'response' => 'Response code',
  5.         'string1'  => 'The response string',
  6.         'string2'  => 'The null string'
  7.     )...
  8.  )

  • throws: Exception
  • access: protected
array assemble_packets (array $packets)
  • array $packets: The packets to be assembled
authenticate (line 299)

Authenticate

In the case of source, connect and send password In the case of classic, connect and ask the server to say hi back

  • throws: Exception
  • access: public
void authenticate ()
classic_read (line 557)

Classic Read

Read data from servers using the classic protocol Optionally strips that extra character from the front of the return. Not entirely sure it's a good idea to do that - as it does serve a purpose...

  • throws: Exception
  • access: protected
string classic_read ([boolean $strip_first = true])
  • boolean $strip_first: (true ) Strip that extra byte from the front
classic_timeout (line 222)

Classic Timeout Getter/Setter

Returns the current value of the classic timeout, or replaces it with a passed value.

You shouldn't need to tweak this, but it's here in case you do

  • return: The current timeout
  • access: public
integer classic_timeout ([ $timout = null], integer $timeout)
  • integer $timeout: (null ) The new timeout
  • $timout
classic_write (line 597)

Classic Write

Write data to servers using the classic protocol

  • throws: Exception
  • access: protected
void classic_write (string $string)
  • string $string: The string to send to the servr
connect (line 266)

Connect

Connect to the server

  • throws: Exception
  • access: public
void connect ()
disconnect (line 284)

Disconnect

Disconnect from the server

  • throws: Exception
  • access: public
void disconnect ()
execute (line 330)

Execute

This is the big function, this right here is the portal to the whole entire complex world that this class represents

It doesn't matter which type of rcon you are using, be it classic or source. To get somewhere in life all you have to do is execute($command)

See Valve_RCON for a synopsis

  • return: The results of that command
  • access: public
string execute (string $command)
  • string $command: The rcon command to send to the server
host (line 181)

Host Getter/Setter

Returns the current value of host, or replaces it with passed value

  • return: The current host
  • access: public
string host ([string $host = null])
  • string $host: (null ) The new host name/ip
port (line 193)

Port Getter/Setter

Returns the current value of port, or replaces it with passed value

  • return: The current port
  • access: public
integer port ([integer $port = null])
  • integer $port: (null ) The new port
protocol (line 207)

Protocol Getter/Setter

Returns the current value of protocol, or replaces it with passed value

Defined constants: PROTO_CLASSIC, PROTO_SOURCE

  • return: The current protocol
  • access: public
integer protocol ([integer $protocol = null])
  • integer $protocol: (null ) The new protocol
smart_udp_read (line 520)

Smart UDP Read

Face it, when it comes to reading UDP packets, PHP is rather dumb This gives us a slightly smarter udp read that waits for the socket to be unblocked and keeps reading until there's no more waiting data.

  • throws: Exception
  • access: protected
string smart_udp_read ()
socket_timeout (line 238)

Socket Timeout Setter/Getter

Sets the socket timeout to the number of seconds + the number of microseconds if passed otherwise just returns the current settings

  • return: (timeout_seconds, timeout_microseconds)
  • access: public
array socket_timeout ([integer $timeout_seconds = null], [ $timeout_microseconds = null], integer $timeout_mircoseconds)
  • integer $timeout_seconds: (null ) The number of seconds
  • integer $timeout_mircoseconds: (null ) The number of microseconds
  • $timeout_microseconds
source_read (line 425)

Source Read

Read data from servers using the source protocol Optionally ignores all packets that don't match the ID passed Optionally can speed up the process slightly (a few MS nothing more) by only waiting for a specific number of packets - useful if you KNOW how many packets your command is going to return, but generally not recommended. Return array structure

  1.  array(
  2.     array(
  3.         'id'       => 'Request ID',
  4.         'response' => 'Response code',
  5.         'string1'  => 'The response string',
  6.         'string2'  => 'The null string'
  7.     )...
  8.  )

  • throws: Exception
  • access: protected
array source_read ([integer $expected_id = null], [integer $expected_packets = null])
  • integer $expected_id: (null ) The id of the request/response
  • integer $expected_packets: (null ) The expected number of packets
source_write (line 472)

Source Write

Write data to servers using the source protocol

Defined constants: SERVERDATA_EXECCOMMAND, SERVERDATA_AUTH

  • return: The id of this request
  • throws: Exception
  • access: protected
integer source_write (integer $serverdata, [string $string1 = ''], [string $string2 = ''])
  • integer $serverdata: One of the above two constants...
  • string $string1: ('' ) The string to send to the server
  • string $string2: ('' ) The docs say this should stay blank
Class Constants
PROTO_CLASSIC = 1 (line 73)

Classic Protocol

Constants required for setting which protocol the class is using

PROTO_SOURCE = 2 (line 78)

Source Protocol - The default mode of operation

Constants required for setting which protocol the class is using

SERVERDATA_AUTH = 3 (line 85)

Constants used internally for talking to/from the server

SERVERDATA_AUTH_RESPONSE = 2 (line 88)

Constants used internally for talking to/from the server

SERVERDATA_EXECCOMMAND = 2 (line 84)

Constants used internally for talking to/from the server

SERVERDATA_RESPONSE_VALUE = 0 (line 87)

Constants used internally for talking to/from the server

Documentation generated on Thu, 07 Aug 2008 09:42:37 +1000 by phpDocumentor 1.3.2