From dd6bc6445b865e614fa69860554fe964326e9a13 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 19 Feb 2023 12:39:36 -0800 Subject: [PATCH] Provide a username CLI flag for fast login --- Sources/Plasma/Apps/plClient/linux/main.cpp | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/linux/main.cpp b/Sources/Plasma/Apps/plClient/linux/main.cpp index 0e2a3054cc..552bfc5ef4 100644 --- a/Sources/Plasma/Apps/plClient/linux/main.cpp +++ b/Sources/Plasma/Apps/plClient/linux/main.cpp @@ -102,7 +102,8 @@ enum kArgStartUpAgeName, kArgPvdFile, kArgSkipIntroMovies, - kArgRenderer + kArgRenderer, + kArgUsername }; static const plCmdArgDef s_cmdLineArgs[] = { @@ -116,6 +117,7 @@ static const plCmdArgDef s_cmdLineArgs[] = { { kCmdArgFlagged | kCmdTypeString, "PvdFile", kArgPvdFile }, { kCmdArgFlagged | kCmdTypeBool, "SkipIntroMovies", kArgSkipIntroMovies }, { kCmdArgFlagged | kCmdTypeString, "Renderer", kArgRenderer }, + { kCmdArgFlagged | kCmdTypeString, "Username", kArgUsername }, }; // @@ -244,7 +246,7 @@ static size_t CurlCallback(void *buffer, size_t size, size_t nmemb, void *param) return size * nmemb; } -static bool ConsoleLoginScreen() +static bool ConsoleLoginScreen(const ST::string& cliUsername) { std::thread statusThread = std::thread([]() { ST::string statusUrl = GetServerStatusUrl(); @@ -275,19 +277,22 @@ static bool ConsoleLoginScreen() statusFlag.Wait(); statusThread.join(); - fprintf(stdout, "[Use Ctrl+D to cancel]\nUsername or Email: "); - fflush(stdout); - - char username[kMaxAccountNameLength]; + ST::string username = cliUsername; + if (cliUsername.empty()) { + fprintf(stdout, "[Use Ctrl+D to cancel]\nUsername or Email: "); + fflush(stdout); - if (fscanf(stdin, "%s", username) != 1) { - return false; + char tmpUsername[kMaxAccountNameLength]; + if (fscanf(stdin, "%s", tmpUsername) != 1) { + return false; + } + username = tmpUsername; } pfPasswordStore* store = pfPasswordStore::Instance(); ST::string password = store->GetPassword(username); - if (!password.empty()) { + if (!password.empty() && cliUsername.empty()) { fprintf(stdout, "Use saved password? [y/n] "); fflush(stdout); char c; @@ -652,6 +657,7 @@ int main(int argc, const char** argv) cmdParser.Parse(args); bool doIntroDialogs = true; + ST::string cliUsername; #ifndef PLASMA_EXTERNAL_RELEASE if (cmdParser.IsSpecified(kArgSkipLoginDialog)) doIntroDialogs = false; @@ -672,6 +678,8 @@ int main(int argc, const char** argv) plPXSimulation::SetDefaultDebuggerEndpoint(cmdParser.GetString(kArgPvdFile)); if (cmdParser.IsSpecified(kArgRenderer)) gClient.SetRequestedRenderingBackend(ParseRendererArgument(cmdParser.GetString(kArgRenderer))); + if (cmdParser.IsSpecified(kArgUsername)) + cliUsername = cmdParser.GetString(kArgUsername); #endif plFileName serverIni = "server.ini"; @@ -724,7 +732,7 @@ int main(int argc, const char** argv) curl_global_init(CURL_GLOBAL_ALL); // Login stuff - if (!ConsoleLoginScreen()) { + if (!ConsoleLoginScreen(cliUsername)) { gClient.ShutdownStart(); gClient.ShutdownEnd(); NetCommShutdown();