void help()
	{
		//print command-specific help if available, otherwise list commands
		if (help_command(get_arg(1))) {
			return;
		}
		std::stringstream ss;
		bool show_unavail = show_unavailable_ || get_arg(1) == "all";
		for (typename command_map::value_type i : command_map_) {
			if (show_unavail || is_enabled(i.second)) {
				ss << i.first;
				//if (!i.second.usage.empty()) {
				//	ss << " " << i.second.usage;
				//}
				//uncomment the above to display usage information in command list
				//which might clutter it somewhat
				if (!i.second.flags.empty()) {
					ss << " (" << i.second.flags << ") ";
				}
				ss << "; ";
			}
		}
		utils::string_map symbols;
		symbols["flags_description"] = get_flags_description();
		symbols["list_of_commands"] = ss.str();
		symbols["help_command"] = cmd_prefix_ + "help";
		print(_("help"), VGETTEXT("Available commands $flags_description:\n$list_of_commands", symbols));
		print(_("help"), VGETTEXT("Type $help_command <command> for more info.", symbols));
	}
示例#2
0
void chat_command_handler::do_register() {
	config data;
	config& nickserv = data.add_child("nickserv");

	if (get_data(1).empty()) return command_failed_need_arg(1);

	config &reg = nickserv.add_child("register");
	reg["password"] = get_arg(1);
	if (!get_data(2).empty()) {
		reg["mail"] = get_arg(2);
	}
	std::string msg;
	if (get_data(2).empty()) {
		msg = _("registering with password *** and no email address");
	}
	else {
		utils::string_map symbols;
		symbols["email"] = get_data(2);
		msg = VGETTEXT("registering with password *** and "
			"email address $email", symbols);
	}
	print(_("nick registration"), msg);

	chat_handler_.send_to_server(data);
}
示例#3
0
void chat_command_handler::do_ignore()
{
	if (get_arg(1).empty()) {
		do_display();
	}
	else {
		utils::string_map symbols;
		symbols["nick"] = get_arg(1);

		if (preferences::add_acquaintance(get_arg(1), "ignore", get_data(2))) {
			print(_("ignores list"), VGETTEXT("Added to ignore list: $nick", symbols));
			chat_handler_.user_relation_changed(get_arg(1));
		}
		else {
			command_failed(VGETTEXT("Invalid username: $nick", symbols));
		}
	}
}
示例#4
0
tlobby_chat_window* tlobby_main::search_create_window(const std::string& name,
													  bool whisper,
													  bool open_new)
{
	for(auto & t : open_windows_) {
		if(t.name == name && t.whisper == whisper)
			return &t;
	}

	if(open_new) {
		open_windows_.push_back(tlobby_chat_window(name, whisper));
		std::map<std::string, string_map> data;
		utils::string_map symbols;
		symbols["name"] = name;
		if(whisper) {
			add_label_data(data, "log_text",
			   VGETTEXT("Whisper session with $name started. "
						"If you do not want to receive messages "
						"from this user, "
						"type /ignore $name\n",
						symbols));
		} else {
			add_label_data(data, "log_text", VGETTEXT("<i>Room $name joined</i>", symbols));
			lobby_info_.open_room(name);
		}

		chat_log_container_->add_page(data);
		std::map<std::string, string_map> data2;
		add_label_data(data2, "room", whisper ? "<" + name + ">" : name);
		tgrid* row_grid = &roomlistbox_->add_row(data2);

		tbutton& close_button = find_widget<tbutton>(row_grid, "close_window", false);
		connect_signal_mouse_left_click(close_button,
			std::bind(&tlobby_main::close_window_button_callback,
					this, roomlistbox_->get_item_count() - 1));

		if(name == "lobby") {
			close_button.set_visible(tcontrol::tvisible::hidden);
		}

		return &open_windows_.back();
	}
	return nullptr;
}
示例#5
0
void chat_command_handler::do_remove()
{
	for (int i = 1;!get_arg(i).empty();i++) {
		preferences::remove_acquaintance(get_arg(i));
		chat_handler_.user_relation_changed(get_arg(i));
		utils::string_map symbols;
		symbols["nick"] = get_arg(i);
		print(_("friends and ignores list"), VGETTEXT("Removed from list: $nick", symbols));
	}
}
示例#6
0
std::string irdya_date::to_string() const
{
	utils::string_map args {{"year", std::to_string(year)}};

	switch(epoch.v) {
	case EPOCH::BEFORE_WESNOTH:
		// TRANSLATORS: "Before Wesnoth"   - format for years prior to the founding of Wesnoth
		return VGETTEXT("$year BW", args);
	case EPOCH::WESNOTH:
		// TRANSLATORS: "Year of Wesnoth"  - format for years after the founding of Wesnoth
		return VGETTEXT("$year YW", args);
	case EPOCH::BEFORE_FALL:
		// TRANSLATORS: "Before the Fall" -  format for years prior to the fall of Wesnoth
		return VGETTEXT("$year BF", args);
	case EPOCH::AFTER_FALL:
		// TRANSLATORS: "After the Fall"   - format for years after the fall of Wesonth
		return VGETTEXT("$year AF", args);
	}

	return "";
}
示例#7
0
void chat_command_handler::do_info() {
	if (get_data(1).empty()) return command_failed_need_arg(1);

	config data;
	config& nickserv = data.add_child("nickserv");

	nickserv.add_child("info")["name"] = get_data(1);
	utils::string_map symbols;
	symbols["nick"] = get_arg(1);
	print(_("nick registration"), VGETTEXT("requesting information for user $nick", symbols));

	chat_handler_.send_to_server(data);
}
示例#8
0
void tlobby_main::update_gamelist_header()
{
#ifndef GUI2_EXPERIMENTAL_LISTBOX
	utils::string_map symbols;
	symbols["num_shown"]
			= std::to_string(lobby_info_.games_filtered().size());
	symbols["num_total"]
			= std::to_string(lobby_info_.games().size());
	std::string games_string
			= VGETTEXT("Games: showing $num_shown out of $num_total", symbols);
	find_widget<tlabel>(gamelistbox_, "map", false).set_label(games_string);
#endif
}
示例#9
0
void tlobby_main::process_room_join(const config& data)
{
	const std::string& room = data["room"];
	const std::string& player = data["player"];
	room_info* r = lobby_info_.get_room(room);
	DBG_LB << "room join: " << room << " " << player << " "
		   << static_cast<void*>(r) << "\n";

	if(r) {
		if(player == preferences::login()) {
			if(const config& members = data.child("members")) {
				r->process_room_members(members);
			}
		} else {
			r->add_member(player);
			/* TODO: add/use preference */
			utils::string_map symbols;
			symbols["player"] = player;
			add_room_window_message(
					room,
					"server",
					VGETTEXT("$player has entered the room", symbols));
		}
		if(r == active_window_room()) {
			player_list_dirty_ = true;
		}
	} else {
		if(player == preferences::login()) {
			tlobby_chat_window* t = room_window_open(room, true);
			lobby_info_.open_room(room);
			r = lobby_info_.get_room(room);
			assert(r);
			if(const config& members = data.child("members")) {
				r->process_room_members(members);
			}
			switch_to_window(t);

			const std::string& topic = data["topic"];
			if(!topic.empty()) {
				add_chat_room_message_received(
						"room", "server", room + ": " + topic);
			}
		} else {
			LOG_LB << "Discarding join info for a room the player is not in\n";
		}
	}
}
示例#10
0
void chat_command_handler::do_set() {
	config data;
	config& nickserv = data.add_child("nickserv");

	if (get_data(1).empty()) return command_failed_need_arg(1);
	if (get_data(2).empty()) return command_failed_need_arg(2);

	config &set = nickserv.add_child("set");
	set["detail"] = get_arg(1);
	set["value"] = get_data(2);
	utils::string_map symbols;
	symbols["var"] = get_arg(1);
	symbols["value"] = get_arg(2);
	print(_("nick registration"), VGETTEXT("setting $var to $value", symbols));

	chat_handler_.send_to_server(data);
}
示例#11
0
void tlobby_main::add_whisper_sent(const std::string& receiver,
								   const std::string& message)
{
	if(whisper_window_active(receiver)) {
		add_active_window_message(preferences::login(), message, true);
	} else if(tlobby_chat_window* t = whisper_window_open(
					  receiver, preferences::auto_open_whisper_windows())) {
		switch_to_window(t);
		add_active_window_message(preferences::login(), message, true);
	} else {
		utils::string_map symbols;
		symbols["receiver"] = receiver;
		add_active_window_whisper(VGETTEXT("whisper to $receiver", symbols),
								  message, true);
	}
	lobby_info_.get_whisper_log(receiver)
			.add_message(preferences::login(), message);
}
示例#12
0
void tlobby_main::process_room_part(const config& data)
{
	// todo close room window when the part message is sent
	const std::string& room = data["room"];
	const std::string& player = data["player"];
	DBG_LB << "Room part: " << room << " " << player << "\n";
	room_info* r = lobby_info_.get_room(room);
	if(r) {
		r->remove_member(player);
		/* TODO: add/use preference */
		utils::string_map symbols;
		symbols["player"] = player;
		add_room_window_message(
				room, "server", VGETTEXT("$player has left the room", symbols));
		if(active_window_room() == r) {
			player_list_dirty_ = true;
		}
	} else {
		LOG_LB << "Discarding part info for a room the player is not in\n";
	}
}
	//actual work function
	void dispatch(std::string cmd)
	{
		if (empty()) {
			init_map_default();
			init_map();
		}

		// We recursively resolve alias (100 max to avoid infinite recursion)
		for (int i = 0; i < 100; ++i) {
			parse_cmd(cmd);
			std::string actual_cmd = get_actual_cmd(get_cmd());
			if (actual_cmd == get_cmd())
				break;
			std::string data = get_data(1);
			// translate the command and add space + data if any
			cmd = actual_cmd + (data.empty() ? "" : " ") + data;
		}

		if (get_cmd().empty()) {
			return;
		}

		if (const command* c = get_command(get_cmd())) {
			if (is_enabled(*c)) {
				(static_cast<Worker*>(this)->*(c->handler))();
			}
			else {
				print(get_cmd(), _("This command is currently unavailable."));
			}
		}
		else if (help_on_unknown_) {
			utils::string_map symbols;
			symbols["command"] = get_cmd();
			symbols["help_command"] = cmd_prefix_ + "help";
			print("help", VGETTEXT("Unknown command '$command', try $help_command "
				"for a list of available commands.", symbols));
		}
	}
