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\Capture;
14:
15: /**
16: * Represents detailed information about a game server, including status, players, and configuration.
17: */
18: final class ServerInfo
19: {
20: /**
21: * Initializes server information with the provided data.
22: *
23: * @param null|string $address Server IP address
24: * @param null|int $queryport Query port number
25: * @param bool $online Whether the server is online
26: * @param null|string $gamename Name of the game
27: * @param null|string $gameversion Game version
28: * @param null|string $servertitle Server title
29: * @param null|string $mapname Current map name
30: * @param null|string $gametype Game type/mode
31: * @param int $numplayers Current number of players
32: * @param int $maxplayers Maximum number of players
33: * @param array<mixed> $rules Server rules/configuration
34: * @param array<mixed> $players List of players
35: * @param array<mixed> $channels Voice channels (for applicable games)
36: * @param null|string $errstr Error message if query failed
37: */
38: public function __construct(
39: public ?string $address = null,
40: public ?int $queryport = null,
41: public bool $online = false,
42: public ?string $gamename = null,
43: public ?string $gameversion = null,
44: public ?string $servertitle = null,
45: public ?string $mapname = null,
46: public ?string $gametype = null,
47: public int $numplayers = 0,
48: public int $maxplayers = 0,
49: public array $rules = [],
50: public array $players = [],
51: public array $channels = [],
52: public ?string $errstr = null,
53: public ?bool $password = null,
54: public ?string $name = null,
55: public ?string $map = null,
56: public ?int $players_current = null,
57: public ?int $players_max = null,
58: public ?string $version = null,
59: public ?string $motd = null,
60: ) {
61: }
62:
63: /**
64: * Converts the server information to an associative array.
65: *
66: * @return array<mixed> Server info as key-value pairs
67: */
68: public function toArray(): array
69: {
70: return [
71: 'address' => $this->address,
72: 'queryport' => $this->queryport,
73: 'online' => $this->online,
74: 'gamename' => $this->gamename,
75: 'gameversion' => $this->gameversion,
76: 'servertitle' => $this->servertitle,
77: 'mapname' => $this->mapname,
78: 'gametype' => $this->gametype,
79: 'numplayers' => $this->numplayers,
80: 'maxplayers' => $this->maxplayers,
81: 'rules' => $this->rules,
82: 'players' => $this->players,
83: 'channels' => $this->channels,
84: 'errstr' => $this->errstr,
85: 'password' => $this->password,
86: 'name' => $this->name,
87: 'map' => $this->map,
88: 'players_current' => $this->players_current,
89: 'players_max' => $this->players_max,
90: 'version' => $this->version,
91: 'motd' => $this->motd,
92: ];
93: }
94: }
95: