Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions player-counter/src/Models/GameQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function runQuery(Server $server): ?array
return null;
}

$ip = config('player-counter.use_alias') && is_ip($server->allocation->alias) ? $server->allocation->alias : $server->allocation->ip;
$ip = is_ipv6($ip) ? '[' . $ip . ']' : $ip;
$host = static::getQueryHost($server->allocation);
$host = is_ipv6($host) ? '[' . $host . ']' : $host;

$port = $server->allocation->port + ($this->query_port_offset ?? 0);

Expand All @@ -59,7 +59,7 @@ public function runQuery(Server $server): ?array
/** @var QueryTypeService $service */
$service = app(QueryTypeService::class);

return $service->get($this->query_type)?->process($server, $ip, $port);
return $service->get($this->query_type)?->process($server, $host, $port);
}

public static function canRunQuery(?Allocation $allocation): bool
Expand All @@ -68,8 +68,19 @@ public static function canRunQuery(?Allocation $allocation): bool
return false;
}

$ip = config('player-counter.use_alias') && is_ip($allocation->alias) ? $allocation->alias : $allocation->ip;
$host = static::getQueryHost($allocation);

return !in_array($ip, ['0.0.0.0', '::']);
return !blank($host) && !in_array($host, ['0.0.0.0', '::'], true);
}

protected static function getQueryHost(Allocation $allocation): string
{
$alias = trim((string) $allocation->alias);

if (config('player-counter.use_alias') && $alias !== '') {
return $alias;
}

return $allocation->ip;
}
}