From: Kevin Abrams <21090310+kkabrams@users.noreply.github.com> Date: Tue, 18 Dec 2018 19:15:14 +0000 (-0600) Subject: Add command line option to load password from file (#7832) X-Git-Tag: 5.0.0~120 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b7eb81fed922f7215cfff1068389fa85b2ee4ab2;p=oweals%2Fminetest.git Add command line option to load password from file (#7832) --- diff --git a/doc/minetest.6 b/doc/minetest.6 index 50b085de0..c1c814e49 100644 --- a/doc/minetest.6 +++ b/doc/minetest.6 @@ -75,6 +75,9 @@ Set player name .B \-\-password Set password .TP +.B \-\-password\-file +Set password from contents of file +.TP .B \-\-random\-input Enable random user input, for testing (client only) .TP diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 0820177b4..9dfd248a2 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -392,6 +392,20 @@ bool ClientLauncher::launch_game(std::string &error_message, if (cmd_args.exists("password")) menudata.password = cmd_args.get("password"); + + if (cmd_args.exists("password-file")) { + std::ifstream passfile(cmd_args.get("password-file")); + if (passfile.good()) { + getline(passfile, menudata.password); + } else { + error_message = gettext("Provided password file " + "failed to open: ") + + cmd_args.get("password-file"); + errorstream << error_message << std::endl; + return false; + } + } + // If a world was commanded, append and select it if (!game_params.world_path.empty()) { worldspec.gameid = getWorldGameId(game_params.world_path, true); diff --git a/src/main.cpp b/src/main.cpp index 546eb2a00..26ad978c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -308,6 +308,8 @@ static void set_allowed_options(OptionList *allowed_options) _("Set player name")))); allowed_options->insert(std::make_pair("password", ValueSpec(VALUETYPE_STRING, _("Set password")))); + allowed_options->insert(std::make_pair("password-file", ValueSpec(VALUETYPE_STRING, + _("Set password from contents of file")))); allowed_options->insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG, _("Disable main menu")))); allowed_options->insert(std::make_pair("console", ValueSpec(VALUETYPE_FLAG,