Added --username and --password options for testing purposes.

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.

Manual not updated yet.
This commit is contained in:
Gabriel Morin 2012-01-21 23:16:25 +00:00
parent b55884208c
commit 337cc47f69
3 changed files with 20 additions and 0 deletions

View file

@ -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<unsigned int>(), "seeds the random number generator with number <arg>. Example: --rng-seed 0")
("screenshot", po::value<two_strings>()->multitoken(), "takes two arguments: <map> <output>. Saves a screenshot of <map> to <output> without initializing a screen. Editor must be compiled in for this to work.")
("server,s", po::value<std::string>()->implicit_value(std::string()), "connects to the host <arg> if specified or to the first host in your preferences.")
("username", po::value<std::string>(), "uses <username> when connecting to a server, ignoring other preferences.")
("password", po::value<std::string>(), "uses <password> when connecting to a server, ignoring other preferences.")
("strict-validation", "makes validation errors fatal")
("test,t", po::value<std::string>()->implicit_value(std::string()), "runs the game in a small test scenario. If specified, scenario <arg> 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<std::string>();
if (vm.count("username"))
username = vm["username"].as<std::string>();
if (vm.count("password"))
password = vm["password"].as<std::string>();
if (vm.count("side"))
multiplayer_side = parse_to_uint_string_tuples_(vm["side"].as<std::vector<std::string> >());
if (vm.count("test"))

View file

@ -146,6 +146,10 @@ public:
boost::optional<unsigned int> 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<std::string> server;
/// Non-empty if --username was given on the command line. Forces Wesnoth to use this network username.
boost::optional<std::string> username;
/// Non-empty if --password was given on the command line. Forces Wesnoth to use this network password.
boost::optional<std::string> 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.

View file

@ -236,6 +236,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)