17 #define GETTEXT_DOMAIN "wesnoth-lib"
34 #include <boost/range/iterator_range.hpp>
38 #ifdef INADDR_BROADCAST
39 #undef INADDR_BROADCAST
49 #define ERR_CFG LOG_STREAM(err , log_config)
53 bool message_private_on =
false;
57 std::map<std::string, std::set<std::string> > completed_campaigns;
58 std::set<std::string> encountered_units_set;
59 std::set<t_translation::t_terrain> encountered_terrains_set;
61 std::map<std::string, std::vector<std::string> > history_map;
63 std::map<std::string, preferences::acquaintance> acquaintances;
65 std::vector<std::string> mp_modifications;
66 bool mp_modifications_initialized =
false;
67 std::vector<std::string> sp_modifications;
68 bool sp_modifications_initialized =
false;
71 bool options_initialized =
false;
73 bool authenticated =
false;
75 const char WRAP_CHAR =
'@';
80 return WRAP_CHAR + value + WRAP_CHAR;
85 if(raw.empty() || raw == EMPTY_WRAPPED_STRING) {
88 }
else if(raw.length() < 2 || raw[0] != WRAP_CHAR || raw[raw.length() - 1] != WRAP_CHAR ) {
90 ERR_CFG <<
"malformed user credentials (did you manually edit the preferences file?)" << std::endl;
94 return raw.substr(1, raw.length() - 2);
97 void initialize_modifications(
bool mp =
true)
101 mp_modifications_initialized =
true;
104 sp_modifications_initialized =
true;
137 completed_campaigns[
c];
141 std::set<std::string> &
d = completed_campaigns[cc[
"name"]];
142 std::vector<std::string> nd =
utils::split(cc[
"difficulty_levels"]);
143 std::copy(nd.begin(), nd.end(), std::inserter(d, d.begin()));
148 encountered_units_set.insert(v.begin(), v.end());
151 encountered_terrains_set.insert(terrain.begin(), terrain.end());
165 history_map[
h.key].push_back(
l[
"message"]);
176 typedef const std::pair<std::string, std::set<std::string> > cc_elem;
177 for (cc_elem &elem : completed_campaigns) {
179 cmp[
"name"] = elem.first;
180 cmp[
"difficulty_levels"] =
utils::join(elem.second);
184 std::vector<std::string>
v (encountered_units_set.begin(), encountered_units_set.end());
197 typedef std::pair<std::string, std::vector<std::string> > hack;
198 for (
const hack& history_id : history_map) {
201 for (
const std::string& line : history_id.second) {
204 cfg[
"message"] = line;
208 history.
add_child(history_id.first, history_id_cfg);
213 encountered_units_set.clear();
214 encountered_terrains_set.clear();
218 return authenticated;
222 if(sender !=
"server")
return;
223 if(message.find(
"You are now recognized as an administrator.") == 0) {
224 authenticated =
true;
225 }
else if(message.find(
"You are no longer recognized as an administrator.") == 0) {
226 authenticated =
false;
236 authenticated =
false;
240 if(acquaintances.empty()) {
254 i != acquaintances.end(); ++
i)
257 i->second.save(item);
263 return acquaintances;
269 std::map<std::string, std::string> ac_nice;
273 if(
i->second.get_status() ==
filter) {
274 ac_nice[
i->second.get_nick()] =
i->second.get_notes();
299 if(i == acquaintances.end()) {
300 size_t pos = nick.find_first_of(
' ');
302 if(pos != std::string::npos) {
303 i = acquaintances.find(nick.substr(0, pos));
307 if(i == acquaintances.end()) {
311 acquaintances.erase(i);
321 >::const_iterator it = acquaintances.find(nick);
323 if(it == acquaintances.end()) {
334 >::const_iterator it = acquaintances.find(nick);
336 if(it == acquaintances.end()) {
344 completed_campaigns[campaign_id].insert(difficulty_level);
348 return completed_campaigns.count(campaign_id) != 0;
352 std::map<std::string, std::set<std::string> >
::iterator it = completed_campaigns.find(campaign_id);
353 return it == completed_campaigns.end() ?
false : it->second.count(difficulty_level) != 0;
359 if (sender !=
"server")
return true;
360 std::string::size_type
pos = message.find(
" has logged into the lobby");
361 if (pos == std::string::npos){
362 pos = message.find(
" has disconnected");
363 if (pos == std::string::npos)
return true;
368 return is_friend(message.substr(0, pos));
374 if (pref ==
"friends") {
376 }
else if (pref ==
"all") {
378 }
else if (pref ==
"none") {
399 return get(
"new_lobby",
false);
404 static std::vector<game_config::server_info> pref_servers;
405 if(pref_servers.empty()) {
407 VALIDATE(!game_servers.empty(),
_(
"No server has been defined."));
408 pref_servers.insert(pref_servers.begin(), game_servers.begin(), game_servers.end());
411 sinf.
name = server[
"name"].str();
412 sinf.
address = server[
"address"].str();
413 pref_servers.push_back(sinf);
444 return "add-ons.wesnoth.org";
455 const bool have_old_password_format =
457 return have_old_password_format ?
false :
preferences::get(
"password_is_wrapped",
true);
467 const bool have_old_login_format =
469 return have_old_login_format ?
false :
preferences::get(
"login_is_wrapped",
true);
483 if(GetUserNameW(buffer,&size)) {
489 if(
char*
const login = getenv(
"USER")) {
499 if(res.empty() || res == EMPTY_WRAPPED_STRING) {
513 return parse_wrapped_credentials_field(res);
534 return parse_wrapped_credentials_field(saved_pass);
646 return lexical_cast_default<int>(
preferences::get(
"mp_server_warning_disabled"), 0);
713 if (options_initialized) {
714 return option_values;
726 options_initialized =
true;
728 return option_values;
734 options_initialized =
false;
769 return lexical_cast_in_range<int>
780 return lexical_cast_in_range<int>(
791 return lexical_cast_in_range<int>(
802 return lexical_cast_in_range<int>(
873 if ((!mp_modifications_initialized && mp) || (!sp_modifications_initialized && !mp))
874 initialize_modifications(mp);
876 return mp ? mp_modifications : sp_modifications;
883 mp_modifications_initialized =
false;
886 sp_modifications_initialized =
false;
982 if(theme !=
"null") {
999 return message_private_on;
1004 message_private_on =
value;
1025 if(choice.empty() || choice ==
"gzip" || choice ==
"yes") {
1027 }
else if(choice ==
"bzip2") {
1029 }
else if(choice ==
"none" || choice ==
"no") {
1076 return lexical_cast_default<int>(
preferences::get(
"chat_message_aging"), 20);
1086 return lexical_cast_default<int>(
preferences::get(
"max_wml_menu_items"), 7);
1098 return encountered_units_set;
1102 return encountered_terrains_set;
1120 return &history_map[
id];
1127 if (confirmation ==
"green" || confirmation ==
"yes")
1141 return confirmation ==
"no_moves" || confirmation.empty();
1146 for (std::vector<team>::const_iterator help_team_it = teams.begin();
1147 help_team_it != teams.end(); ++help_team_it) {
1148 help_team_it->log_recruitable();
1149 encountered_units_set.insert(help_team_it->recruits().begin(), help_team_it->recruits().end());
1155 help_unit_it != units.
end(); ++help_unit_it) {
1156 encountered_units_set.insert(help_unit_it->type_id());
1161 for (
const team&
t : teams) {
1163 encountered_units_set.insert(u->type_id());
1169 for (
int map_x = 0; map_x < map.
w(); ++map_x) {
1170 for (
int map_y = 0; map_y < map.
h(); ++map_y) {
1174 for (std::vector<t_translation::t_terrain>::const_iterator ut = underlaying_list.begin(); ut != underlaying_list.end(); ++ut) {
1190 nick_ = cfg[
"nick"].str();
1191 status_ = cfg[
"status"].str();
1192 notes_ = cfg[
"notes"].str();
1197 item[
"nick"] =
nick_;
void set_password(const std::string &password)
child_itors child_range(const std::string &key)
void set_hide_whiteboard(bool value)
bool isvalid_wildcard(const std::string &username)
Check if the username pattern contains only valid characters.
void set_campaign_server(const std::string &host)
virtual const unit_map & units() const
void set_village_support(int value)
void set_wrap_password(bool wrap)
void set_show_haloes(bool value)
std::string random_faction_mode()
static void encounter_recallable_units(const std::vector< team > &teams)
unsigned int get_ping_timeout()
void set_countdown_action_bonus(int value)
void set_countdown_turn_bonus(int value)
t_list read_list(const std::string &str, const t_layer filler)
Reads a list of terrains from a string, when reading the.
std::string get_timestamp(const time_t &t, const std::string &format)
void set_shroud(bool value)
static lg::log_domain log_config("config")
void set_countdown_init_time(int value)
std::string campaign_server()
void set_mp_server_warning_disabled(int value)
bool wrap_login()
Returns whether the MP username is stored wrapped in markers.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
void set_remember_password(bool remember)
void set_show_floating_labels(bool value)
void set_options(const config &values)
bool wrap_password()
Returns whether the password is stored wrapped in markers.
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
const std::map< std::string, acquaintance > & get_acquaintances()
bool is_campaign_completed(const std::string &campaign_id)
void set_show_side_colors(bool value)
std::string network_host()
void load_from_config(const config &cfg)
void parse_admin_authentication(const std::string &sender, const std::string &message)
void clear(const std::string &key)
void set_login(const std::string &username)
void _set_lobby_joins(int show)
void set_chat_lines(int lines)
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
std::string status_
status (e.g., "friend", "ignore")
void set_random_faction_mode(const std::string &value)
static CVideo & get_singleton()
static void load_acquaintances()
void set(const std::string &key, bool value)
virtual const std::vector< team > & teams() const
void set_network_host(const std::string &host)
void set_sound_volume(int vol)
void clear_children(const std::string &key)
void set_countdown(bool value)
const t_translation::t_list & underlying_union_terrain(const map_location &loc) const
bool remove_acquaintance(const std::string &nick)
void set_interrupt_when_ally_sighted(bool value)
int countdown_init_time()
std::string address
may include ':' followed by port number
void set_registered_users_only(bool value)
void set_max_wml_menu_items(int max)
GLboolean GLenum GLenum GLvoid * values
int get_village_support(const std::string &value)
Gets the village unit level support.
void set_mp_server_program_name(const std::string &path)
This module controls the multiplayer lobby.
static std::vector< team > *& teams
void set_chat_message_aging(const int aging)
This class stores all the data for a single 'side' (in game nomenclature).
void set_turn_dialog(bool ison)
static UNUSEDNOWARN std::string _(const char *str)
int countdown_turn_bonus()
void set_level_type(int value)
std::string get(const std::string &key)
void set_custom_command(const std::string &command)
GLsizei const char ** path
static void save_acquaintances()
void set_save_replays(bool value)
bool is_friend(const std::string &nick)
std::string write_list(const t_list &list)
Writes a list of terrains to a string, only writes the new format.
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
void set_theme(const std::string &theme)
void encounter_map_terrain(const gamemap &map)
General settings and defaults for scenarios.
void encounter_start_units(const unit_map &units)
static std::string get_system_username()
int countdown_reservoir_time()
GLsizei const GLfloat * value
void set_enable_whiteboard_mode_on_start(bool value)
int w() const
Effective map width.
void set_music_volume(int vol)
std::set< t_translation::t_terrain > & encountered_terrains()
Encapsulates the map of the game.
const std::vector< game_config::server_info > & server_list()
void erase(const std::string &key)
void set_random_start_time(bool value)
config & add_child(const std::string &key)
const std::string & get_status() const
Modify, read and display user preferences.
bool registered_users_only()
bool show_all_units_in_help()
void set_blindfold_replay(bool value)
static const ::config * terrain
The terrain used to create the cache.
void set_message_private(bool value)
bool is_ignored(const std::string &nick)
void set_chat_timestamping(bool value)
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
void set_level(const std::string &value)
Encapsulates the map of the game.
bool add_friend(const std::string &nick, const std::string ¬es)
bool add_ignore(const std::string &nick, const std::string &reason)
admin_authentication_reset()
Default constructor, defined out of line to work around a warning in gcc 4.5.2.
void set_child(const std::string &key, const config &val)
void set_allow_observers(bool value)
std::vector< std::string > * get_history(const std::string &id)
Returns a pointer to the history vector associated with given id making a new one if it doesn't exist...
int mp_server_warning_disabled()
std::string get_mp_server_program_name()
int h() const
Effective map height.
bool interrupt_when_ally_sighted()
void set_delete_saves(bool value)
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
void set_wrap_login(bool wrap)
void encounter_all_content(const game_board &gameboard_)
GLfloat GLfloat GLfloat GLfloat h
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
void set_skip_mp_replay(bool value)
std::set< std::string > & encountered_units()
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
const std::string & get_nick() const
const config & get_child(const std::string &key)
void set_turns(int value)
void set_autosavemax(int value)
virtual const gamemap & map() const
compression::format save_compression_format()
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
void set_show_all_units_in_help(bool value)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
bool show_floating_labels()
const std::vector< std::string > & modifications(bool mp)
bool have_setting(const std::string &key)
std::string notes_
notes on the acquaintance
std::string get_chat_timestamp(const time_t &t)
void set_modifications(const std::vector< std::string > &value, bool mp)
bool enable_whiteboard_mode_on_start()
Standard logging facilities (interface).
int countdown_action_bonus()
Container associating units to locations.
void set_show_ai_moves(bool value)
GLsizei GLenum GLuint GLuint GLsizei char * message
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
void set_era(const std::string &value)
void set_shuffle_sides(bool value)
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
void set_ask_delete_saves(bool value)
void encounter_recruitable_units(const std::vector< team > &teams)
A config object defines a single node in a WML file, with access to child nodes.
void set_countdown_reservoir_time(int value)
std::string custom_command()
void set_xp_modifier(int value)
int get_turns(const std::string &value)
Gets the number of turns.
GLsizei const GLcharARB ** string
bool use_twelve_hour_clock_format()
void set_village_gold(int value)
std::vector< server_info > server_list
void set_use_map_settings(bool value)
~admin_authentication_reset()
std::vector< t_terrain > t_list
std::string nick_
acquaintance's MP nick