1 /** @file serverinfo.h  Information about a multiplayer server.
2  *
3  * @authors Copyright (c) 2016-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  *
5  * @par License
6  * LGPL: http://www.gnu.org/licenses/lgpl.html
7  *
8  * <small>This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at your
11  * option) any later version. This program is distributed in the hope that it
12  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
14  * General Public License for more details. You should have received a copy of
15  * the GNU Lesser General Public License along with this program; if not, see:
16  * http://www.gnu.org/licenses</small>
17  */
18 
19 #ifndef LIBDOOMSDAY_SERVERINFO_H
20 #define LIBDOOMSDAY_SERVERINFO_H
21 
22 #include "libshell.h"
23 #include <de/Record>
24 #include <de/Address>
25 #include <de/Version>
26 
27 namespace de { namespace shell {
28 
29 /**
30  * Information about a multiplayer server. @ingroup network
31  */
32 class LIBSHELL_PUBLIC ServerInfo
33 {
34 public:
35     enum Flag { AllowJoin = 0x1, DefaultFlags = AllowJoin };
36     Q_DECLARE_FLAGS(Flags, Flag)
37 
38     ServerInfo();
39     ServerInfo(ServerInfo const &other);
40     ServerInfo(Record const &rec);
41     ServerInfo &operator=(ServerInfo const &other);
42 
43     Version version() const;
44     int     compatibilityVersion() const;
45 
46     Address    address() const;
47     String     domainName() const;
48     duint16    port() const;
49     duint32    serverId() const;
50     String     name() const;
51     String     description() const;
52     String     pluginDescription() const;
53     StringList packages() const;
54     String     gameId() const;
55     String     gameConfig() const;
56     String     map() const;
57     StringList players() const;
58     int        playerCount() const;
59     int        maxPlayers() const;
60     Flags      flags() const;
61 
62     String        asStyledText() const;
63     Block         asJSON() const;
64     const Record &asRecord() const;
65     Record        strippedForBroadcast() const;
66 
67     ServerInfo &setCompatibilityVersion(int compatVersion);
68     ServerInfo &setServerId(duint32 sid);
69     ServerInfo &setAddress(Address const &address);
70     ServerInfo &setDomainName(String const &domain);
71     ServerInfo &setName(String const &name);
72     ServerInfo &setDescription(String const &description);
73     ServerInfo &setPluginDescription(String const &pluginDescription);
74     ServerInfo &setPackages(StringList packages);
75     ServerInfo &setGameId(String const &gameId);
76     ServerInfo &setGameConfig(String const &gameConfig);
77     ServerInfo &setMap(String const &map);
78     ServerInfo &addPlayer(String const &playerName);
79     ServerInfo &removePlayer(String const &playerName);
80     ServerInfo &setMaxPlayers(int count);
81     ServerInfo &setFlags(Flags const &flags);
82 
83     /**
84      * Prints server/host information into the console. The header line is
85      * printed if 'info' is NULL.
86      */
87     void printToLog(int indexNumber, bool includeHeader = false) const;
88 
89 private:
90     DENG2_PRIVATE(d)
91 };
92 
93 Q_DECLARE_OPERATORS_FOR_FLAGS(ServerInfo::Flags)
94 
95 }} // namespace de::shell
96 
97 #endif // SERVERINFO_H
98