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].toAscii());
59 int engineIndex = gPlugins->pluginIndexFromName(customServerInfo.engine);
60 customServerInfo.engineIndex = engineIndex;
62 customServerInfo.host = QUrl::fromPercentEncoding(entryList[1].toAscii());
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 QList<CustomServerInfo> customServerInfoList = gConfig.doomseeker.customServers.toList();
89 setServers(customServerInfoList, receiver, slotUpdated, slotBegunRefreshing);
92 void CustomServers::setServers(
const QList<CustomServerInfo>& csiList, QObject* receiver,
const char* slotUpdated,
const char* slotBegunRefreshing)
98 if (customServerInfo.engineIndex < 0)
101 gLog << tr(
"Unknown game for custom server %1:%2")
102 .arg(customServerInfo.host).arg(customServerInfo.port);
106 QHostAddress address;
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);
131 connect(p.data(), SIGNAL( updated(ServerPtr,
int) ), receiver, slotUpdated);
132 connect(p.data(), SIGNAL( begunRefreshing(ServerPtr) ), receiver, slotBegunRefreshing);
void registerNewServer(ServerPtr server)
Registers new server with this MasterClient.
void setServers(const QList< CustomServerInfo > &csiList, QObject *receiver, const char *slotUpdated, const char *slotBegunRefreshing)
void readConfig(QObject *receiver, const char *slotUpdated, const char *slotBegunRefreshing)
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.
EnginePlugin * info() const
Main plugin interface.