Skip to content

Commit b7eb81f

Browse files
Kevin AbramsSmallJoker
Kevin Abrams
authored andcommittedDec 18, 2018
Add command line option to load password from file (#7832)
1 parent 80eb762 commit b7eb81f

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed
 

Diff for: ‎doc/minetest.6

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Set player name
7575
.B \-\-password <value>
7676
Set password
7777
.TP
78+
.B \-\-password\-file <value>
79+
Set password from contents of file
80+
.TP
7881
.B \-\-random\-input
7982
Enable random user input, for testing (client only)
8083
.TP

Diff for: ‎src/client/clientlauncher.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,20 @@ bool ClientLauncher::launch_game(std::string &error_message,
392392
if (cmd_args.exists("password"))
393393
menudata.password = cmd_args.get("password");
394394

395+
396+
if (cmd_args.exists("password-file")) {
397+
std::ifstream passfile(cmd_args.get("password-file"));
398+
if (passfile.good()) {
399+
getline(passfile, menudata.password);
400+
} else {
401+
error_message = gettext("Provided password file "
402+
"failed to open: ")
403+
+ cmd_args.get("password-file");
404+
errorstream << error_message << std::endl;
405+
return false;
406+
}
407+
}
408+
395409
// If a world was commanded, append and select it
396410
if (!game_params.world_path.empty()) {
397411
worldspec.gameid = getWorldGameId(game_params.world_path, true);

Diff for: ‎src/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ static void set_allowed_options(OptionList *allowed_options)
308308
_("Set player name"))));
309309
allowed_options->insert(std::make_pair("password", ValueSpec(VALUETYPE_STRING,
310310
_("Set password"))));
311+
allowed_options->insert(std::make_pair("password-file", ValueSpec(VALUETYPE_STRING,
312+
_("Set password from contents of file"))));
311313
allowed_options->insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG,
312314
_("Disable main menu"))));
313315
allowed_options->insert(std::make_pair("console", ValueSpec(VALUETYPE_FLAG,

0 commit comments

Comments
 (0)
Please sign in to comment.