1: <?php declare(strict_types=1);
2:
3: /**
4: * Clansuite Server Query
5: *
6: * SPDX-FileCopyrightText: 2003-2025 Jens A. Koch
7: * SPDX-License-Identifier: MIT
8: *
9: * For the full copyright and license information, please view
10: * the LICENSE file that was distributed with this source code.
11: */
12:
13: namespace Clansuite\ServerQuery\ServerProtocols;
14:
15: use Override;
16:
17: /**
18: * Implements the query protocol for Ark: Survival Evolved servers.
19: * Utilizes the Steam query protocol to retrieve server information, player lists, and game statistics.
20: */
21: class ArkSurvivalEvolved extends Steam
22: {
23: /**
24: * Protocol name.
25: */
26: public string $name = 'Ark: Survival Evolved';
27:
28: /**
29: * List of supported games.
30: *
31: * @var array<string>
32: */
33: public array $supportedGames = ['Ark: Survival Evolved'];
34:
35: /**
36: * Protocol identifier.
37: */
38: public string $protocol = 'A2S';
39:
40: /**
41: * Game series.
42: *
43: * @var array<string>
44: */
45: public array $game_series_list = ['Ark: Survival Evolved'];
46: protected int $port_diff = 19238;
47:
48: /**
49: * Constructor for Ark: Survival Evolved.
50: *
51: * @param string $address Server address
52: * @param int $port Port number (game port if autoCalculateQueryPort is true, query port if false)
53: * @param bool $autoCalculateQueryPort Whether to auto-calculate query port (default: true)
54: */
55: public function __construct(string $address, int $port, protected bool $autoCalculateQueryPort = true)
56: {
57: parent::__construct($address, $port);
58: }
59:
60: /**
61: * Returns a native join URI for Ark SE.
62: */
63: #[Override]
64: public function getNativeJoinURI(): string
65: {
66: return 'steam://connect/' . $this->address . ':' . $this->hostport;
67: }
68:
69: /**
70: * query_server method.
71: */
72: #[Override]
73: public function query_server(bool $getPlayers = true, bool $getRules = true): bool
74: {
75: if ($this->autoCalculateQueryPort) {
76: // For Ark SE, the query port is typically game_port + 19238
77: // Store original queryport and calculate the correct one
78: $originalQueryPort = $this->queryport;
79: $this->queryport = ($this->queryport ?? 0) + $this->port_diff;
80:
81: $result = parent::query_server($getPlayers, $getRules);
82:
83: // Restore original queryport
84: $this->queryport = $originalQueryPort;
85:
86: return $result;
87: }
88:
89: // Use the provided port directly as query port
90: return parent::query_server($getPlayers, $getRules);
91: }
92: }
93: