You've already forked Epicnabbo-Catalogus-Updated-Daily
🆙 Fix code in somephp files an refactored and deleted deprecated code 🆙
This commit is contained in:
@@ -32,16 +32,19 @@ class RconService
|
||||
|
||||
if (! $this->socket) {
|
||||
$error = socket_strerror(socket_last_error());
|
||||
Log::error("RCON initialization failed: $error");
|
||||
Log::error("RCON initialization failed: {$error}");
|
||||
|
||||
$this->closeConnection();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 5, 'usec' => 0]);
|
||||
socket_set_option($this->socket, SOL_SOCKET, SO_SNDTIMEO, ['sec' => 5, 'usec' => 0]);
|
||||
|
||||
if (! @socket_connect($this->socket, $this->config['ip'], $this->config['port'])) {
|
||||
$error = socket_strerror(socket_last_error());
|
||||
Log::error("RCON connection failed: $error");
|
||||
Log::error("RCON connection failed: {$error}");
|
||||
|
||||
$this->closeConnection();
|
||||
|
||||
@@ -53,7 +56,7 @@ class RconService
|
||||
|
||||
private function closeConnection(): void
|
||||
{
|
||||
if ($this->socket instanceof \Socket) {
|
||||
if ($this->socket instanceof Socket) {
|
||||
socket_close($this->socket);
|
||||
}
|
||||
|
||||
@@ -70,29 +73,24 @@ class RconService
|
||||
* @throws RconConnectionException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function sendCommand(string $command, ?array $data = null)
|
||||
public function sendCommand(string $command, ?array $data = null): bool
|
||||
{
|
||||
if (! $this->isConnected) {
|
||||
$error = 'RCON command failed: Not connected';
|
||||
Log::error($error);
|
||||
|
||||
Log::error('RCON command failed: Not connected');
|
||||
$this->closeConnection();
|
||||
|
||||
return $this->isConnected;
|
||||
return false;
|
||||
}
|
||||
|
||||
$payload = json_encode(['key' => $command, 'data' => $data], JSON_THROW_ON_ERROR);
|
||||
|
||||
if (! @socket_write($this->socket, $payload, strlen($payload))) {
|
||||
$error = socket_strerror(socket_last_error($this->socket));
|
||||
Log::error("RCON command ($command) failed: $error");
|
||||
|
||||
Log::error("RCON command ({$command}) failed: {$error}");
|
||||
$this->closeConnection();
|
||||
|
||||
return $this->isConnected;
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isConnected;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,4 +252,9 @@ class RconService
|
||||
'command' => $command,
|
||||
]);
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user