示例#14
0
void tgame_version::pre_show(twindow& window)
{
	string_map i18n_syms;

	//
	// General information.
	//

	tcontrol& version_label = find_widget<tcontrol>(&window, "version", false);
	i18n_syms["version"] = game_config::revision;
	version_label.set_label(VGETTEXT("Version $version", i18n_syms));

	tcontrol& os_label = find_widget<tcontrol>(&window, "os", false);
	i18n_syms["os"] = desktop::os_version();
	os_label.set_label(VGETTEXT("Running on $os", i18n_syms));

	tbutton& copy_all = find_widget<tbutton>(&window, "copy_all", false);
	connect_signal_mouse_left_click(
			copy_all,
			std::bind(&tgame_version::report_copy_callback, this));

	//
	// Game paths tab.
	//

	for(const auto & path_ent : path_map_)
	{
		const std::string& path_id = path_ent.first;
		const std::string& path_path = path_ent.second;

		ttext_& path_w
				= find_widget<ttext_>(&window, path_wid_stem_ + path_id, false);
		tbutton& copy_w = find_widget<tbutton>(
				&window, copy_wid_stem_ + path_id, false);
		tbutton& browse_w = find_widget<tbutton>(
				&window, browse_wid_stem_ + path_id, false);

		path_w.set_value(path_path);
		path_w.set_active(false);

		connect_signal_mouse_left_click(
				copy_w,
				std::bind(&tgame_version::copy_to_clipboard_callback,
							this,
							path_path));
		connect_signal_mouse_left_click(
				browse_w,
				std::bind(&tgame_version::browse_directory_callback,
							this,
							path_path));

		if(!desktop::open_object_is_supported()) {
			// No point in displaying these on platforms that can't do
			// open_object().
			browse_w.set_visible(tcontrol::tvisible::invisible);
		}

		if(!desktop::clipboard::available()) {
			copy_w.set_active(false);
			copy_w.set_tooltip(_("Clipboard support not found, contact your packager"));
		}
	}

#ifndef _WIN32
	tgrid& w32_options_grid
			= find_widget<tgrid>(&window, "win32_paths", false);
	w32_options_grid.set_visible(twidget::tvisible::invisible);
#else
	tbutton& stderr_button
			= find_widget<tbutton>(&window, "open_stderr", false);
	connect_signal_mouse_left_click(
			stderr_button,
			std::bind(&tgame_version::browse_directory_callback,
						this,
						log_path_));
	stderr_button.set_active(!log_path_.empty());
#endif

	//
	// Build info tab.
	//

	std::map<std::string, string_map> list_data;

	tlistbox& deps_listbox
			= find_widget<tlistbox>(&window, "deps_listbox", false);

	for(const auto & dep : deps_)
	{
		list_data["dep_name"]["label"] = dep[0];

		list_data["dep_build_version"]["label"] = dep[1];

		// The build version is always known, but runtime version isn't, esp.
		// for header-only libraries like Boost for which the concept does not
		// apply.
		if(!dep[2].empty()) {
			list_data["dep_rt_version"]["label"] = dep[2];
		} else {
			list_data["dep_rt_version"]["label"] = _("version^N/A");
		}

		deps_listbox.add_row(list_data);
	}

	deps_listbox.select_row(0);
	list_data.clear();

	//
	// Features tab.
	//

	tlistbox& opts_listbox
			= find_widget<tlistbox>(&window, "opts_listbox", false);

	for(const auto & opt : opts_)
	{
		list_data["opt_name"]["label"] = opt.name;

		if(opt.enabled) {
			list_data["opt_status"]["label"] = text_feature_on;
		} else {
			list_data["opt_status"]["label"] = text_feature_off;
		}
		list_data["opt_status"]["use_markup"] = "true";

		opts_listbox.add_row(list_data);
	}

	opts_listbox.select_row(0);
	list_data.clear();

	//
	// Set-up page stack and auxiliary controls last.
	//

	tstacked_widget& pager
			= find_widget<tstacked_widget>(&window, "tabs_container", false);
	pager.select_layer(0);

	tlistbox& tab_bar
			= find_widget<tlistbox>(&window, "tab_bar", false);

	window.keyboard_capture(&tab_bar);

	const unsigned tab_count = tab_bar.get_item_count();
	VALIDATE(tab_count == pager.get_layer_count(), "Tab bar and container size mismatch");

#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(tab_bar,
		std::bind(&tgame_version::tab_switch_callback, *this, std::ref(window)));
