23 #include "customservers.h" 24 #include "configuration/doomseekerconfig.h" 25 #include "plugins/engineplugin.h" 26 #include "plugins/pluginloader.h" 27 #include "serverapi/server.h" 35 assert(server != NULL);
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)
88 customServerInfo.enabled = entryList[3].toInt() != 0;
92 int port = QString(entryList[2]).toInt(&ok);
93 if (ok && port >= 1 && port <= 65535)
95 customServerInfo.port = port;
97 else if (engineIndex >= 0)
100 customServerInfo.port = pPlugin->
info()->data()->defaultServerPort;
104 customServerInfo.port = 1;
107 outCustomServerInfoList << customServerInfo;
115 foreach (
const CustomServerInfo &knownPinned, gConfig.doomseeker.customServers)
119 return knownPinned.enabled;
127 CustomServerInfo otherServerInfo = CustomServerInfo::fromServer(otherServer);
128 foreach (ServerCPtr knownServer, servers())
130 if (CustomServerInfo::fromServer(knownServer.data()).
isSameServer(otherServerInfo))
138 return setServers(gConfig.doomseeker.customServers.toList());
141 void CustomServers::setServerPinned(
const CustomServerInfo &serverInfo,
bool pinned)
144 for (
int serverIdx = 0; serverIdx < gConfig.doomseeker.customServers.size(); ++serverIdx)
146 CustomServerInfo &knownPinned = gConfig.doomseeker.customServers[serverIdx];
149 knownPinned.enabled = pinned;
157 gConfig.doomseeker.customServers << serverInfo;
165 QList<ServerPtr> servers;
168 if (!customServerInfo.enabled)
170 if (customServerInfo.engineIndex < 0)
173 gLog << tr(
"Unknown game for custom server %1:%2")
174 .arg(customServerInfo.host).arg(customServerInfo.port);
178 QHostAddress address;
179 if (!address.setAddress(customServerInfo.host))
181 QHostInfo hostInfo(QHostInfo::fromName(customServerInfo.host));
182 if (hostInfo.addresses().size() == 0)
185 gLog << tr(
"Failed to resolve address for custom server %1:%2")
186 .arg(customServerInfo.host).arg(customServerInfo.port);
189 address = hostInfo.addresses().first();
192 const EnginePlugin* pInterface = gPlugins->plugin(customServerInfo.engineIndex)->info();
193 ServerPtr p = pInterface->
server(address, customServerInfo.port);
196 gLog << tr(
"Plugin returned NULL \"Server*\" for custom server %1:%2. " 197 "This is a problem with the plugin.")
198 .arg(customServerInfo.host).arg(customServerInfo.port);
203 registerNewServer(p);
bool hasSameServer(const Server *otherServer) const
QList< ServerPtr > setServers(const QList< CustomServerInfo > &serverDefs)
virtual EnginePlugin * plugin() const =0
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()
unsigned short port() const
Network port on which this server is hosted.
const QHostAddress & address() const
Address of this server.