23 #include "joincommandlinebuilder.h" 25 #include "application.h" 26 #include "apprunner.h" 27 #include "configuration/doomseekerconfig.h" 28 #include "datapaths.h" 30 #include "gui/passworddlg.h" 31 #include "gui/wadseekerinterface.h" 32 #include "gui/wadseekershow.h" 33 #include "ini/settingsproviderqt.h" 35 #include "plugins/engineplugin.h" 36 #include "serverapi/exefile.h" 37 #include "serverapi/gameclientrunner.h" 38 #include "serverapi/message.h" 39 #include "serverapi/server.h" 42 #include <QDialogButtonBox> 43 #include <QGridLayout> 45 #include <QListWidget> 46 #include <QMessageBox> 47 #include <wadseeker/wadseeker.h> 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()
87 if (d->server->isLockedAnywhere())
89 if (!d->passwordsAlreadySet)
92 int ret = password.exec();
93 if (ret != QDialog::Accepted)
97 d->connectPassword = password.connectPassword();
98 d->inGamePassword = password.inGamePassword();
99 d->passwordsAlreadySet =
true;
101 params.setConnectPassword(d->connectPassword);
102 params.setInGamePassword(d->inGamePassword);
105 if (!d->demoName.isEmpty())
107 params.setDemoName(d->demoName);
112 const CommandLineInfo &JoinCommandLineBuilder::builtCommandLine()
const 117 bool JoinCommandLineBuilder::checkServerStatus()
120 if (d->server->isRefreshing())
122 d->error = tr(
"This server is still refreshing.\nPlease wait until it is finished.");
123 gLog << tr(
"Attempted to obtain a join command line for a \"%1\" " 124 "server that is under refresh.").arg(d->server->addressWithPort());
128 else if (!d->server->isKnown())
130 d->error = tr(
"Data for this server is not available.\nOperation failed.");
131 gLog << tr(
"Attempted to obtain a join command line for an unknown server \"%1\"").arg(
132 d->server->addressWithPort());
138 bool JoinCommandLineBuilder::checkWadseekerValidity(QWidget *parent)
141 QString targetDirPath = gConfig.wadseeker.targetDirectory;
142 QDir targetDir(targetDirPath);
143 QFileInfo targetDirFileInfo(targetDirPath);
145 if (targetDirPath.isEmpty() || !targetDir.exists() || !targetDirFileInfo.isWritable())
153 const QString &JoinCommandLineBuilder::error()
const 158 void JoinCommandLineBuilder::failBuild()
161 emit commandLineBuildFinished();
164 void JoinCommandLineBuilder::handleError(
const JoinError &error)
166 if (!error.error().isEmpty())
168 d->error = error.error();
172 d->error = tr(
"Unknown error.");
174 d->configurationError = (error.type() == JoinError::ConfigurationError);
176 gLog << tr(
"Error when obtaining join parameters for server " 177 "\"%1\", game \"%2\": %3").arg(d->server->name()).arg(
178 d->server->engineName()).arg(d->error);
181 MissingWadsDialog::MissingWadsProceed JoinCommandLineBuilder::handleMissingWads(
const JoinError &error)
183 QList<PWad> missingWads;
194 if (dialog.exec() == QDialog::Accepted)
196 if (dialog.decision() == MissingWadsDialog::Install)
198 if (!gWadseekerShow->checkWadseekerValidity(d->parentWidget))
200 return MissingWadsDialog::Cancel;
203 this->connect(wadseeker, SIGNAL(finished(
int)), SLOT(onWadseekerDone(
int)));
204 wadseeker->
setWads(dialog.filesToDownload());
205 wadseeker->setAttribute(Qt::WA_DeleteOnClose);
209 return dialog.decision();
212 bool JoinCommandLineBuilder::isConfigurationError()
const 214 return d->configurationError;
217 void JoinCommandLineBuilder::missingWadsClicked(QAbstractButton *button)
219 d->lastButtonClicked = d->buttonBox->standardButton(button);
224 assert(d->server !=
nullptr);
227 if (!checkServerStatus())
234 if (!buildServerConnectParams(params))
243 switch (joinError.type())
248 case JoinError::ConfigurationError:
249 case JoinError::Critical:
251 handleError(joinError);
258 if (tryToInstallGame())
269 case JoinError::MissingWads:
271 MissingWadsDialog::MissingWadsProceed proceed =
272 handleMissingWads(joinError);
275 case MissingWadsDialog::Cancel:
278 case MissingWadsDialog::Ignore:
280 case MissingWadsDialog::Install:
284 gLog <<
"Bug: not sure how to proceed after \"MissingWads\".";
288 [[gnu::fallthrough]];
291 case JoinError::NoError:
292 if (d->demo == GameDemo::Managed)
294 GameDemo::saveDemoMetaData(d->demoName, *d->server->plugin(),
295 d->server->iwad(), d->server->wads());
300 gLog <<
"JoinCommandLineBuilder - unhandled JoinError type!";
304 emit commandLineBuildFinished();
307 void JoinCommandLineBuilder::onWadseekerDone(
int result)
309 qDebug() <<
"onWadseekerDone:" << result;
310 if (result == QDialog::Accepted)
320 ServerPtr JoinCommandLineBuilder::server()
const 327 d->passwordsAlreadySet = !(connectPassword.isNull() && inGamePassword.isNull());
328 if (!connectPassword.isNull())
329 d->connectPassword = connectPassword;
330 if (!inGamePassword.isNull())
331 d->inGamePassword = inGamePassword;
334 bool JoinCommandLineBuilder::tryToInstallGame()
336 Message message = d->server->clientExe()->install(gApp->mainWindowAsQWidget());
339 QMessageBox::critical(gApp->mainWindowAsQWidget(), tr(
"Game installation failure"),
340 message.
contents(), QMessageBox::Ok);
Structure holding parameters for application launch.
Message object used to pass messages throughout the Doomseeker's system.
const QList< PWad > & incompatibleWads() const
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...
void setWads(const QList< PWad > &wads)
Sets WADs to seek.
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.
Wadseeker dialog box, only one instance is allowed.
Game executable was not found but it can be automatically installed by the plugin.
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...