1 | <?php |
||
13 | namespace Thedudeguy; |
||
14 | |||
15 | class Rcon { |
||
16 | private $host; |
||
17 | private $port; |
||
18 | private $password; |
||
19 | private $timeout; |
||
20 | |||
21 | private $socket; |
||
22 | |||
23 | private $authorized; |
||
24 | private $last_response; |
||
25 | |||
26 | const PACKET_AUTHORIZE = 5; |
||
27 | const PACKET_COMMAND = 6; |
||
28 | |||
29 | const SERVERDATA_AUTH = 3; |
||
30 | const SERVERDATA_AUTH_RESPONSE = 2; |
||
31 | const SERVERDATA_EXECCOMMAND = 2; |
||
32 | const SERVERDATA_RESPONSE_VALUE = 0; |
||
33 | |||
34 | /** |
||
35 | * Create a new instance of the Rcon class. |
||
36 | * |
||
37 | * @param string $host |
||
38 | * @param integer $port |
||
39 | * @param string $password |
||
40 | * @param integer $timeout |
||
41 | */ |
||
42 | public function __construct($host, $port, $password, $timeout) |
||
49 | |||
50 | /** |
||
51 | * Get the latest response from the server. |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getResponse() |
||
59 | |||
60 | /** |
||
61 | * Connect to a server. |
||
62 | * |
||
63 | * @return boolean |
||
64 | */ |
||
65 | public function connect() |
||
83 | |||
84 | /** |
||
85 | * Disconnect from server. |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | public function disconnect() |
||
94 | |||
95 | /** |
||
96 | * True if socket is connected and authorized. |
||
97 | * |
||
98 | * @return boolean |
||
99 | */ |
||
100 | public function isConnected() |
||
104 | |||
105 | /** |
||
106 | * Send a command to the connected server. |
||
107 | * |
||
108 | * @param string $command |
||
109 | * |
||
110 | * @return boolean|mixed |
||
111 | */ |
||
112 | public function sendCommand($command) |
||
132 | |||
133 | /** |
||
134 | * Log into the server with the given credentials. |
||
135 | * |
||
136 | * @return boolean |
||
137 | */ |
||
138 | private function authorize() |
||
154 | |||
155 | /** |
||
156 | * Writes a packet to the socket stream. |
||
157 | * |
||
158 | * @param $packet_id |
||
159 | * @param $packet_type |
||
160 | * @param $packet_body |
||
161 | * |
||
162 | * @return void |
||
163 | */ |
||
164 | private function writePacket($packet_id, $packet_type, $packet_body) |
||
188 | |||
189 | /** |
||
190 | * Read a packet from the socket stream. |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | private function readPacket() |
||
212 | |||
213 | // Below are the deprecated functions for reverse compatibility |
||
214 | |||
215 | /** |
||
216 | * @deprecated |
||
217 | * @see Rcon::getResponse() |
||
218 | */ |
||
219 | public function get_response() |
||
223 | |||
224 | /** |
||
225 | * @deprecated |
||
226 | * @see Rcon::isConnected() |
||
227 | */ |
||
228 | public function is_connected() |
||
232 | |||
233 | /** |
||
234 | * @deprecated |
||
235 | * @see Rcon::sendCommand() |
||
236 | */ |
||
237 | public function send_command($command) |
||
241 | } |
||
242 |
This check looks for method names that are not written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes
databaseConnectionSeeker
.