23 #include "joincommandlinebuilder.h" 25 #include "apprunner.h" 26 #include "datapaths.h" 28 #include "configuration/doomseekerconfig.h" 29 #include "gui/passworddlg.h" 30 #include "gui/wadseekerinterface.h" 31 #include "gui/wadseekershow.h" 32 #include "ini/settingsproviderqt.h" 33 #include "plugins/engineplugin.h" 34 #include "serverapi/exefile.h" 35 #include "serverapi/gameclientrunner.h" 36 #include "serverapi/message.h" 37 #include "serverapi/server.h" 38 #include "application.h" 41 #include <wadseeker/wadseeker.h> 42 #include <QDialogButtonBox> 43 #include <QGridLayout> 45 #include <QListWidget> 46 #include <QMessageBox> 49 DClass<JoinCommandLineBuilder>
53 bool configurationError;
54 QString connectPassword;
58 QString inGamePassword;
60 QWidget *parentWidget;
61 bool passwordsAlreadySet;
64 QDialogButtonBox *buttonBox;
65 QDialogButtonBox::StandardButton lastButtonClicked;
71 GameDemo demo, QWidget *parentWidget)
73 d->configurationError =
false;
75 d->demoName = GameDemo::mkDemoFullPath(demo, *server->plugin());
76 d->parentWidget = parentWidget;
77 d->passwordsAlreadySet =
false;
81 JoinCommandLineBuilder::~JoinCommandLineBuilder()
85 void JoinCommandLineBuilder::allDownloadableWads(
const JoinError &joinError, QStringList &required, QStringList &optional)
92 const QList<PWad> missingWads = joinError.
missingWads();
93 foreach(
const PWad &wad, missingWads)
96 optional.append(wad.
name());
98 required.append(wad.
name());
100 required = Wadseeker::filterAllowedOnlyWads(required);
101 optional = Wadseeker::filterAllowedOnlyWads(optional);
106 if (d->server->isLockedAnywhere())
108 if (!d->passwordsAlreadySet)
111 int ret = password.exec();
112 if (ret != QDialog::Accepted)
116 d->connectPassword = password.connectPassword();
117 d->inGamePassword = password.inGamePassword();
118 d->passwordsAlreadySet =
true;
120 params.setConnectPassword(d->connectPassword);
121 params.setInGamePassword(d->inGamePassword);
124 if (!d->demoName.isEmpty())
126 params.setDemoName(d->demoName);
131 const CommandLineInfo &JoinCommandLineBuilder::builtCommandLine()
const 136 bool JoinCommandLineBuilder::checkServerStatus()
139 if (d->server->isRefreshing())
141 d->error = tr(
"This server is still refreshing.\nPlease wait until it is finished.");
142 gLog << tr(
"Attempted to obtain a join command line for a \"%1\" " 143 "server that is under refresh.").arg(d->server->addressWithPort());
147 else if (!d->server->isKnown())
149 d->error = tr(
"Data for this server is not available.\nOperation failed.");
150 gLog << tr(
"Attempted to obtain a join command line for an unknown server \"%1\"").arg(
151 d->server->addressWithPort());
157 bool JoinCommandLineBuilder::checkWadseekerValidity(QWidget *parent)
159 QString targetDirPath = gConfig.wadseeker.targetDirectory;
160 QDir targetDir(targetDirPath);
161 QFileInfo targetDirFileInfo(targetDirPath);
163 if (targetDirPath.isEmpty() || !targetDir.exists() || !targetDirFileInfo.isWritable())
171 const QString &JoinCommandLineBuilder::error()
const 176 void JoinCommandLineBuilder::failBuild()
179 emit commandLineBuildFinished();
182 void JoinCommandLineBuilder::handleError(
const JoinError &error)
184 if (!error.error().isEmpty())
186 d->error = error.error();
190 d->error = tr(
"Unknown error.");
192 d->configurationError = (error.type() == JoinError::ConfigurationError);
194 gLog << tr(
"Error when obtaining join parameters for server " 195 "\"%1\", game \"%2\": %3").arg(d->server->name()).arg(
196 d->server->engineName()).arg(d->error);
199 MissingWadsDialog::MissingWadsProceed JoinCommandLineBuilder::handleMissingWads(
const JoinError &error)
201 QList<PWad> missingWads;
211 if (dialog.exec() == QDialog::Accepted)
213 if (dialog.decision() == MissingWadsDialog::Install)
215 if (!gWadseekerShow->checkWadseekerValidity(d->parentWidget))
217 return MissingWadsDialog::Cancel;
220 this->connect(wadseeker, SIGNAL(finished(
int)), SLOT(onWadseekerDone(
int)));
221 wadseeker->
setWads(dialog.filesToDownload());
222 wadseeker->setAttribute(Qt::WA_DeleteOnClose);
226 return dialog.decision();
229 bool JoinCommandLineBuilder::isConfigurationError()
const 231 return d->configurationError;
234 void JoinCommandLineBuilder::missingWadsClicked(QAbstractButton *button)
236 d->lastButtonClicked = d->buttonBox->standardButton(button);
241 assert(d->server != NULL);
244 if (!checkServerStatus())
251 if (!buildServerConnectParams(params))
260 switch (joinError.type())
265 case JoinError::ConfigurationError:
266 case JoinError::Critical:
268 handleError(joinError);
275 if (tryToInstallGame())
286 case JoinError::MissingWads:
288 MissingWadsDialog::MissingWadsProceed proceed =
289 handleMissingWads(joinError);
292 case MissingWadsDialog::Cancel:
295 case MissingWadsDialog::Ignore:
297 case MissingWadsDialog::Install:
301 gLog <<
"Bug: not sure how to proceed after \"MissingWads\".";
308 case JoinError::NoError:
309 if (d->demo == GameDemo::Managed)
311 GameDemo::saveDemoMetaData(d->demoName, *d->server->plugin(),
312 d->server->iwad(), d->server->wads());
317 gLog <<
"JoinCommandLineBuilder - unhandled JoinError type!";
321 emit commandLineBuildFinished();
324 void JoinCommandLineBuilder::onWadseekerDone(
int result)
326 qDebug() <<
"onWadseekerDone:" << result;
327 if (result == QDialog::Accepted)
337 ServerPtr JoinCommandLineBuilder::server()
const 344 d->passwordsAlreadySet = !(connectPassword.isNull() && inGamePassword.isNull());
345 if(!connectPassword.isNull())
346 d->connectPassword = connectPassword;
347 if(!inGamePassword.isNull())
348 d->inGamePassword = inGamePassword;
351 bool JoinCommandLineBuilder::tryToInstallGame()
353 Message message = d->server->clientExe()->install(gApp->mainWindowAsQWidget());
356 QMessageBox::critical(gApp->mainWindowAsQWidget(), tr(
"Game installation failure"),
357 message.
contents(), QMessageBox::Ok);
Structure holding parameters for application launch.
Message object used to pass messages throughout the Doomseeker's system.
A DTO for GameClientRunner; exchanges information between main program and plugins, and allows future extensions.
bool isError() const
True if type() is equal to or greater than CUSTOM_ERROR.
void setPasswords(const QString &connectPassword=QString(), const QString &inGamePassword=QString())
Sets the connect/ingame password and bypasses the prompt. Set passwords to a null string to unset...
const QList< PWad > & missingWads() const
Generates command line for joining specified server.
Aborts without printing error.
Indicator of error for the server join process.
JoinError createJoinCommandLine(CommandLineInfo &cli, const ServerConnectParams ¶ms)
Fills out CommandLineInfo object that allows client executables to be launched.
const QString & missingIwad() const
void obtainJoinCommandLine()
Runs asynchronously and emits commandLineBuildFinished() when done.
void setWads(const QStringList &wads)
Sets WADs to seek.
Wadseeker dialog box, only one instance is allowed.
Game executable was not found but it can be automatically installed by the plugin.
bool isOptional() const
Is this WAD required to join the server?
static const unsigned SUCCESSFUL
Message indicates that the operation was successful.
unsigned type() const
Message::Type.
QString contents() const
Customized displayable contents of this Message.
Creates command line that launches the client executable of the game and connects it to a server...
const QString & name() const
File name of the WAD.