mirror of
https://github.com/eliasstepanik/ark-ac-server-tools.git
synced 2026-01-23 23:18:28 +00:00
Check Query port when determining if server is up
This commit is contained in:
parent
9bc1f8e417
commit
e2f8a3e9c5
@ -393,6 +393,30 @@ function isTheServerRunning(){
|
|||||||
function isTheServerUp(){
|
function isTheServerUp(){
|
||||||
$lsof -i :"$ark_Port" > /dev/null
|
$lsof -i :"$ark_Port" > /dev/null
|
||||||
result=$?
|
result=$?
|
||||||
|
if [ $result -ne 0 ]; then
|
||||||
|
perl -MSocket -MFcntl -e '
|
||||||
|
my $port = int($ARGV[0]);
|
||||||
|
socket(my $socket, PF_INET, SOCK_DGRAM, 0);
|
||||||
|
setsockopt($socket, SOL_SOCKET, SO_RCVTIMEO, pack("i4", 1, 0, 0, 0));
|
||||||
|
my $sockaddr = pack_sockaddr_in($port, inet_aton("127.0.0.1"));
|
||||||
|
send($socket, "\xff\xff\xff\xffTSource Engine Query\x00", 0, $sockaddr);
|
||||||
|
my $flags = fcntl($socket, F_GETFL, 0) or exit(1);
|
||||||
|
fcntl($socket, F_SETFL, $flags | O_NONBLOCK) or exit(1);
|
||||||
|
my $data = "";
|
||||||
|
my $rin = "";
|
||||||
|
vec($rin, fileno($socket), 1) = 1;
|
||||||
|
if (select($rin, undef, undef, 0.25) >= 0) {
|
||||||
|
recv($socket, $data, 1400, 0) or exit(1);
|
||||||
|
my ($servername, $mapname, $game, $fullname, $rest) = split(/\x00/, substr($data, 6), 5);
|
||||||
|
my $maxplayers = ord(substr($rest, 3, 1));
|
||||||
|
if ($maxplayers == 0) { exit(1); }
|
||||||
|
exit(0);
|
||||||
|
} else {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
' "${ark_QueryPort}"
|
||||||
|
result=$?
|
||||||
|
fi
|
||||||
# In this case, the result is:
|
# In this case, the result is:
|
||||||
# 1 if the command fail. The port is not listenning
|
# 1 if the command fail. The port is not listenning
|
||||||
# 0 if the command succeed. The port is listenning
|
# 0 if the command succeed. The port is listenning
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user