23 #include "configuration/doomseekerconfig.h" 24 #include "customservers.h" 26 #include "plugins/engineplugin.h" 27 #include "plugins/pluginloader.h" 28 #include "serverapi/server.h" 35 assert(server !=
nullptr);
37 obj.engine = server->
plugin()->data()->name;
38 obj.engineIndex = gPlugins->pluginIndexFromName(obj.engine);
39 obj.host = server->
address().toString();
40 obj.port = server->
port();
47 return engine == other.engine
49 && host == other.host;
56 outCustomServerInfoList.clear();
58 int openingBracketIndex = 0;
59 int closingBracketIndex = 0;
60 bool bSeekClosingBracket =
false;
61 for (
int charIdx = 0; charIdx < str.length(); ++charIdx)
63 if (!bSeekClosingBracket && str[charIdx] ==
'(')
65 openingBracketIndex = charIdx;
66 bSeekClosingBracket =
true;
68 else if (bSeekClosingBracket && str[charIdx] ==
')')
70 closingBracketIndex = charIdx;
71 bSeekClosingBracket =
false;
73 QString entry = str.mid(openingBracketIndex + 1, closingBracketIndex - (openingBracketIndex + 1));
74 QStringList entryList = entry.split(
";");
76 if (entryList.size() >= 3)
79 customServerInfo.engine = QUrl::fromPercentEncoding(entryList[0].toUtf8());
81 int engineIndex = gPlugins->pluginIndexFromName(customServerInfo.engine);
82 customServerInfo.engineIndex = engineIndex;
84 customServerInfo.host = QUrl::fromPercentEncoding(entryList[1].toUtf8());
85 customServerInfo.enabled =
true;
86 if (entryList.size() >= 4)
87 customServerInfo.enabled = entryList[3].toInt() != 0;
90 int port = QString(entryList[2]).toInt(&ok);
91 if (ok && port >= 1 && port <= 65535)
92 customServerInfo.port = port;
93 else if (engineIndex >= 0)
96 customServerInfo.port = pPlugin->
info()->data()->defaultServerPort;
99 customServerInfo.port = 1;
101 outCustomServerInfoList << customServerInfo;
109 for (
const CustomServerInfo &knownPinned : gConfig.doomseeker.customServers)
112 return knownPinned.enabled;
119 CustomServerInfo otherServerInfo = CustomServerInfo::fromServer(otherServer);
120 for (ServerCPtr knownServer : servers())
122 if (CustomServerInfo::fromServer(knownServer.data()).
isSameServer(otherServerInfo))
130 return setServers(gConfig.doomseeker.customServers.toList());
133 void CustomServers::setServerPinned(
const CustomServerInfo &serverInfo,
bool pinned)
136 for (
int serverIdx = 0; serverIdx < gConfig.doomseeker.customServers.size(); ++serverIdx)
138 CustomServerInfo &knownPinned = gConfig.doomseeker.customServers[serverIdx];
141 knownPinned.enabled = pinned;
148 gConfig.doomseeker.customServers << serverInfo;
155 QList<ServerPtr> servers;
158 if (!customServerInfo.enabled)
160 if (customServerInfo.engineIndex < 0)
163 gLog << tr(
"Unknown game for custom server %1:%2")
164 .arg(customServerInfo.host).arg(customServerInfo.port);
168 QHostAddress address;
169 if (!address.setAddress(customServerInfo.host))
171 QHostInfo hostInfo(QHostInfo::fromName(customServerInfo.host));
172 if (hostInfo.addresses().size() == 0)
175 gLog << tr(
"Failed to resolve address for custom server %1:%2")
176 .arg(customServerInfo.host).arg(customServerInfo.port);
179 address = hostInfo.addresses().first();
182 const EnginePlugin *pInterface = gPlugins->plugin(customServerInfo.engineIndex)->info();
183 ServerPtr p = pInterface->
server(address, customServerInfo.port);
186 gLog << tr(
"Plugin returned nullptr \"Server*\" for custom server %1:%2. " 187 "This is a problem with the plugin.")
188 .arg(customServerInfo.host).arg(customServerInfo.port);
193 registerNewServer(p);
bool hasSameServer(const Server *otherServer) const
QList< ServerPtr > setServers(const QList< CustomServerInfo > &serverDefs)
A representation of a server for a given game.
static void decodeConfigEntries(const QString &str, QList< CustomServerInfo > &outCustomServerInfoList)
bool isSameServer(const CustomServerInfo &other) const
virtual ServerPtr server(const QHostAddress &address, unsigned short port) const
Creates an instance of server object from this plugin.
EnginePlugin * info() const
Main plugin interface.
QList< ServerPtr > readConfig()
virtual EnginePlugin * plugin() const =0
unsigned short port() const
Network port on which this server is hosted.
const QHostAddress & address() const
Address of this server.