1 | <?php |
||
18 | class Connection |
||
19 | { |
||
20 | /** |
||
21 | * The socket used to send messages to the server. |
||
22 | * |
||
23 | * @var \Socket\Raw\Socket |
||
24 | */ |
||
25 | protected $client; |
||
26 | |||
27 | /** |
||
28 | * Current message id that is processed. |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $currentId = 0; |
||
33 | |||
34 | /** |
||
35 | * Initialize this connection. |
||
36 | * The socket client is used to send and receive actual data to the rcon server. |
||
37 | * |
||
38 | * @param Socket $client |
||
39 | * @param $password |
||
40 | */ |
||
41 | public function __construct(Socket $client, $password) |
||
46 | |||
47 | /** |
||
48 | * Send a RCON message. |
||
49 | * |
||
50 | * |
||
51 | * @param Message $message |
||
52 | * |
||
53 | * @return Message |
||
54 | */ |
||
55 | public function sendMessage(Message $message) |
||
63 | |||
64 | /** |
||
65 | * Get the response value of the server. |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | protected function getResponseMessage() |
||
101 | |||
102 | /** |
||
103 | * Authenticate with the server. |
||
104 | * |
||
105 | * @param $password |
||
106 | * |
||
107 | * @throws Exception\AuthenticationFailedException |
||
108 | */ |
||
109 | protected function authenticate($password) |
||
118 | |||
119 | /** |
||
120 | * This handles a fragmented response. |
||
121 | * (https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Multiple-packet_Responses) |
||
122 | * |
||
123 | * We basically send a RESPONSE_VALUE Message to the server to force the response of the rest of the package, |
||
124 | * until we receive another package or an empty response. |
||
125 | * |
||
126 | * All the received data is then appended to the current ResponseMessage. |
||
127 | * |
||
128 | * @param $responseMessage |
||
129 | * @throws Exception\InvalidPacketException |
||
130 | */ |
||
131 | protected function handleFragmentedResponse(Message $responseMessage) |
||
152 | } |
||
153 |