#else
	tab_bar.set_callback_value_change(
		dialog_callback<tgame_version, &tgame_version::tab_switch_callback>);
#endif
}
示例#15
0
void chat_handler::add_whisper_received(const std::string& sender, const std::string& message)
{
	utils::string_map symbols;
	symbols["sender"] = sender;
	add_chat_message(time(nullptr), VGETTEXT("whisper: $sender", symbols), 0, message);
}
示例#16
0
void chat_handler::add_whisper_sent(const std::string& receiver, const std::string& message)
{
	utils::string_map symbols;
	symbols["receiver"] = receiver;
	add_chat_message(time(nullptr), VGETTEXT("whisper to $receiver", symbols), 0, message);
}
示例#17
0
config initial_level_config(saved_game& state)
{
	const mp_game_settings& params = state.mp_settings();
	state.set_defaults();

	// Also impliers state.expand_scenario()
	// We need to call this before expand_mp_events/options otherwise they might be overwritten.
	state.expand_random_scenario();
	state.expand_mp_events();
	state.expand_mp_options();

	if(!state.valid()) {
		throw config::error("Failed to load the scenario");
	}

	config& scenario = state.get_starting_point();
	if(state.mp_settings().saved_game == mp_game_settings::SAVED_GAME_MODE::NONE) {
		state.set_random_seed();
	}

	if(scenario["objectives"].empty()) {
		// Generic victory objectives.
		std::ostringstream ss;
		ss << "<big>";
		ss << t_string(N_("Victory:"), "wesnoth") << "</big>\n";
		ss << "<span color='#00ff00'>" << font::unicode_bullet << " ";
		ss << t_string(N_("Defeat enemy leader(s)"), "wesnoth") << "</span>";

		scenario["objectives"] = ss.str();
	}

	config level = state.to_config();
	add_multiplayer_classification(level.child_or_add("multiplayer"), state);

	// [multiplayer] mp_era= should be persistent over saves.
	std::string era = params.mp_era;

	/**
	 * [era] and [modification]s are toplevel tags here.
	 * They are not part of the saved_game and are only used during mp_staging/mp_join_game.
	 *
	 * @todo: see if all the comments ai algorithms are still up-to-date and relevant.
	 *
	 * -- vultraz, 2017-11-24
	 */

	const config& game_config = game_config_manager::get()->game_config();
	const config& era_cfg = game_config.find_child("era", "id", era);

	if(!era_cfg) {
		if(params.saved_game == mp_game_settings::SAVED_GAME_MODE::NONE) {
			throw config::error(VGETTEXT("Cannot find era $era", {{"era", era}}));
		}

		// FIXME: @todo We should tell user about missing era but still load game...
		WRN_CF << "Missing era in MP load game " << era << std::endl;

		// Otherwise we get an error when when we try to add ai algorithms in mp_staging.
		level.add_child("era");
	} else {
		level.add_child("era", era_cfg);

		// Initialize the list of sides available for the current era.
		// We also need this so not to get a segfault in mp_staging for ai configuration.
		const config& custom_side = game_config.find_child("multiplayer_side", "id", "Custom");
		level.child("era").add_child_at("multiplayer_side", custom_side, 0);
	}

	// Add modifications, needed for ai algorithms which are applied in mp_staging.
	const std::vector<std::string>& mods = params.active_mods;

	for(unsigned i = 0; i < mods.size(); ++i) {
		if(const config& mod_cfg = game_config.find_child("modification", "id", mods[i])) {
			level.add_child("modification", mod_cfg);
		}
	}

	// This will force connecting clients to be using the same version number as us.
	level["version"] = game_config::wesnoth_version.str();
	return level;
}
	void command_failed_need_arg(int argn)
	{
		utils::string_map symbols;
		symbols["arg_id"] = std::to_string(argn);
		command_failed(VGETTEXT("Missing argument $arg_id", symbols));
	}