Add command line option to load password from file (#7832)
authorKevin Abrams <21090310+kkabrams@users.noreply.github.com>
Tue, 18 Dec 2018 19:15:14 +0000 (13:15 -0600)
committerSmallJoker <SmallJoker@users.noreply.github.com>
Tue, 18 Dec 2018 19:15:14 +0000 (20:15 +0100)
doc/minetest.6
src/client/clientlauncher.cpp
src/main.cpp

index 50b085de0faf60f5313d900ddf2c906178f6e689..c1c814e49b5e50a40594f3611b7e1809c662575f 100644 (file)
@@ -75,6 +75,9 @@ Set player name
 .B \-\-password <value>
 Set password
 .TP
+.B \-\-password\-file <value>
+Set password from contents of file
+.TP
 .B \-\-random\-input
 Enable random user input, for testing (client only)
 .TP
index 0820177b4d38e47a323a0266c374533990ca8f61..9dfd248a2bb15b71cd716316e0232fe4845af9de 100644 (file)
@@ -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);
index 546eb2a00e7ac487c6f5236ecf6e2b4621f0ebea..26ad978c6f205cb3de34127428b7c73379429207 100644 (file)
@@ -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,