25 #include "apprunner.h" 26 #include "commandlinetokenizer.h" 27 #include "configuration/doomseekerconfig.h" 29 #include "ini/inisection.h" 30 #include "ini/inivariable.h" 31 #include "plugins/engineplugin.h" 32 #include "serverapi/gamecreateparams.h" 33 #include "serverapi/message.h" 37 #include <QStringList> 39 #define BAIL_ON_ERROR(method) \ 42 if (d->message.isError()) \ 51 QString argBexLoading;
52 QString argDehLoading;
53 QString argIwadLoading;
54 QString argOptionalWadLoading;
56 QString argPwadLoading;
57 QString argDemoPlayback;
58 QString argDemoRecord;
59 QString argServerLaunch;
69 void (
GameHost::*addGlobalGameCustomParameters)();
76 d->argBexLoading =
"-deh";
77 d->argDehLoading =
"-deh";
78 d->argIwadLoading =
"-iwad";
79 d->argOptionalWadLoading =
"-file";
81 d->argPwadLoading =
"-file";
82 d->argDemoPlayback =
"-playdemo";
83 d->argDemoRecord =
"-record";
84 d->currentCmdLine =
nullptr;
87 set_addIwad(&GameHost::addIwad_default);
88 set_addPwads(&GameHost::addPwads_default);
89 set_addDMFlags(&GameHost::addDMFlags_default);
90 set_addGlobalGameCustomParameters(&GameHost::addGlobalGameCustomParameters_default);
99 POLYMORPHIC_DEFINE(
void, GameHost,
addDMFlags, (), ())
107 void GameHost::addDemoPlaybackIfApplicable()
109 if (
params().hostMode() == GameCreateParams::Demo)
116 void GameHost::addDemoRecordIfApplicable()
118 if (
params().hostMode() == GameCreateParams::Offline
119 &&
params().demoRecord() != GameDemo::NoDemo)
126 void GameHost::addDMFlags_default()
134 void GameHost::addGlobalGameCustomParameters_default()
137 QString customParameters = config[
"CustomParameters"];
139 args() << tokenizer.tokenize(customParameters);
142 void GameHost::addIwad_default()
144 const QString &iwadPath =
params().iwadPath();
146 if (iwadPath.isEmpty())
152 QFileInfo fi(iwadPath);
156 QString error = tr(
"IWAD Path error:\n\"%1\" doesn't exist or is a directory!").arg(iwadPath);
163 void GameHost::addPwads_default()
166 for (
int i = 0; i <
params().pwadsPaths().size(); ++i)
168 const QString &pwad =
params().pwadsPaths()[i];
169 args() << fileLoadingPrefix(i) << pwad;
176 QMap<QString, QStringList> groups;
177 for (
int i = 0; i <
params().pwadsPaths().size(); ++i)
179 const QString &pwad =
params().pwadsPaths()[i];
180 QString prefix = fileLoadingPrefix(i);
181 groups[prefix] << pwad;
183 for (
const QString &prefix : groups.keys())
186 for (
const QString &file : groups[prefix])
193 QString GameHost::fileLoadingPrefix(
int index)
const 195 const QString &pwad =
params().pwadsPaths()[index];
196 bool optional =
false;
197 if (
params().pwadsOptional().size() > index)
199 optional =
params().pwadsOptional()[index];
202 if (pwad.toLower().endsWith(
".deh"))
206 else if (pwad.toLower().endsWith(
".bex"))
218 return d->argBexLoading;
223 return d->argDehLoading;
228 return d->argIwadLoading;
233 return d->argOptionalWadLoading;
243 return d->argPwadLoading;
248 return d->argDemoPlayback;
253 return d->argDemoRecord;
258 return d->argServerLaunch;
263 return d->currentCmdLine->args;
273 if (
params().hostMode() == GameCreateParams::Host &&
params().port() > 0)
282 args() << QString(c.command()) << c.valueString();
285 if (
params().hostMode() == GameCreateParams::Host)
298 addDemoPlaybackIfApplicable();
299 addDemoRecordIfApplicable();
306 d->currentCmdLine = &cmdLine;
312 if (d->message.isError())
332 const bool WRAP_IN_SSS_CONSOLE =
false;
334 const bool WRAP_IN_SSS_CONSOLE = params.hostMode() == GameCreateParams::Host;
337 if (WRAP_IN_SSS_CONSOLE)
349 return AppRunner::runExecutable(cmdLine);
363 void GameHost::saveDemoMetaData()
365 if (
params().demoRecord() == GameDemo::Managed)
367 GameDemo::saveDemoMetaData(
params().demoPath(), *
plugin(),
372 void GameHost::setArgForBexLoading(
const QString &arg)
374 d->argBexLoading = arg;
377 void GameHost::setArgForDehLoading(
const QString &arg)
379 d->argDehLoading = arg;
382 void GameHost::setArgForIwadLoading(
const QString &arg)
384 d->argIwadLoading = arg;
387 void GameHost::setArgForOptionalWadLoading(
const QString &arg)
389 d->argOptionalWadLoading = arg;
392 void GameHost::setArgForPort(
const QString &arg)
397 void GameHost::setArgForPwadLoading(
const QString &arg)
399 d->argPwadLoading = arg;
402 void GameHost::setArgForDemoPlayback(
const QString &arg)
404 d->argDemoPlayback = arg;
407 void GameHost::setArgForDemoRecord(
const QString &arg)
409 d->argDemoRecord = arg;
412 void GameHost::setArgForServerLaunch(
const QString &arg)
414 d->argServerLaunch = arg;
419 d->message = message;
422 void GameHost::setupGamePaths()
424 QFileInfo fileInfo(
params().executablePath());
425 if (!fileInfo.isFile() && !fileInfo.isBundle())
427 QString error = tr(
"%1\n doesn't exist or is not a file.").arg(fileInfo.filePath());
432 d->currentCmdLine->applicationDir = fileInfo.dir();
437 for (
const QString &pwad :
params().pwadsPaths())
442 QString error = tr(
"PWAD path error:\n\"%1\" doesn't exist or is a directory!").arg(pwad);
void addPwads_prefixOnce()
See: GameClientRunner::addModFiles_prefixOnce()
EnginePlugin * plugin() const
EnginePlugin that this GameHost is associated with.
Game parametrization data used when creating new games.
Structure holding parameters for application launch.
Message object used to pass messages throughout the Doomseeker's system.
const QString & argForBexLoading() const
Command line parameter that is used to load a BEX file.
const QString & argForDemoPlayback() const
Command line parameter for playing back a demo.
const QString & argForPort() const
Command line parameter that is used to set network port for the game.
const QString & argForServerLaunch() const
Command line parameter used to launch a server.
void setMessage(const Message &message)
Call this method to convey errors.
const QString & executablePath() const
Path to the game executable.
const QString & demoPath() const
Use if running in HostMode::Demo mode or recording a demo.
const GameCreateParams & params() const
GameCreateParams with which this game should be configured.
const QString & argForOptionalWadLoading() const
Command line parameter that is used to load optional WADs.
virtual void addCustomParameters()
"Custom parameters" are specified directly by user in "Create Game" dialog box.
bool isIgnore() const
True for 'Null' messages.
void addGlobalGameCustomParameters()
[Virtual] Adds custom parameters as defined in Doomseeker's configuration box.
void addDMFlags()
[Virtual] Creates engine specific command line parameters out of passed DM flags list.
const QString & argForPwadLoading() const
Command line parameter that is used to load a PWAD.
void addPwads()
[Virtual] Loads PWADs and other mod files (dehacked patches, pk3s, etc.)
static void runExecutableWrappedInStandardServerConsole(const QIcon &icon, const CommandLineInfo &cli)
Executes predefined command line.
QStringList & args()
Reference to command line arguments.
virtual void createCommandLineArguments()
Builds command line arguments sequentially by calling other methods.
bool verifyPwadPaths()
Verifies if all params().pwadsPaths() exist.
Message createHostCommandLine(const GameCreateParams ¶ms, CommandLineInfo &cmdLine)
QList< GameCVar > & cvars()
Contents of this list will be passed as "+consoleCommand value" to the command line.
INI section representation.
Creates game servers, offline games or demo playbacks.
Splits command line into separate arguments in a manner appropriate for current OS.
const QString & argForDemoRecord() const
Command line parameter for recording a demo.
const QString & argForIwadLoading() const
Command line parameter that is used to set IWAD.
Message host(const GameCreateParams ¶ms)
void addIwad()
[Virtual] Loads IWAD.
static Message customError(const QString &content)
Convenience method. Sets type to Type::CUSTOM_ERROR.
A general game setting or variable (like fraglimit).
virtual void addExtra()
Creates engine specific command line parameters out of Server class fields.
const QString & argForDehLoading() const
Command line parameter that is used to load a DEHACKED file.