24 #include "connectionhandler.h" 26 #include "joincommandlinebuilder.h" 29 #include "configuration/doomseekerconfig.h" 30 #include "gui/configuration/doomseekerconfigurationdialog.h" 31 #include "plugins/engineplugin.h" 32 #include "plugins/pluginloader.h" 33 #include "refresher/canrefreshserver.h" 34 #include "refresher/refresher.h" 35 #include "serverapi/gameclientrunner.h" 36 #include "serverapi/message.h" 37 #include "serverapi/server.h" 38 #include "apprunner.h" 40 #include <QDesktopServices> 41 #include <QMessageBox> 44 DClass<ConnectionHandler>
49 QWidget *parentWidget;
56 : QObject(parentWidget)
58 d->handleResponse = handleResponse;
60 d->parentWidget = parentWidget;
61 connect(d->server.data(), SIGNAL(updated(ServerPtr,
int)),
62 this, SLOT(checkResponse(ServerPtr,
int)));
65 ConnectionHandler::~ConnectionHandler()
69 void ConnectionHandler::checkResponse(
const ServerPtr &server,
int response)
78 QMessageBox::critical(d->parentWidget, tr(
"Doomseeker - join server"), tr(
"Connection to server timed out."));
81 QMessageBox::critical(d->parentWidget, tr(
"Doomseeker - join server"), tr(
"An error occured while trying to connect to server."));
95 gLog << QString(
"Attempting to connect to server: %1").arg(url.toString());
100 bool zdsScheme = url.scheme().compare(
"zds", Qt::CaseInsensitive) == 0;
101 for(
unsigned int i = 0;i < gPlugins->numPlugins();++i)
103 const EnginePlugin *plugin = gPlugins->plugin(i)->info();
104 if(plugin->data()->scheme.compare(url.scheme(), Qt::CaseInsensitive) == 0 ||
105 (zdsScheme && plugin->data()->scheme.left(2).compare(url.path().mid(1), Qt::CaseInsensitive) == 0))
113 gLog <<
"Scheme not recognized starting normally.";
117 unsigned short port = url.port(handler->data()->defaultServerPort);
124 ServerPtr server = handler->
server(QHostAddress(address), port);
126 gRefresher->registerServer(server.data());
128 return connectionHandler;
131 void ConnectionHandler::finish(
int response)
133 d->server->disconnect(
this);
134 emit finished(response);
137 void ConnectionHandler::buildJoinCommandLine()
140 gConfig.doomseeker.bRecordDemo ? GameDemo::Managed : GameDemo::NoDemo,
142 this->connect(builder, SIGNAL(commandLineBuildFinished()), SLOT(onCommandLineBuildFinished()));
146 void ConnectionHandler::onCommandLineBuildFinished()
152 runCommandLine(builtCli);
156 if (!builder->error().isEmpty())
158 QMessageBox::critical(d->parentWidget, tr(
"Doomseeker - join game"), builder->error());
160 if (builder->isConfigurationError())
162 DoomseekerConfigurationDialog::openConfiguration(d->server->plugin());
165 builder->deleteLater();
171 Message message = AppRunner::runExecutable(cli);
174 gLog << tr(
"Error while launching executable for server \"%1\", game \"%2\": %3")
175 .arg(d->server->name()).arg(d->server->engineName()).arg(message.
contents());
176 QMessageBox::critical(d->parentWidget, tr(
"Doomseeker - launch executable"), message.
contents());
180 void ConnectionHandler::refreshToJoin()
185 if(refreshCheck.shouldRefresh() && gConfig.doomseeker.bQueryBeforeLaunch)
187 gRefresher->registerServer(d->server.data());
195 void ConnectionHandler::run()
197 buildJoinCommandLine();
204 void PluginUrlHandler::registerAll()
206 for(
unsigned int i = 0;i < gPlugins->numPlugins();++i)
207 registerScheme(gPlugins->plugin(i)->info()->data()->scheme);
210 registerScheme(
"zds");
213 void PluginUrlHandler::registerScheme(
const QString &scheme)
218 QDesktopServices::setUrlHandler(scheme, instance,
"handleUrl");
221 void PluginUrlHandler::handleUrl(
const QUrl &url)
223 if(QMessageBox::question(NULL, tr(
"Connect to server"),
224 tr(
"Do you want to connect to the server at %1?").arg(url.toString()),
225 QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
227 ConnectionHandler::connectByUrl(url);
static void translateServerAddress(const QString &addressString, QString &hostname, unsigned short &port, const QString &defaultAddress)
Translates string in format "hostname:port" to atomic values.
Structure holding parameters for application launch.
Message object used to pass messages throughout the Doomseeker's system.
bool isError() const
True if type() is equal to or greater than CUSTOM_ERROR.
Generates command line for joining specified server.
virtual ServerPtr server(const QHostAddress &address, unsigned short port) const
Creates an instance of server object from this plugin.
void obtainJoinCommandLine()
Runs asynchronously and emits commandLineBuildFinished() when done.
Response was parsed properly and Server information is available.
Server didn't respond at all.
QString contents() const
Customized displayable contents of this Message.
bool isValid() const
It's valid when at least executable is set.