20 #define GETTEXT_DOMAIN "wesnoth-lib"
46 #include <boost/algorithm/string.hpp>
54 #include <openssl/evp.h>
55 #include <openssl/err.h>
57 #include <CommonCrypto/CommonCryptor.h>
61 #define ERR_CFG LOG_STREAM(err , log_config)
62 #define DBG_CFG LOG_STREAM(debug , log_config)
65 #define ERR_FS LOG_STREAM(err, log_filesystem)
68 #define ERR_ADV LOG_STREAM(err, advanced_preferences)
70 using namespace std::chrono_literals;
75 , completed_campaigns_()
76 , encountered_units_set_()
77 , encountered_terrains_set_()
81 , options_initialized_(false)
83 , mp_modifications_initialized_(false)
85 , sp_modifications_initialized_(false)
86 , message_private_on_(false)
109 cmp[
"name"] = elem.first;
110 cmp[
"difficulty_levels"] =
utils::join(elem.second);
114 set_child(prefs_list::completed_campaigns, campaigns);
130 for(
const std::string&
line : history_id.second) {
133 cfg[
"message"] =
line;
134 history_id_cfg.
add_child(
"line", std::move(cfg));
137 history.
add_child(history_id.first, history_id_cfg);
168 }
catch(
const std::invalid_argument&
e) {
177 if(op.field == prefs_list::show_deprecation) {
178 op.cfg[
"default"] =
true;
183 std::sort(
advanced_prefs_.begin(),
advanced_prefs_.end(), [](
const auto& lhs,
const auto& rhs) { return translation::icompare(lhs.name, rhs.name) < 0; });
196 read(current_cfg, *current_stream);
199 read(old_cfg, *old_stream);
204 if(current_prefs_are_older || !current_cfg.
has_attribute(key)) {
224 std::set<std::string> attrs;
228 attrs.emplace(attr.first);
245 #ifdef DEFAULT_PREFS_PATH
250 read(default_prefs, *stream);
255 read(unsynced_prefs, *stream);
260 read(synced_prefs, *stream);
290 ERR_CFG <<
"Error loading preference, message: " <<
e.what();
311 if(
auto ccc =
get_child(prefs_list::completed_campaigns)) {
314 std::vector<std::string> nd =
utils::split(cc[
"difficulty_levels"]);
315 std::copy(nd.begin(), nd.end(), std::inserter(
d,
d.begin()));
324 if(
auto history =
get_child(prefs_list::history)) {
332 for(
const auto [key, cfg] : history->all_children_view()) {
393 write(*synced_prefs_file, synced);
400 write(*unsynced_prefs_file, unsynced);
408 if(!synced_prefs_file_existed) {
413 if(!unsynced_prefs_file_existed) {
426 std::fill(cred.username.begin(), cred.username.end(),
'\0');
427 std::fill(cred.server.begin(), cred.server.end(),
'\0');
447 ERR_CFG <<
"Invalid data in credentials file";
451 std::size_t
at = elem.find_last_of(
'@');
452 std::size_t eq = elem.find_first_of(
'=',
at + 1);
453 if(
at != std::string::npos && eq != std::string::npos) {
474 credentials_data.insert(credentials_data.end(), cred.username.begin(), cred.username.end());
475 credentials_data.push_back(
'@');
476 credentials_data.insert(credentials_data.end(), cred.server.begin(), cred.server.end());
477 credentials_data.push_back(
'=');
479 credentials_data.insert(credentials_data.end(), key_escaped.begin(), key_escaped.end());
484 credentials_file->write(
reinterpret_cast<const char*
>(encrypted.data()), encrypted.size());
490 if(!creds_file_existed) {
511 std::string
prefs::get(
const std::string& key,
const std::string& def) {
524 if (color.substr(0,4) ==
"orb_") {
525 if(color[4] >=
'0' && color[4] <=
'9') {
526 return color.substr(5);
528 return color.substr(4);
536 if (ally_color.empty())
576 if (partmoved_color.empty())
585 if (reachmap_color.empty())
595 if (reachmap_enemy_color.empty())
625 const unsigned x_res =
preferences_[prefs_list::xresolution].to_unsigned();
626 const unsigned y_res =
preferences_[prefs_list::yresolution].to_unsigned();
629 if(x_res == 0 || y_res == 0) {
641 preferences_[prefs_list::xresolution] = std::to_string(res.x);
642 preferences_[prefs_list::yresolution] = std::to_string(res.y);
688 return preferences_[prefs_list::keepalive_timeout].to_int(20);
693 preferences_[prefs_list::keepalive_timeout] = std::abs(seconds);
701 const std::size_t buf_size = 4096;
703 const std::size_t buf_size = 1024;
706 return preferences_[prefs_list::sound_buffer_size].to_int(buf_size);
711 const std::string new_size = std::to_string(
size);
712 if (
preferences_[prefs_list::sound_buffer_size] == new_size)
813 return preferences_[prefs_list::ui_sound].to_bool(
true);
840 return preferences_[prefs_list::message_bell].to_bool(
true);
849 if(!
sound() && ison) {
857 }
else if(
sound() && !ison) {
894 return std::clamp<int>(
preferences_[prefs_list::scroll].to_int(50), 1, 100);
904 return preferences_[prefs_list::middle_click_scrolls].to_bool(
true);
909 return preferences_[prefs_list::scroll_threshold].to_int(10);
941 alias_list[alias] = command;
952 return preferences_[prefs_list::sample_rate].to_int(44100);
968 return preferences_[prefs_list::confirm_load_save_from_different_version].to_bool(
true);
973 return preferences_[prefs_list::use_twelve_hour_clock_format].to_bool();
990 if(ach[
"content_for"].str() == content_for)
992 std::vector<std::string> ids =
utils::split(ach[
"ids"]);
993 return std::find(ids.begin(), ids.end(),
id) != ids.end();
1004 if(ach[
"content_for"].str() == content_for)
1006 std::vector<std::string> ids =
utils::split(ach[
"ids"]);
1012 else if(
std::find(ids.begin(), ids.end(),
id) == ids.end())
1014 ach[
"ids"] = ach[
"ids"].str() +
"," +
id;
1016 ach.remove_children(
"in_progress", [&
id](
config cfg){
return cfg[
"id"].str() ==
id;});
1023 ach[
"content_for"] = content_for;
1038 if(ach[
"content_for"].str() == content_for)
1043 if(in_progress[
"id"].str() ==
id)
1046 int starting_progress = in_progress[
"progress_at"].to_int();
1047 if(starting_progress >= limit) {
1048 return starting_progress;
1051 in_progress[
"progress_at"] = std::clamp(starting_progress + amount, 0, std::min(limit, max_progress));
1052 return in_progress[
"progress_at"].to_int();
1060 set_progress[
"id"] =
id;
1061 set_progress[
"progress_at"] = std::clamp(amount, 0, std::min(limit, max_progress));
1064 return child[
"progress_at"].to_int();
1076 set_progress[
"id"] =
id;
1077 set_progress[
"progress_at"] = std::clamp(amount, 0, std::min(limit, max_progress));
1079 ach[
"content_for"] = content_for;
1084 return child[
"progress_at"].to_int();
1099 if(ach[
"content_for"].str() == content_for)
1102 for(
const auto& in_progress : ach.child_range(
"in_progress"))
1104 if(in_progress[
"id"] ==
id)
1106 std::vector<std::string> sub_ids =
utils::split(in_progress[
"sub_ids"]);
1107 return std::find(sub_ids.begin(), sub_ids.end(), sub_id) != sub_ids.end();
1126 if(ach[
"content_for"].str() == content_for)
1131 if(in_progress[
"id"].str() ==
id)
1133 std::vector<std::string> sub_ids =
utils::split(ach[
"ids"]);
1135 if(
std::find(sub_ids.begin(), sub_ids.end(), sub_id) == sub_ids.end())
1137 in_progress[
"sub_ids"] = in_progress[
"sub_ids"].str() +
"," + sub_id;
1140 in_progress[
"progress_at"] = sub_ids.size()+1;
1147 set_progress[
"id"] =
id;
1148 set_progress[
"sub_ids"] = sub_id;
1149 set_progress[
"progress_at"] = 1;
1150 ach.
add_child(
"in_progress", set_progress);
1159 set_progress[
"id"] =
id;
1160 set_progress[
"sub_ids"] = sub_id;
1161 set_progress[
"progress_at"] = 1;
1163 ach[
"content_for"] = content_for;
1166 ach.
add_child(
"in_progress", set_progress);
1172 return preferences_[prefs_list::show_deprecation].to_bool(def);
1177 return preferences_[prefs_list::scroll_when_mouse_outside].to_bool(def);
1182 set_child(prefs_list::dir_bookmarks, cfg);
1186 return get_child(prefs_list::dir_bookmarks);
1191 return preferences_[prefs_list::lobby_auto_open_whisper_windows].to_bool(
true);
1196 return std::max(std::size_t(1),
preferences_[prefs_list::editor_max_recent_files].to_size_t(10));
1207 auto cfg =
get_child(prefs_list::editor_recent_files);
1209 std::vector<std::string> mru;
1216 const std::string& entry = child[
"path"].str();
1217 if(!entry.empty()) {
1218 mru.push_back(entry);
1232 for(
const std::string& entry : mru)
1239 child[
"path"] = entry;
1246 set_child(prefs_list::editor_recent_files, cfg);
1266 mru.insert(mru.begin(),
path);
1274 return preferences_[prefs_list::color_cursors].to_bool(
true);
1286 return preferences_[prefs_list::unit_standing_animations].to_bool(
true);
1291 preferences_[prefs_list::unit_standing_animations] = value;
1294 d->reset_standing_animations();
1302 if (themes.empty()) {
1304 _(
"No known themes. Try changing from within an existing game."));
1311 for (std::size_t k = 0; k < themes.size(); ++k) {
1312 if(themes[k].
id ==
theme()) {
1341 const std::string
msg =
VGETTEXT(
"The <b>$filename</b> server application provides multiplayer server functionality and is required for hosting local network games. It will normally be found in the same folder as the game executable.", {{
"filename",
filename}});
1361 static const std::string null_theme =
"null";
1375 if(
theme !=
"null") {
1391 return preferences_[prefs_list::mp_server_program_name].str();
1401 std::vector<std::string> ignored;
1404 if(person.second.get_status() ==
"ignore") {
1405 ignored.push_back(person.second.get_nick());
1415 std::map<std::string, std::string> ac_nice;
1418 if(a.second.get_status() ==
filter) {
1419 ac_nice[a.second.get_nick()] = a.second.get_notes();
1426 std::pair<preferences::acquaintance*, bool>
prefs::add_acquaintance(
const std::string& nick,
const std::string& mode,
const std::string& notes)
1429 return std::pair(
nullptr,
false);
1433 auto [iter, added_new] =
acquaintances_.insert_or_assign(nick, new_entry);
1435 return std::pair(&iter->second, added_new);
1444 std::size_t pos = nick.find_first_of(
' ');
1446 if(pos != std::string::npos) {
1467 return it->second.get_status() ==
"friend";
1478 return it->second.get_status() ==
"ignore";
1501 if(sender !=
"server") {
1505 std::string::size_type pos = message.find(
" has logged into the lobby");
1506 if(pos == std::string::npos) {
1507 pos = message.find(
" has disconnected");
1508 if(pos == std::string::npos) {
1522 return is_friend(message.substr(0, pos));
1528 if(pref ==
"friends") {
1530 }
else if(pref ==
"all") {
1532 }
else if(pref ==
"none") {
1553 return pref_servers;
1558 std::vector<game_config::server_info> pref_servers;
1561 pref_servers.emplace_back();
1562 pref_servers.back().name = server[
"name"].str();
1563 pref_servers.back().address = server[
"address"].str();
1566 return pref_servers;
1573 for(
const auto& svinfo : value) {
1575 sv_cfg[
"name"] = svinfo.name;
1576 sv_cfg[
"address"] = svinfo.address;
1597 if(!
preferences_[prefs_list::campaign_server].empty()) {
1598 return preferences_[prefs_list::campaign_server].str();
1611 return preferences_[prefs_list::show_combat].to_bool(
true);
1647 preferences_[prefs_list::mp_countdown_init_time] = std::clamp(value, 0
s, 1500
s);
1662 preferences_[prefs_list::mp_countdown_reservoir_time] = std::clamp(value, 30
s, 1500
s);
1677 preferences_[prefs_list::mp_countdown_turn_bonus] = std::clamp(value, 0
s, 300
s);
1692 preferences_[prefs_list::mp_countdown_action_bonus] = std::clamp(value, 0
s, 30
s);
1727 preferences_[prefs_list::mp_village_support] = std::to_string(value);
1778 const std::string& choice =
preferences_[prefs_list::compress_saves];
1782 if(choice.empty() || choice ==
"gzip" || choice ==
"yes") {
1784 }
else if(choice ==
"bzip2") {
1786 }
else if(choice ==
"none" || choice ==
"no") {
1798 if(chat_timestamp()) {
1832 const std::string confirmation =
preferences_[prefs_list::confirm_end_turn];
1833 return confirmation ==
"green" || confirmation ==
"yes";
1838 return preferences_[prefs_list::confirm_end_turn] ==
"yellow";
1844 const std::string confirmation =
preferences_[prefs_list::confirm_end_turn];
1845 return confirmation ==
"no_moves" || confirmation.
empty();
1850 for(
const team& help_team : teams) {
1851 help_team.log_recruitable();
1858 for(
const auto& help_unit : units) {
1865 for(
const team&
t : teams) {
1928 wchar_t buffer[300];
1930 if(GetUserNameW(buffer, &
size)) {
1933 return unicode_cast<std::string>(std::wstring_view{buffer});
1936 if(
char*
const login = getenv(
"USER")) {
1947 unsigned char i = 0;
1948 std::generate(result.begin(), result.end(), [&
i]() {return
'x' ^ i++;});
1949 std::copy(
login.begin(),
login.end(), result.begin());
1950 std::copy(sysname.begin(), sysname.end(), result.begin() +
login.size());
1951 std::copy(server.begin(), server.end(), result.begin() +
login.size() + sysname.size());
1962 const unsigned char iv[] = {1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8};
1963 unsigned char encrypted_buffer[1024];
1965 if(plaintext.size() > 1008)
1967 ERR_CFG <<
"Cannot encrypt data larger than 1008 bytes.";
1970 DBG_CFG <<
"Encrypting data with length: " << plaintext.size();
1972 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
1975 ERR_CFG <<
"AES EVP_CIPHER_CTX_new failed with error:";
1976 ERR_CFG << ERR_error_string(ERR_get_error(),
nullptr);
1981 if(EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(),
nullptr, key.data(), iv) != 1)
1983 ERR_CFG <<
"AES EVP_EncryptInit_ex failed with error:";
1984 ERR_CFG << ERR_error_string(ERR_get_error(),
nullptr);
1985 EVP_CIPHER_CTX_free(ctx);
1989 if(EVP_EncryptUpdate(ctx, encrypted_buffer, &update_length, plaintext.data(), plaintext.size()) != 1)
1991 ERR_CFG <<
"AES EVP_EncryptUpdate failed with error:";
1992 ERR_CFG << ERR_error_string(ERR_get_error(),
nullptr);
1993 EVP_CIPHER_CTX_free(ctx);
1996 DBG_CFG <<
"Update length: " << update_length;
1998 if(EVP_EncryptFinal_ex(ctx, encrypted_buffer + update_length, &extra_length) != 1)
2000 ERR_CFG <<
"AES EVP_EncryptFinal failed with error:";
2001 ERR_CFG << ERR_error_string(ERR_get_error(),
nullptr);
2002 EVP_CIPHER_CTX_free(ctx);
2005 DBG_CFG <<
"Extra length: " << extra_length;
2007 EVP_CIPHER_CTX_free(ctx);
2009 total_length = update_length+extra_length;
2011 for(
int i = 0;
i < total_length;
i++)
2013 result.push_back(encrypted_buffer[
i]);
2016 DBG_CFG <<
"Successfully encrypted plaintext value of '" <<
utils::join(plaintext,
"") <<
"' having length " << plaintext.size();
2017 DBG_CFG <<
"For a total encrypted length of: " << total_length;
2021 size_t outWritten = 0;
2024 CCCryptorStatus ccStatus = CCCrypt(kCCDecrypt,
2026 kCCOptionPKCS7Padding,
2036 assert(ccStatus == kCCSuccess);
2037 assert(outWritten == plaintext.size());
2050 const unsigned char iv[] = {1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8};
2051 unsigned char plaintext_buffer[1024];
2053 if(encrypted.size() > 1024)
2055 ERR_CFG <<
"Cannot decrypt data larger than 1024 bytes.";
2058 DBG_CFG <<
"Decrypting data with length: " << encrypted.size();
2060 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
2063 ERR_CFG <<
"AES EVP_CIPHER_CTX_new failed with error:";
2064 ERR_CFG << ERR_error_string(ERR_get_error(),
nullptr);
2069 if(EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(),
nullptr, key.data(), iv) != 1)
2071 ERR_CFG <<
"AES EVP_DecryptInit_ex failed with error:";
2072 ERR_CFG << ERR_error_string(ERR_get_error(),
nullptr);
2073 EVP_CIPHER_CTX_free(ctx);
2077 if(EVP_DecryptUpdate(ctx, plaintext_buffer, &update_length, encrypted.data(), encrypted.size()) != 1)
2079 ERR_CFG <<
"AES EVP_DecryptUpdate failed with error:";
2080 ERR_CFG << ERR_error_string(ERR_get_error(),
nullptr);
2081 EVP_CIPHER_CTX_free(ctx);
2084 DBG_CFG <<
"Update length: " << update_length;
2086 if(EVP_DecryptFinal_ex(ctx, plaintext_buffer + update_length, &extra_length) != 1)
2088 ERR_CFG <<
"AES EVP_DecryptFinal failed with error:";
2089 ERR_CFG << ERR_error_string(ERR_get_error(),
nullptr);
2090 EVP_CIPHER_CTX_free(ctx);
2093 DBG_CFG <<
"Extra length: " << extra_length;
2095 EVP_CIPHER_CTX_free(ctx);
2097 total_length = update_length+extra_length;
2099 for(
int i = 0;
i < total_length;
i++)
2101 result.push_back(plaintext_buffer[
i]);
2105 DBG_CFG <<
"For a total decrypted length of: " << total_length;
2109 size_t outWritten = 0;
2112 CCCryptorStatus ccStatus = CCCrypt(kCCDecrypt,
2114 kCCOptionPKCS7Padding,
2124 assert(ccStatus == kCCSuccess);
2125 assert(outWritten == encrypted.size());
2128 while(!result.empty() && result.back() == 0) {
2139 unescaped.reserve(text.size());
2140 bool escaping =
false;
2141 for(
char c : text) {
2144 unescaped.push_back(
'\xc');
2145 }
else if(
c ==
'.') {
2146 unescaped.push_back(
'@');
2148 unescaped.push_back(
c);
2151 }
else if(
c ==
'\x1') {
2154 unescaped.push_back(
c);
2164 escaped.reserve(text.size());
2165 for(
char c : text) {
2167 escaped.push_back(
'\x1');
2168 escaped.push_back(
'\x1');
2169 }
else if(
c ==
'\xc') {
2170 escaped.push_back(
'\x1');
2171 escaped.push_back(
'\xa');
2172 }
else if(
c ==
'@') {
2173 escaped.push_back(
'\x1');
2174 escaped.push_back(
'.');
2176 escaped.push_back(
c);
2184 return preferences_[prefs_list::remember_password].to_bool();
2189 preferences_[prefs_list::remember_password] = remember;
2203 }
else if(name.size() > 2 && name.front() ==
'@' && name.back() ==
'@') {
2204 name = name.substr(1, name.size() - 2);
2206 ERR_CFG <<
"malformed user credentials (did you manually edit the preferences file?)";
2216 auto login_clean =
login;
2219 preferences_[prefs_list::login] =
'@' + login_clean +
'@';
2224 DBG_CFG <<
"Retrieving password for server: '" << server <<
"', login: '" <<
login <<
"'";
2225 auto login_clean =
login;
2231 return std::string(temp.begin(), temp.end());
2237 return cred.server == server && cred.username == login_clean;
2243 return std::string(temp.begin(), temp.end());
2248 DBG_CFG <<
"Setting password for server: '" << server <<
"', login: '" <<
login <<
"'";
2249 auto login_clean =
login;
2259 return cred.server == server && cred.username == login_clean;
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
const_attr_itors attribute_range() const
auto all_children_view() const
In-order iteration over all children.
void clear_children(T... keys)
bool has_attribute(config_key_type key) const
void merge_with(const config &c)
Merge config 'c' into this config, overwriting this config's values.
child_itors child_range(config_key_type key)
config & child_or_add(config_key_type key)
Returns a reference to the first child with the given key.
void remove_attribute(config_key_type key)
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
config & add_child(config_key_type key)
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
void set_theme(const std::string &new_theme)
static display * get_singleton()
Returns the display object if a display object exists.
virtual const std::vector< team > & teams() const override
virtual const unit_map & units() const override
virtual const gamemap & map() const override
A class grating read only view to a vector of config objects, viewed as one config with all children ...
static game_config_view wrap(const config &cfg)
config_array_view child_range(config_key_type key) const
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
void for_each_loc(const F &f) const
Encapsulates the map of the game.
const t_translation::ter_list & underlying_union_terrain(const map_location &loc) const
file_dialog & set_ok_label(const std::string &value)
Sets the OK button label.
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
file_dialog & set_read_only(bool value)
Whether to provide user interface elements for manipulating existing objects.
file_dialog & set_filename(const std::string &value)
Sets the initial file name input but not the path.
file_dialog & set_message(const std::string &value)
Sets the current dialog instructions/message text.
bool show(const unsigned auto_close_time=0)
Shows the window.
int selected_index() const
Returns the selected item index after displaying.
void set_selected_index(int index)
Sets the initially selected item index (-1 by default).
const std::string & get_nick() const
void set_lobby_joins(pref_constants::lobby_joins show)
std::string enemy_color()
config::attribute_value get_as_attribute(const std::string &key)
void set_reach_map_enemy_color(const std::string &color_id)
void set_network_host(const std::string &host)
std::set< t_translation::terrain_code > & encountered_terrains()
bool set_music(bool ison)
void set_sound_volume(int vol)
void set_remember_password(bool remember)
const std::map< std::string, preferences::acquaintance > & get_acquaintances()
optional_const_config get_alias()
void set_turbo(bool ison)
std::string get_system_username()
bool mp_modifications_initialized_
std::map< std::string, std::vector< std::string > > history_map_
void set_addon_manager_saved_order_direction(sort_order::type value)
std::chrono::seconds countdown_turn_bonus()
bool middle_click_scrolls()
void set_countdown_reservoir_time(const std::chrono::seconds &value)
std::set< std::string > & encountered_units()
void add_alias(const std::string &alias, const std::string &command)
std::vector< std::string > sp_modifications_
void clear_mp_alert_prefs()
The most recently selected add-on id from the editor.
void set_village_gold(int value)
bool confirm_load_save_from_different_version()
std::string network_host()
void clear_countdown_init_time()
std::set< std::string > unknown_unsynced_attributes_
bool set_ui_sound(bool ison)
void set_reach_map_border_opacity(const int new_opacity)
std::chrono::minutes chat_message_aging()
void set_login(const std::string &login)
const std::string get_ignored_delim()
std::map< std::string, preferences::acquaintance > acquaintances_
static constexpr std::array unsynced_children_
void encounter_recallable_units(const std::vector< team > &teams)
std::map< std::string, std::set< std::string > > completed_campaigns_
optional_const_config dir_bookmarks()
void set_theme(const std::string &theme)
void set_xp_modifier(int value)
void set_user_servers_list(const std::vector< game_config::server_info > &value)
preferences::secure_buffer build_key(const std::string &server, const std::string &login)
Fills a secure_buffer with 32 bytes of deterministically generated bytes, then overwrites it with the...
bool is_campaign_completed(const std::string &campaign_id)
void set_allied_color(const std::string &color_id)
bool get_scroll_when_mouse_outside(bool def)
void show_wesnothd_server_search()
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
std::string get_chat_timestamp(const std::chrono::system_clock::time_point &t)
bool is_ignored(const std::string &nick)
std::vector< std::string > mp_modifications_
bool achievement(const std::string &content_for, const std::string &id)
std::set< std::string > unknown_synced_attributes_
void set_enemy_color(const std::string &color_id)
std::chrono::seconds countdown_init_time()
void set_password(const std::string &server, const std::string &login, const std::string &key)
bool sub_achievement(const std::string &content_for, const std::string &id, const std::string &sub_id)
std::vector< preferences::login_info > credentials_
std::vector< std::string > do_read_editor_mru()
void encounter_recruitable_units(const std::vector< team > &teams)
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
int progress_achievement(const std::string &content_for, const std::string &id, int limit=999999, int max_progress=999999, int amount=0)
Increments the achievement's current progress by amount if it hasn't already been completed.
sort_order::type addon_manager_saved_order_direction()
bool set_turn_bell(bool ison)
static constexpr std::array synced_attributes_
unsigned int sample_rate()
void set_reach_map_tint_opacity(const int new_opacity)
void set_countdown_turn_bonus(const std::chrono::seconds &value)
static constexpr std::array synced_children_
void set_options(const config &values)
int reach_map_tint_opacity()
void set_message_private(bool value)
std::vector< game_config::server_info > user_servers_list()
optional_const_config get_child(const std::string &key)
std::string unmoved_color()
void set_music_volume(int vol)
void load_advanced_prefs(const game_config_view &gc)
std::string allied_color()
void set_show_standing_animations(bool value)
void set_show_fps(bool value)
void set_pixel_scale(const int scale)
std::size_t editor_mru_limit()
void set_color_cursors(bool value)
std::vector< preferences::option > advanced_prefs_
void encounter_start_units(const unit_map &units)
pref_constants::lobby_joins get_lobby_joins()
void set_chat_message_aging(const std::chrono::minutes &value)
void encounter_map_terrain(const gamemap &map)
void set_village_support(int value)
preferences::secure_buffer escape(const preferences::secure_buffer &text)
std::chrono::seconds countdown_action_bonus()
std::string moved_color()
void set_font_scaling(int scale)
std::size_t sound_buffer_size()
void migrate_preferences(const std::string &prefs_dir)
void set_dir_bookmarks(const config &cfg)
std::set< t_translation::terrain_code > encountered_terrains_set_
bool set_sound(bool ison)
bool is_friend(const std::string &nick)
void set_achievement(const std::string &content_for, const std::string &id)
Marks the specified achievement as completed.
preferences::secure_buffer aes_decrypt(const preferences::secure_buffer &text, const preferences::secure_buffer &key)
Same as aes_encrypt(), except of course it takes encrypted data as an argument and returns decrypted ...
void clear_countdown_turn_bonus()
int font_scaled(int size)
void set_scroll_speed(const int scroll)
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string ¬es)
bool options_initialized_
std::string partial_color()
preferences::secure_buffer unescape(const preferences::secure_buffer &text)
void set_resolution(const point &res)
void set_campaign_server(const std::string &host)
void set_unmoved_color(const std::string &color_id)
bool remove_acquaintance(const std::string &nick)
void clear_countdown_reservoir_time()
void set_ui_volume(int vol)
const std::vector< std::string > & modifications(bool mp=true)
void do_commit_editor_mru(const std::vector< std::string > &mru)
std::chrono::seconds countdown_reservoir_time()
std::string reach_map_color()
compression::format save_compression_format()
std::vector< std::string > recent_files()
Retrieves the list of recently opened files.
std::set< std::string > encountered_units_set_
void set_bell_volume(int vol)
std::string get_mp_server_program_name()
std::string reach_map_enemy_color()
void set_partial_color(const std::string &color_id)
void set_child(const std::string &key, const config &val)
static constexpr std::array unsynced_attributes_
std::set< std::string > all_attributes()
void set_mp_server_program_name(const std::string &)
void add_recent_files_entry(const std::string &path)
Adds an entry to the recent files list.
void set_moved_color(const std::string &color_id)
void save_sample_rate(const unsigned int rate)
bool use_twelve_hour_clock_format()
static bool no_preferences_save
int reach_map_border_opacity()
void set_modifications(const std::vector< std::string > &value, bool mp=true)
void set_countdown_init_time(const std::chrono::seconds &value)
void set_sub_achievement(const std::string &content_for, const std::string &id, const std::string &sub_id)
Marks the specified sub-achievement as completed.
std::set< std::string > unknown_unsynced_children_
const std::vector< game_config::server_info > & builtin_servers_list()
void set_reach_map_color(const std::string &color_id)
void reload_preferences()
std::string campaign_server()
std::set< std::string > unknown_synced_children_
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
void save_sound_buffer_size(const std::size_t size)
void encounter_all_content(const game_board &gb)
std::string password(const std::string &server, const std::string &login)
bool sp_modifications_initialized_
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...
preferences::secure_buffer aes_encrypt(const preferences::secure_buffer &text, const preferences::secure_buffer &key)
Encrypts the value of text using key and a hard coded IV using AES.
void set_countdown_action_bonus(const std::chrono::seconds &value)
bool auto_open_whisper_windows()
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
bool get_show_deprecation(bool def)
bool show_standing_animations()
void clear_countdown_action_bonus()
This class stores all the data for a single 'side' (in game nomenclature).
static std::vector< theme_info > get_basic_theme_info(bool include_hidden=false)
Returns minimal info about saved themes, optionally including hidden ones.
Container associating units to locations.
static std::string _(const char *str)
std::string id
Text to match against addon_info.tags()
Standard logging facilities (interface).
General settings and defaults for scenarios.
auto parse_duration(const config_attribute_value &val, const Duration &def=Duration{0})
auto format_local_timestamp(const std::chrono::system_clock::time_point &time, std::string_view format="%F %T")
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
void point(int x, int y)
Draw a single point.
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
std::time_t file_modified_time(const std::string &fname)
Get the modification time of a file.
filesystem::scoped_istream istream_file(const std::string &fname, bool treat_failure_as_error)
void copy_file(const std::string &src, const std::string &dest)
Read a file and then writes it back out.
bool delete_file(const std::string &filename)
static bool file_exists(const bfs::path &fpath)
std::string get_exe_dir()
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
std::string get_synced_prefs_file()
location of preferences file containing preferences that are synced between computers note that wesno...
std::string get_unsynced_prefs_file()
location of preferences file containing preferences that aren't synced between computers
filesystem::scoped_ostream ostream_file(const std::string &fname, std::ios_base::openmode mode, bool create_directory)
std::unique_ptr< std::istream > scoped_istream
std::string get_credentials_file()
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
std::unique_ptr< std::ostream > scoped_ostream
std::string get_wesnothd_name()
std::string get_default_prefs_file()
std::string partial_orb_color
std::string reach_map_enemy_color
std::string moved_orb_color
std::string unmoved_orb_color
std::string ally_orb_color
std::string enemy_orb_color
std::string reach_map_color
const version_info wesnoth_version(VERSION)
int reach_map_border_opacity
std::vector< server_info > server_list
int reach_map_tint_opacity
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
static int music_volume()
static int sound_volume()
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
void save_hotkeys(config &cfg)
Save the non-default hotkeys to the config.
void reset_default_hotkeys()
Reset all hotkeys to the defaults.
void load_custom_hotkeys(const game_config_view &cfg)
Registers all hotkeys present in this config, overwriting any matching default hotkeys.
Main entry points of multiplayer mode.
const int min_window_height
const int max_pixel_scale
const std::string EMPTY_LOGIN
const int min_pixel_scale
const std::string default_addons_server
const int def_window_width
const int min_font_scaling
const int min_window_width
const int max_font_scaling
const int def_window_height
const unsigned char CREDENTIAL_SEPARATOR
static std::string at(const std::string &file, int line)
int get_village_support(const std::string &value)
Gets the village unit level support.
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
void set_bell_volume(int vol)
void set_music_volume(int vol)
void set_UI_volume(int vol)
void set_sound_volume(int vol)
std::vector< terrain_code > ter_list
ter_list read_list(std::string_view str, const ter_layer filler)
Reads a list of terrains from a string, when reading the.
std::string write_list(const ter_list &list)
Writes a list of terrains to a string, only writes the new format.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
void trim(std::string_view &s)
bool isvalid_wildcard(const std::string &username)
Check if the username pattern contains only valid characters.
std::size_t erase(Container &container, const Value &value)
Convenience wrapper for using std::remove on a container.
std::set< std::string > split_set(std::string_view s, char sep, const int flags)
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< std::string > split(const config_attribute_value &val)
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
bool headless()
The game is running headless.
std::string::const_iterator iterator
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, ColorFormat colFmt, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
static lg::log_domain log_filesystem("filesystem")
static lg::log_domain advanced_preferences("advanced_preferences")
static std::string fix_orb_color_name(const std::string &color)
static lg::log_domain log_config("config")
std::shared_ptr< const unit > unit_const_ptr
void read(config &cfg, std::istream &in, abstract_validator *validator)
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
std::string filename
Filename.
An exception object used when an IO error occurs.
Encapsulates the map of the game.
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
static map_location::direction n
static map_location::direction s