23 #include "customservers.h" 24 #include "configuration/doomseekerconfig.h" 25 #include "plugins/engineplugin.h" 26 #include "plugins/pluginloader.h" 27 #include "serverapi/server.h" 34 outCustomServerInfoList.clear();
36 int openingBracketIndex = 0;
37 int closingBracketIndex = 0;
38 bool bSeekClosingBracket =
false;
39 for (
int i = 0; i < str.length(); ++i)
41 if (!bSeekClosingBracket && str[i] ==
'(')
43 openingBracketIndex = i;
44 bSeekClosingBracket =
true;
46 else if (bSeekClosingBracket && str[i] ==
')')
48 closingBracketIndex = i;
49 bSeekClosingBracket =
false;
51 QString entry = str.mid(openingBracketIndex + 1, closingBracketIndex - (openingBracketIndex + 1));
52 QStringList entryList = entry.split(
";");
54 if (entryList.size() == 3)
57 customServerInfo.engine = QUrl::fromPercentEncoding(entryList[0].toUtf8());
59 int engineIndex = gPlugins->pluginIndexFromName(customServerInfo.engine);
60 customServerInfo.engineIndex = engineIndex;
62 customServerInfo.host = QUrl::fromPercentEncoding(entryList[1].toUtf8());
65 int port = QString(entryList[2]).toInt(&ok);
66 if (ok && port >= 1 && port <= 65535)
68 customServerInfo.port =
port;
70 else if (engineIndex >= 0)
73 customServerInfo.port = pPlugin->
info()->data()->defaultServerPort;
77 customServerInfo.port = 1;
80 outCustomServerInfoList << customServerInfo;
88 return setServers(gConfig.doomseeker.customServers.toList());
95 QList<ServerPtr> servers;
98 if (customServerInfo.engineIndex < 0)
101 gLog << tr(
"Unknown game for custom server %1:%2")
102 .arg(customServerInfo.host).arg(customServerInfo.port);
107 if (!address.setAddress(customServerInfo.host))
109 QHostInfo hostInfo(QHostInfo::fromName(customServerInfo.host));
110 if (hostInfo.addresses().size() == 0)
113 gLog << tr(
"Failed to resolve address for custom server %1:%2")
114 .arg(customServerInfo.host).arg(customServerInfo.port);
117 address = hostInfo.addresses().first();
120 const EnginePlugin* pInterface = gPlugins->plugin(customServerInfo.engineIndex)->info();
121 ServerPtr p = pInterface->
server(address, customServerInfo.port);
124 gLog << tr(
"Plugin returned NULL \"Server*\" for custom server %1:%2. " 125 "This is a problem with the plugin.")
126 .arg(customServerInfo.host).arg(customServerInfo.port);
QList< ServerPtr > setServers(const QList< CustomServerInfo > &serverDefs)
unsigned short port() const
Network port of the master server.
void registerNewServer(ServerPtr server)
Registers new server with this MasterClient.
static void decodeConfigEntries(const QString &str, QList< CustomServerInfo > &outCustomServerInfoList)
virtual ServerPtr server(const QHostAddress &address, unsigned short port) const
Creates an instance of server object from this plugin.
QHostAddress address() const
Address of the master server.
EnginePlugin * info() const
Main plugin interface.
QList< ServerPtr > readConfig()