From c6d9e6030ada30ae98ddd74c0e795f043fe9c6fc Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 26 Apr 2024 19:36:59 -0500 Subject: [PATCH] Use -connect-trusted from next Daemon release The next version of Daemon will have the -connect-trusted option for connecting to a server. If that is available, use it (and begin to respect the custom command line). --- main.cpp | 4 ++-- qmldownloader.cpp | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 55c16ff..1472bfe 100644 --- a/main.cpp +++ b/main.cpp @@ -96,8 +96,8 @@ QString getURLFromPositionalOptions(const QCommandLineParser& parser) url.remove(passwordEnd, 1); } - // When connect URL + custom command are supported together, we have to consider the pessimistic case - // of a custom command line like bash -c "%command%" + // If a custom command is used, we have to consider the pessimistic case + // of a command line like bash -c "%command%" // so metacharacters from any common shells must be forbidden. // What we need to accept are domain names and IP addresses. // Also throw in '@' for limited support of the password feature (unv://hunter2@1.2.3.4) diff --git a/qmldownloader.cpp b/qmldownloader.cpp index d201f57..e5bbc87 100644 --- a/qmldownloader.cpp +++ b/qmldownloader.cpp @@ -185,11 +185,21 @@ void QmlDownloader::startGame() StartGame(settings_, connectUrl_, false); } +// Does our version of daemon have -connect-trusted? +static bool haveConnectTrusted(const QString& gameVersion) +{ + // Updater version up to v0.2.0 may set "unknown" as game version if versions.json request fails + if (gameVersion == "unknown") + return false; + // Hacky string comparision, assume we won't go down to 0.9 or up to 0.100 :) + return gameVersion > "0.54.1"; +} + void StartGame(const Settings& settings, const QString& connectUrl, bool failIfWindowsAdmin) { QString gameCommand = Sys::getGameCommand(settings.installPath()); QString commandLine; - if (!connectUrl.isEmpty()) { + if (!connectUrl.isEmpty() && !haveConnectTrusted(settings.currentVersion())) { // Behave for now as the old protocol handler which ignores the custom command commandLine = gameCommand + " -connect " + connectUrl; } else { @@ -197,6 +207,9 @@ void StartGame(const Settings& settings, const QString& connectUrl, bool failIfW if (!commandLine.contains(COMMAND_REGEX)) { commandLine = "%command% " + commandLine; } + if (!connectUrl.isEmpty()) { + gameCommand = gameCommand + " -connect-trusted " + connectUrl; + } commandLine.replace(COMMAND_REGEX, gameCommand); } qDebug() << "Starting game with command line:" << commandLine;