Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Swat4
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 4
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 query
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getProtocolName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getVersion
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
13namespace Clansuite\ServerQuery\ServerProtocols;
14
15use Clansuite\Capture\Protocol\ProtocolInterface;
16use Clansuite\Capture\ServerAddress;
17use Clansuite\Capture\ServerInfo;
18use Override;
19
20/**
21 * SWAT 4 protocol implementation.
22 *
23 * Uses Gamespy2 query protocol.
24 */
25class Swat4 extends Gamespy2 implements ProtocolInterface
26{
27    /**
28     * Protocol name.
29     */
30    public string $name = 'Swat4';
31
32    /**
33     * List of supported games.
34     *
35     * @var array<string>
36     */
37    public array $supportedGames = ['SWAT 4'];
38
39    /**
40     * Protocol identifier.
41     */
42    public string $protocol = 'swat4';
43
44    /**
45     * Constructor.
46     */
47    public function __construct(?string $address = null, ?int $queryport = null)
48    {
49        parent::__construct($address, $queryport);
50    }
51
52    /**
53     * query method.
54     */
55    #[Override]
56    public function query(ServerAddress $addr): ServerInfo
57    {
58        // For SWAT 4, query port is game port + 1
59        $queryAddr = new ServerAddress($addr->ip, $addr->port + 1);
60
61        return parent::query($queryAddr);
62    }
63
64    /**
65     * getProtocolName method.
66     */
67    #[Override]
68    public function getProtocolName(): string
69    {
70        return $this->protocol;
71    }
72
73    /**
74     * getVersion method.
75     */
76    #[Override]
77    public function getVersion(ServerInfo $info): string
78    {
79        return $info->gameversion ?? 'unknown';
80    }
81}