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 Clansuite\Capture\Protocol\ProtocolInterface;
16: use Clansuite\Capture\ServerAddress;
17: use Clansuite\Capture\ServerInfo;
18: use Override;
19:
20: /**
21: * DayZ protocol implementation.
22: *
23: * Extends Steam protocol with DayZ specific port calculation.
24: * Query port = 27016 + floor((host_port - 2302) / 100)
25: */
26: class Dayz extends Steam implements ProtocolInterface
27: {
28: /**
29: * Protocol name.
30: */
31: public string $name = 'DayZ';
32:
33: /**
34: * List of supported games.
35: *
36: * @var array<string>
37: */
38: public array $supportedGames = ['DayZ'];
39:
40: /**
41: * Protocol identifier.
42: */
43: public string $protocol = 'dayz';
44:
45: /**
46: * Query server information.
47: *
48: * @return bool True on success, false on failure
49: */
50: #[Override]
51: public function query_server(bool $getPlayers = true, bool $getRules = true): bool
52: {
53: $result = parent::query_server($getPlayers, $getRules);
54:
55: if ($result) {
56: // For DayZ: query_port = game_port + 2714
57: // So host_port = query_port - 2714
58: $this->hostport = ($this->queryport ?? 0) - 2714;
59: }
60:
61: return $result;
62: }
63:
64: /**
65: * query method.
66: */
67: #[Override]
68: public function query(ServerAddress $addr): ServerInfo
69: {
70: $this->address = $addr->ip;
71: $this->queryport = $addr->port;
72: $this->query_server(true, true);
73:
74: return new ServerInfo(
75: address: $this->address,
76: queryport: $this->queryport,
77: online: $this->online,
78: gamename: $this->gamename,
79: gameversion: $this->gameversion,
80: servertitle: $this->servertitle,
81: mapname: $this->mapname,
82: gametype: $this->gametype,
83: numplayers: $this->numplayers,
84: maxplayers: $this->maxplayers,
85: rules: $this->rules ?? [],
86: players: $this->players ?? [],
87: errstr: $this->errstr,
88: );
89: }
90:
91: /**
92: * getProtocolName method.
93: */
94: #[Override]
95: public function getProtocolName(): string
96: {
97: return $this->protocol;
98: }
99:
100: /**
101: * getVersion method.
102: */
103: #[Override]
104: public function getVersion(ServerInfo $info): string
105: {
106: return $info->gameversion ?? 'unknown';
107: }
108: }
109: