34 lines
785 B
PHP
34 lines
785 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
class RealmStatusProbe
|
|
{
|
|
public function isOnline(string $address, int $port): bool
|
|
{
|
|
if ($address === '' || $port < 1 || $port > 65535) {
|
|
return false;
|
|
}
|
|
|
|
$host = str_contains($address, ':') && ! str_starts_with($address, '[')
|
|
? '['.$address.']'
|
|
: $address;
|
|
$timeout = max(0.1, min(3.0, (float) config('moonwell.launcher.realm_status_timeout', 0.5)));
|
|
$socket = @stream_socket_client(
|
|
'tcp://'.$host.':'.$port,
|
|
$errorCode,
|
|
$errorMessage,
|
|
$timeout,
|
|
STREAM_CLIENT_CONNECT,
|
|
);
|
|
|
|
if ($socket === false) {
|
|
return false;
|
|
}
|
|
|
|
fclose($socket);
|
|
|
|
return true;
|
|
}
|
|
}
|