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 function is_int;
16: use function is_string;
17: use Clansuite\Capture\Protocol\ProtocolInterface;
18: use Clansuite\Capture\ServerAddress;
19: use Clansuite\Capture\ServerInfo;
20: use Override;
21:
22: /**
23: * Day of Defeat: Source protocol implementation.
24: *
25: * The Source engine uses the same A2S (Source) query protocol implemented
26: * in the `Steam` base class. This class exists to provide a distinct
27: * protocol entry for Day of Defeat: Source and to allow game-specific
28: * customizations in the future.
29: */
30: class DayOfDefeatSource extends Steam implements ProtocolInterface
31: {
32: /**
33: * Protocol name.
34: */
35: public string $name = 'Day of Defeat: Source';
36:
37: /**
38: * List of supported games.
39: *
40: * @var array<string>
41: */
42: public array $supportedGames = ['Day of Defeat: Source'];
43:
44: /**
45: * Protocol identifier.
46: */
47: public string $protocol = 'dods';
48:
49: /**
50: * Game series.
51: *
52: * @var array<string>
53: */
54: public array $game_series_list = ['Day of Defeat'];
55:
56: /**
57: * DoD:S specific port adjustment if needed (default 0).
58: */
59: protected int $port_diff = 0;
60:
61: /**
62: * Constructor.
63: */
64: public function __construct(mixed $address = null, mixed $queryport = null)
65: {
66: parent::__construct((is_string($address) ? $address : null), (is_int($queryport) ? $queryport : null));
67: }
68:
69: /**
70: * Returns a native join URI for Source games.
71: */
72: #[Override]
73: public function getNativeJoinURI(): string
74: {
75: return 'steam://connect/' . $this->address . ':' . $this->hostport;
76: }
77:
78: /**
79: * query method.
80: */
81: #[Override]
82: public function query(ServerAddress $addr): ServerInfo
83: {
84: $this->address = $addr->ip;
85: $this->queryport = $addr->port;
86: $this->query_server(true, true);
87:
88: return new ServerInfo(
89: address: $this->address,
90: queryport: $this->queryport,
91: online: $this->online,
92: gamename: $this->gamename,
93: gameversion: $this->gameversion,
94: servertitle: $this->servertitle,
95: mapname: $this->mapname,
96: gametype: $this->gametype,
97: numplayers: $this->numplayers,
98: maxplayers: $this->maxplayers,
99: rules: $this->rules,
100: players: $this->players,
101: errstr: $this->errstr,
102: );
103: }
104:
105: /**
106: * getProtocolName method.
107: */
108: #[Override]
109: public function getProtocolName(): string
110: {
111: return $this->protocol;
112: }
113:
114: /**
115: * getVersion method.
116: */
117: #[Override]
118: public function getVersion(ServerInfo $info): string
119: {
120: return $info->gameversion ?? 'unknown';
121: }
122: }
123: