From 46b997d11d59d2be5e5c7ac03aa9c3909e97fd8e Mon Sep 17 00:00:00 2001 From: Gabriel Morin Date: Sat, 4 Feb 2012 12:02:41 +0000 Subject: [PATCH] Added --username and --password options. Together with the --server option they allow starting several clients that all join the server automatically. When these options are used, preferences are not saved. man page updated, hope I didn't miss anything. --- doc/man/wesnoth.6 | 6 ++++++ src/commandline_options.cpp | 8 ++++++++ src/commandline_options.hpp | 4 ++++ src/game_controller.cpp | 8 ++++++++ 4 files changed, 26 insertions(+) diff --git a/doc/man/wesnoth.6 b/doc/man/wesnoth.6 index 57bea47ee11..cfb09ebd882 100644 --- a/doc/man/wesnoth.6 +++ b/doc/man/wesnoth.6 @@ -189,6 +189,12 @@ sets the screen resolution. Example: connects to the specified host if any, otherwise connect to the first server in preferences. Example: .B --server server.wesnoth.org .TP +.BI --username +uses when connecting to a server, ignoring other preferences. +.TP +.BI --password +uses when connecting to a server, ignoring other preferences. Unsafe. +.TP .B --strict-validation validation errors are treated as fatal errors. .TP diff --git a/src/commandline_options.cpp b/src/commandline_options.cpp index 07e5f9caa7f..8718e7ad1a7 100644 --- a/src/commandline_options.cpp +++ b/src/commandline_options.cpp @@ -100,6 +100,8 @@ commandline_options::commandline_options ( int argc, char** argv ) : resolution(), rng_seed(), server(), + username(), + password(), screenshot(false), screenshot_map_file(), screenshot_output_file(), @@ -145,6 +147,8 @@ commandline_options::commandline_options ( int argc, char** argv ) : ("rng-seed", po::value(), "seeds the random number generator with number . Example: --rng-seed 0") ("screenshot", po::value()->multitoken(), "takes two arguments: . Saves a screenshot of to without initializing a screen. Editor must be compiled in for this to work.") ("server,s", po::value()->implicit_value(std::string()), "connects to the host if specified or to the first host in your preferences.") + ("username", po::value(), "uses when connecting to a server, ignoring other preferences.") + ("password", po::value(), "uses when connecting to a server, ignoring other preferences.") ("strict-validation", "makes validation errors fatal") ("test,t", po::value()->implicit_value(std::string()), "runs the game in a small test scenario. If specified, scenario will be used instead.") ("validcache", "assumes that the cache is valid. (dangerous)") @@ -351,6 +355,10 @@ commandline_options::commandline_options ( int argc, char** argv ) : } if (vm.count("server")) server = vm["server"].as(); + if (vm.count("username")) + username = vm["username"].as(); + if (vm.count("password")) + password = vm["password"].as(); if (vm.count("side")) multiplayer_side = parse_to_uint_string_tuples_(vm["side"].as >()); if (vm.count("test")) diff --git a/src/commandline_options.hpp b/src/commandline_options.hpp index a0fb7f36a86..cd32ebc11fb 100644 --- a/src/commandline_options.hpp +++ b/src/commandline_options.hpp @@ -146,6 +146,10 @@ public: boost::optional rng_seed; /// Non-empty if --server was given on the command line. Connects Wesnoth to specified server. If no server was specified afterwards, contains an empty string. boost::optional server; + /// Non-empty if --username was given on the command line. Forces Wesnoth to use this network username. + boost::optional username; + /// Non-empty if --password was given on the command line. Forces Wesnoth to use this network password. + boost::optional password; /// True if --screenshot was given on the command line. Starts Wesnoth in screenshot mode. bool screenshot; /// Map file to make a screenshot of. First parameter given after --screenshot. diff --git a/src/game_controller.cpp b/src/game_controller.cpp index 0e12f55a4f7..bf4c73ca350 100644 --- a/src/game_controller.cpp +++ b/src/game_controller.cpp @@ -237,6 +237,14 @@ game_controller::game_controller(const commandline_options& cmdline_opts, const multiplayer_server_ = ""; } } + if (cmdline_opts_.username) { + preferences::disable_preferences_save(); + preferences::set_login(*cmdline_opts_.username); + } + if (cmdline_opts_.password) { + preferences::disable_preferences_save(); + preferences::set_password(*cmdline_opts_.password); + } if (cmdline_opts_.smallgui) game_config::small_gui = true; if (cmdline_opts_.test)