Skip to content

Commit

Permalink
Provide a username CLI flag for fast login
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Feb 19, 2023
1 parent d396165 commit c5113d1
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Sources/Plasma/Apps/plClient/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ enum
kArgStartUpAgeName,
kArgPvdFile,
kArgSkipIntroMovies,
kArgRenderer
kArgRenderer,
kArgUsername
};

static const plCmdArgDef s_cmdLineArgs[] = {
Expand All @@ -111,6 +112,7 @@ static const plCmdArgDef s_cmdLineArgs[] = {
{ kCmdArgFlagged | kCmdTypeString, "PvdFile", kArgPvdFile },
{ kCmdArgFlagged | kCmdTypeBool, "SkipIntroMovies", kArgSkipIntroMovies },
{ kCmdArgFlagged | kCmdTypeString, "Renderer", kArgRenderer },
{ kCmdArgFlagged | kCmdTypeString, "Username", kArgUsername },
};

//
Expand Down Expand Up @@ -241,7 +243,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();
Expand Down Expand Up @@ -272,19 +274,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;
Expand Down Expand Up @@ -610,6 +615,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;
Expand All @@ -628,6 +634,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";
Expand Down Expand Up @@ -680,7 +688,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();
Expand Down

0 comments on commit c5113d1

Please sign in to comment.