Skip to content

Commit 5ec6c89

Browse files
authored
Merge pull request #47 from Ruslan-700/master
See #45
2 parents ddfec79 + cf4ce34 commit 5ec6c89

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

arc.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,15 @@ private function authorize()
207207
*/
208208
protected function getResponse()
209209
{
210-
$get = function() {
211-
return substr(fread($this->socket, 102400), strlen($this->head));
212-
};
213-
214-
$output = '';
215-
do {
216-
$answer = $get();
217-
while (strpos($answer, 'RCon admin') !== false) {
218-
$answer = $get();
219-
}
220-
221-
$output .= $answer;
222-
} while (!empty($answer));
223-
210+
$output = '';
211+
212+
$temp = fread($this->socket, 102400);
213+
while ($temp)
214+
{
215+
$output .= $this->splitPacket($temp);
216+
$temp = fread($this->socket, 102400);
217+
}
218+
224219
return $output;
225220
}
226221

@@ -269,7 +264,7 @@ private function writeToSocket($message)
269264
*/
270265
private function getAuthCRC()
271266
{
272-
$authCRC = sprintf('%x', crc32(chr(255).chr(00).trim($this->rconPassword)));
267+
$authCRC = hash('crc32b', chr(255).chr(00).trim($this->rconPassword));
273268
$authCRC = array(substr($authCRC,-2,2), substr($authCRC,-4,2), substr($authCRC,-6,2), substr($authCRC,0,2));
274269

275270
return $authCRC;
@@ -284,7 +279,7 @@ private function getAuthCRC()
284279
*/
285280
private function getMsgCRC($command)
286281
{
287-
$msgCRC = sprintf('%x', crc32(chr(255).chr(01).chr(hexdec(sprintf('%01b', 0))).$command));
282+
$msgCRC = hash('crc32b', chr(255).chr(01).chr(hexdec(sprintf('%01b', 0))).$command);
288283
$msgCRC = array(substr($msgCRC,-2,2),substr($msgCRC,-4,2),substr($msgCRC,-6,2),substr($msgCRC,0,2));
289284

290285
return $msgCRC;
@@ -898,4 +893,23 @@ private function cleanList($str)
898893
{
899894
return preg_replace('/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/', '', $str);
900895
}
896+
897+
public function splitPacket( $data )
898+
{
899+
$responseCode = $this->readPackageRaw($data);
900+
901+
if ($responseCode[1] == "01")
902+
{
903+
if ($responseCode[3] !== "00")
904+
{
905+
return substr($data, 9);
906+
}
907+
else
908+
{
909+
return substr($data, 12);
910+
}
911+
}
912+
913+
return '';
914+
}
901915
}

0 commit comments

Comments
 (0)