24 #include "connectionhandler.h" 26 #include "joincommandlinebuilder.h" 28 #include "strings.hpp" 29 #include "configuration/doomseekerconfig.h" 30 #include "gui/configuration/doomseekerconfigurationdialog.h" 31 #include "gui/mainwindow.h" 32 #include "plugins/engineplugin.h" 33 #include "plugins/pluginloader.h" 34 #include "refresher/canrefreshserver.h" 35 #include "refresher/refresher.h" 36 #include "serverapi/gameclientrunner.h" 37 #include "serverapi/message.h" 38 #include "serverapi/server.h" 39 #include "application.h" 40 #include "apprunner.h" 42 #include <QDesktopServices> 43 #include <QMessageBox> 47 DClass<ConnectionHandler>
57 QWidget *parentWidget;
63 : QObject(parentWidget)
65 d->forceRefresh =
false;
67 d->parentWidget = parentWidget;
70 ConnectionHandler::~ConnectionHandler()
74 void ConnectionHandler::checkResponse(
const ServerPtr &server,
int response)
76 server->disconnect(
this);
82 QMessageBox::critical(d->parentWidget, tr(
"Doomseeker - join server"),
83 tr(
"Connection to server timed out."));
86 QMessageBox::critical(d->parentWidget, tr(
"Doomseeker - join server"),
87 tr(
"An error occured while trying to connect to server."));
98 QTimer::singleShot(0,
this, SLOT(buildJoinCommandLine()));
103 gLog << QString(
"Attempting to connect to server: %1").arg(url.toString());
108 bool zdsScheme = url.scheme().compare(
"zds", Qt::CaseInsensitive) == 0;
109 for(
unsigned int i = 0;i < gPlugins->numPlugins();++i)
111 const EnginePlugin *plugin = gPlugins->plugin(i)->info();
112 if(plugin->data()->scheme.compare(url.scheme(), Qt::CaseInsensitive) == 0 ||
113 (zdsScheme && plugin->data()->scheme.left(2).compare(url.path().mid(1), Qt::CaseInsensitive) == 0))
121 gLog <<
"Scheme not recognized starting normally.";
125 unsigned short port = url.port(handler->data()->defaultServerPort);
132 ServerPtr server = handler->
server(QHostAddress(address), port);
134 connectionHandler->d->forceRefresh =
true;
136 return connectionHandler;
139 void ConnectionHandler::finish(
int response)
141 emit finished(response);
144 void ConnectionHandler::buildJoinCommandLine()
147 gConfig.doomseeker.bRecordDemo ? GameDemo::Managed : GameDemo::NoDemo,
149 this->connect(builder, SIGNAL(commandLineBuildFinished()), SLOT(onCommandLineBuildFinished()));
153 void ConnectionHandler::onCommandLineBuildFinished()
159 runCommandLine(builtCli);
163 if (!builder->error().isEmpty())
165 QMessageBox::critical(d->parentWidget, tr(
"Doomseeker - join game"), builder->error());
167 if (builder->isConfigurationError())
169 DoomseekerConfigurationDialog::openConfiguration(gApp->mainWindow(), d->server->plugin());
172 builder->deleteLater();
178 Message message = AppRunner::runExecutable(cli);
181 gLog << tr(
"Error while launching executable for server \"%1\", game \"%2\": %3")
182 .arg(d->server->name()).arg(d->server->engineName()).arg(message.
contents());
183 QMessageBox::critical(d->parentWidget, tr(
"Doomseeker - launch executable"), message.
contents());
187 void ConnectionHandler::refreshToJoin()
192 if (d->forceRefresh || (refreshCheck.shouldRefresh() && gConfig.doomseeker.bQueryBeforeLaunch))
194 this->connect(d->server.data(), SIGNAL(updated(ServerPtr,
int)),
195 SLOT(checkResponse(ServerPtr,
int)));
196 gRefresher->registerServer(d->server.data());
204 void ConnectionHandler::run()
213 void PluginUrlHandler::registerAll()
215 for(
unsigned int i = 0;i < gPlugins->numPlugins();++i)
216 registerScheme(gPlugins->plugin(i)->info()->data()->scheme);
219 registerScheme(
"zds");
222 void PluginUrlHandler::registerScheme(
const QString &scheme)
227 QDesktopServices::setUrlHandler(scheme, instance,
"handleUrl");
230 void PluginUrlHandler::handleUrl(
const QUrl &url)
232 if(QMessageBox::question(NULL, tr(
"Connect to server"),
233 tr(
"Do you want to connect to the server at %1?").arg(url.toString()),
234 QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
236 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.