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);
166 }
catch(
const std::invalid_argument&
e) {
175 if(op.field == prefs_list::show_deprecation) {
176 op.cfg[
"default"] =
true;
181 std::sort(
advanced_prefs_.begin(),
advanced_prefs_.end(), [](
const auto& lhs,
const auto& rhs) { return translation::icompare(lhs.name, rhs.name) < 0; });
194 read(current_cfg, *current_stream);
197 read(old_cfg, *old_stream);
202 if(current_prefs_are_older || !current_cfg.
has_attribute(key)) {
222 std::set<std::string> attrs;
226 attrs.emplace(attr.first);
229 for(
const auto attr : prefs_list::values) {
243 #ifdef DEFAULT_PREFS_PATH
248 read(default_prefs, *stream);
253 read(unsynced_prefs, *stream);
258 read(synced_prefs, *stream);
288 ERR_CFG <<
"Error loading preference, message: " <<
e.what();
309 if(
auto ccc =
get_child(prefs_list::completed_campaigns)) {
312 std::vector<std::string> nd =
utils::split(cc[
"difficulty_levels"]);
313 std::copy(nd.begin(), nd.end(), std::inserter(
d,
d.begin()));
322 if(
auto history =
get_child(prefs_list::history)) {
330 for(
const auto [key, cfg] : history->all_children_view()) {
391 write(*synced_prefs_file, synced);
398 write(*unsynced_prefs_file, unsynced);
406 if(!synced_prefs_file_existed) {
411 if(!unsynced_prefs_file_existed) {
424 std::fill(cred.username.begin(), cred.username.end(),
'\0');
425 std::fill(cred.server.begin(), cred.server.end(),
'\0');
445 ERR_CFG <<
"Invalid data in credentials file";
449 std::size_t
at = elem.find_last_of(
'@');
450 std::size_t eq = elem.find_first_of(
'=',
at + 1);
451 if(
at != std::string::npos && eq != std::string::npos) {
472 credentials_data.insert(credentials_data.end(), cred.username.begin(), cred.username.end());
473 credentials_data.push_back(
'@');
474 credentials_data.insert(credentials_data.end(), cred.server.begin(), cred.server.end());
475 credentials_data.push_back(
'=');
477 credentials_data.insert(credentials_data.end(), key_escaped.begin(), key_escaped.end());
482 credentials_file->write(
reinterpret_cast<const char*
>(encrypted.data()), encrypted.size());
488 if(!creds_file_existed) {
509 std::string
prefs::get(
const std::string& key,
const std::string& def) {
522 if (color.substr(0,4) ==
"orb_") {
523 if(color[4] >=
'0' && color[4] <=
'9') {
524 return color.substr(5);
526 return color.substr(4);
534 if (ally_color.empty())
574 if (partmoved_color.empty())
584 const unsigned x_res =
preferences_[prefs_list::xresolution].to_unsigned();
585 const unsigned y_res =
preferences_[prefs_list::yresolution].to_unsigned();
588 if(x_res == 0 || y_res == 0) {
600 preferences_[prefs_list::xresolution] = std::to_string(res.x);
601 preferences_[prefs_list::yresolution] = std::to_string(res.y);
647 return preferences_[prefs_list::keepalive_timeout].to_int(20);
652 preferences_[prefs_list::keepalive_timeout] = std::abs(seconds);
660 const std::size_t buf_size = 4096;
662 const std::size_t buf_size = 1024;
665 return preferences_[prefs_list::sound_buffer_size].to_int(buf_size);
670 const std::string new_size = std::to_string(
size);
671 if (
preferences_[prefs_list::sound_buffer_size] == new_size)
772 return preferences_[prefs_list::ui_sound].to_bool(
true);
799 return preferences_[prefs_list::message_bell].to_bool(
true);
808 if(!
sound() && ison) {
816 }
else if(
sound() && !ison) {
853 return std::clamp<int>(
preferences_[prefs_list::scroll].to_int(50), 1, 100);
863 return preferences_[prefs_list::middle_click_scrolls].to_bool(
true);
868 return preferences_[prefs_list::scroll_threshold].to_int(10);
900 alias_list[alias] = command;
911 return preferences_[prefs_list::sample_rate].to_int(44100);
927 return preferences_[prefs_list::confirm_load_save_from_different_version].to_bool(
true);
932 return preferences_[prefs_list::use_twelve_hour_clock_format].to_bool();
949 if(ach[
"content_for"].str() == content_for)
951 std::vector<std::string> ids =
utils::split(ach[
"ids"]);
952 return std::find(ids.begin(), ids.end(),
id) != ids.end();
963 if(ach[
"content_for"].str() == content_for)
965 std::vector<std::string> ids =
utils::split(ach[
"ids"]);
971 else if(std::find(ids.begin(), ids.end(),
id) == ids.end())
973 ach[
"ids"] = ach[
"ids"].str() +
"," +
id;
975 ach.remove_children(
"in_progress", [&
id](
config cfg){
return cfg[
"id"].str() ==
id;});
982 ach[
"content_for"] = content_for;
997 if(ach[
"content_for"].str() == content_for)
1002 if(in_progress[
"id"].str() ==
id)
1005 int starting_progress = in_progress[
"progress_at"].to_int();
1006 if(starting_progress >= limit) {
1007 return starting_progress;
1010 in_progress[
"progress_at"] = std::clamp(starting_progress + amount, 0, std::min(limit, max_progress));
1011 return in_progress[
"progress_at"].to_int();
1019 set_progress[
"id"] =
id;
1020 set_progress[
"progress_at"] = std::clamp(amount, 0, std::min(limit, max_progress));
1023 return child[
"progress_at"].to_int();
1035 set_progress[
"id"] =
id;
1036 set_progress[
"progress_at"] = std::clamp(amount, 0, std::min(limit, max_progress));
1038 ach[
"content_for"] = content_for;
1043 return child[
"progress_at"].to_int();
1058 if(ach[
"content_for"].str() == content_for)
1061 for(
const auto& in_progress : ach.child_range(
"in_progress"))
1063 if(in_progress[
"id"] ==
id)
1065 std::vector<std::string> sub_ids =
utils::split(in_progress[
"sub_ids"]);
1066 return std::find(sub_ids.begin(), sub_ids.end(), sub_id) != sub_ids.end();
1085 if(ach[
"content_for"].str() == content_for)
1090 if(in_progress[
"id"].str() ==
id)
1092 std::vector<std::string> sub_ids =
utils::split(ach[
"ids"]);
1094 if(std::find(sub_ids.begin(), sub_ids.end(), sub_id) == sub_ids.end())
1096 in_progress[
"sub_ids"] = in_progress[
"sub_ids"].str() +
"," + sub_id;
1099 in_progress[
"progress_at"] = sub_ids.size()+1;
1106 set_progress[
"id"] =
id;
1107 set_progress[
"sub_ids"] = sub_id;
1108 set_progress[
"progress_at"] = 1;
1109 ach.
add_child(
"in_progress", set_progress);
1118 set_progress[
"id"] =
id;
1119 set_progress[
"sub_ids"] = sub_id;
1120 set_progress[
"progress_at"] = 1;
1122 ach[
"content_for"] = content_for;
1125 ach.
add_child(
"in_progress", set_progress);
1131 return preferences_[prefs_list::show_deprecation].to_bool(def);
1136 return preferences_[prefs_list::scroll_when_mouse_outside].to_bool(def);
1141 set_child(prefs_list::dir_bookmarks, cfg);
1145 return get_child(prefs_list::dir_bookmarks);
1150 return preferences_[prefs_list::lobby_auto_open_whisper_windows].to_bool(
true);
1155 return std::max(std::size_t(1),
preferences_[prefs_list::editor_max_recent_files].to_size_t(10));
1166 auto cfg =
get_child(prefs_list::editor_recent_files);
1168 std::vector<std::string> mru;
1175 const std::string& entry = child[
"path"].str();
1176 if(!entry.empty()) {
1177 mru.push_back(entry);
1191 for(
const std::string& entry : mru)
1198 child[
"path"] = entry;
1205 set_child(prefs_list::editor_recent_files, cfg);
1225 mru.insert(mru.begin(),
path);
1233 return preferences_[prefs_list::color_cursors].to_bool(
true);
1245 return preferences_[prefs_list::unit_standing_animations].to_bool(
true);
1250 preferences_[prefs_list::unit_standing_animations] = value;
1253 d->reset_standing_animations();
1261 if (themes.empty()) {
1263 _(
"No known themes. Try changing from within an existing game."));
1270 for (std::size_t k = 0; k < themes.size(); ++k) {
1271 if(themes[k].
id ==
theme()) {
1300 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}});
1320 static const std::string null_theme =
"null";
1334 if(
theme !=
"null") {
1350 return preferences_[prefs_list::mp_server_program_name].str();
1360 std::vector<std::string> ignored;
1363 if(person.second.get_status() ==
"ignore") {
1364 ignored.push_back(person.second.get_nick());
1374 std::map<std::string, std::string> ac_nice;
1377 if(a.second.get_status() == filter) {
1378 ac_nice[a.second.get_nick()] = a.second.get_notes();
1385 std::pair<preferences::acquaintance*, bool>
prefs::add_acquaintance(
const std::string& nick,
const std::string& mode,
const std::string& notes)
1388 return std::pair(
nullptr,
false);
1392 auto [iter, added_new] =
acquaintances_.insert_or_assign(nick, new_entry);
1394 return std::pair(&iter->second, added_new);
1403 std::size_t pos = nick.find_first_of(
' ');
1405 if(pos != std::string::npos) {
1426 return it->second.get_status() ==
"friend";
1437 return it->second.get_status() ==
"ignore";
1460 if(sender !=
"server") {
1464 std::string::size_type pos = message.find(
" has logged into the lobby");
1465 if(pos == std::string::npos) {
1466 pos = message.find(
" has disconnected");
1467 if(pos == std::string::npos) {
1481 return is_friend(message.substr(0, pos));
1487 if(pref ==
"friends") {
1489 }
else if(pref ==
"all") {
1491 }
else if(pref ==
"none") {
1512 return pref_servers;
1517 std::vector<game_config::server_info> pref_servers;
1520 pref_servers.emplace_back();
1521 pref_servers.back().name = server[
"name"].str();
1522 pref_servers.back().address = server[
"address"].str();
1525 return pref_servers;
1532 for(
const auto& svinfo : value) {
1534 sv_cfg[
"name"] = svinfo.name;
1535 sv_cfg[
"address"] = svinfo.address;
1541 const std::string res =
preferences_[prefs_list::host];
1556 if(!
preferences_[prefs_list::campaign_server].empty()) {
1557 return preferences_[prefs_list::campaign_server].str();
1570 return preferences_[prefs_list::show_combat].to_bool(
true);
1606 preferences_[prefs_list::mp_countdown_init_time] = std::clamp(value, 0
s, 1500
s);
1621 preferences_[prefs_list::mp_countdown_reservoir_time] = std::clamp(value, 30
s, 1500
s);
1636 preferences_[prefs_list::mp_countdown_turn_bonus] = std::clamp(value, 0
s, 300
s);
1651 preferences_[prefs_list::mp_countdown_action_bonus] = std::clamp(value, 0
s, 30
s);
1686 preferences_[prefs_list::mp_village_support] = std::to_string(value);
1737 const std::string& choice =
preferences_[prefs_list::compress_saves];
1741 if(choice.empty() || choice ==
"gzip" || choice ==
"yes") {
1743 }
else if(choice ==
"bzip2") {
1745 }
else if(choice ==
"none" || choice ==
"no") {
1757 if(chat_timestamp()) {
1758 auto temp = std::chrono::system_clock::from_time_t(
t);
1792 const std::string confirmation =
preferences_[prefs_list::confirm_end_turn];
1793 return confirmation ==
"green" || confirmation ==
"yes";
1798 return preferences_[prefs_list::confirm_end_turn] ==
"yellow";
1804 const std::string confirmation =
preferences_[prefs_list::confirm_end_turn];
1805 return confirmation ==
"no_moves" || confirmation.
empty();
1810 for(
const team& help_team : teams) {
1811 help_team.log_recruitable();
1818 for(
const auto& help_unit : units) {
1825 for(
const team&
t : teams) {
1888 wchar_t buffer[300];
1890 if(GetUserNameW(buffer, &
size)) {
1893 return unicode_cast<std::string>(std::wstring_view{buffer});
1896 if(
char*
const login = getenv(
"USER")) {
1907 unsigned char i = 0;
1908 std::generate(result.begin(), result.end(), [&
i]() {return
'x' ^ i++;});
1909 std::copy(
login.begin(),
login.end(), result.begin());
1910 std::copy(sysname.begin(), sysname.end(), result.begin() +
login.size());
1911 std::copy(server.begin(), server.end(), result.begin() +
login.size() + sysname.size());
1922 const unsigned char iv[] = {1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8};
1923 unsigned char encrypted_buffer[1024];
1925 if(plaintext.size() > 1008)
1927 ERR_CFG <<
"Cannot encrypt data larger than 1008 bytes.";
1930 DBG_CFG <<
"Encrypting data with length: " << plaintext.size();
1932 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
1935 ERR_CFG <<
"AES EVP_CIPHER_CTX_new failed with error:";
1936 ERR_CFG << ERR_error_string(ERR_get_error(), NULL);
1941 if(EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key.data(), iv) != 1)
1943 ERR_CFG <<
"AES EVP_EncryptInit_ex failed with error:";
1944 ERR_CFG << ERR_error_string(ERR_get_error(), NULL);
1945 EVP_CIPHER_CTX_free(ctx);
1949 if(EVP_EncryptUpdate(ctx, encrypted_buffer, &update_length, plaintext.data(), plaintext.size()) != 1)
1951 ERR_CFG <<
"AES EVP_EncryptUpdate failed with error:";
1952 ERR_CFG << ERR_error_string(ERR_get_error(), NULL);
1953 EVP_CIPHER_CTX_free(ctx);
1956 DBG_CFG <<
"Update length: " << update_length;
1958 if(EVP_EncryptFinal_ex(ctx, encrypted_buffer + update_length, &extra_length) != 1)
1960 ERR_CFG <<
"AES EVP_EncryptFinal failed with error:";
1961 ERR_CFG << ERR_error_string(ERR_get_error(), NULL);
1962 EVP_CIPHER_CTX_free(ctx);
1965 DBG_CFG <<
"Extra length: " << extra_length;
1967 EVP_CIPHER_CTX_free(ctx);
1969 total_length = update_length+extra_length;
1971 for(
int i = 0;
i < total_length;
i++)
1973 result.push_back(encrypted_buffer[
i]);
1976 DBG_CFG <<
"Successfully encrypted plaintext value of '" <<
utils::join(plaintext,
"") <<
"' having length " << plaintext.size();
1977 DBG_CFG <<
"For a total encrypted length of: " << total_length;
1981 size_t outWritten = 0;
1984 CCCryptorStatus ccStatus = CCCrypt(kCCDecrypt,
1986 kCCOptionPKCS7Padding,
1996 assert(ccStatus == kCCSuccess);
1997 assert(outWritten == plaintext.size());
2010 const unsigned char iv[] = {1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8};
2011 unsigned char plaintext_buffer[1024];
2013 if(encrypted.size() > 1024)
2015 ERR_CFG <<
"Cannot decrypt data larger than 1024 bytes.";
2018 DBG_CFG <<
"Decrypting data with length: " << encrypted.size();
2020 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
2023 ERR_CFG <<
"AES EVP_CIPHER_CTX_new failed with error:";
2024 ERR_CFG << ERR_error_string(ERR_get_error(), NULL);
2029 if(EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key.data(), iv) != 1)
2031 ERR_CFG <<
"AES EVP_DecryptInit_ex failed with error:";
2032 ERR_CFG << ERR_error_string(ERR_get_error(), NULL);
2033 EVP_CIPHER_CTX_free(ctx);
2037 if(EVP_DecryptUpdate(ctx, plaintext_buffer, &update_length, encrypted.data(), encrypted.size()) != 1)
2039 ERR_CFG <<
"AES EVP_DecryptUpdate failed with error:";
2040 ERR_CFG << ERR_error_string(ERR_get_error(), NULL);
2041 EVP_CIPHER_CTX_free(ctx);
2044 DBG_CFG <<
"Update length: " << update_length;
2046 if(EVP_DecryptFinal_ex(ctx, plaintext_buffer + update_length, &extra_length) != 1)
2048 ERR_CFG <<
"AES EVP_DecryptFinal failed with error:";
2049 ERR_CFG << ERR_error_string(ERR_get_error(), NULL);
2050 EVP_CIPHER_CTX_free(ctx);
2053 DBG_CFG <<
"Extra length: " << extra_length;
2055 EVP_CIPHER_CTX_free(ctx);
2057 total_length = update_length+extra_length;
2059 for(
int i = 0;
i < total_length;
i++)
2061 result.push_back(plaintext_buffer[
i]);
2065 DBG_CFG <<
"For a total decrypted length of: " << total_length;
2069 size_t outWritten = 0;
2072 CCCryptorStatus ccStatus = CCCrypt(kCCDecrypt,
2074 kCCOptionPKCS7Padding,
2084 assert(ccStatus == kCCSuccess);
2085 assert(outWritten == encrypted.size());
2088 while(!result.empty() && result.back() == 0) {
2099 unescaped.reserve(text.size());
2100 bool escaping =
false;
2101 for(
char c : text) {
2104 unescaped.push_back(
'\xc');
2105 }
else if(
c ==
'.') {
2106 unescaped.push_back(
'@');
2108 unescaped.push_back(
c);
2111 }
else if(
c ==
'\x1') {
2114 unescaped.push_back(
c);
2124 escaped.reserve(text.size());
2125 for(
char c : text) {
2127 escaped.push_back(
'\x1');
2128 escaped.push_back(
'\x1');
2129 }
else if(
c ==
'\xc') {
2130 escaped.push_back(
'\x1');
2131 escaped.push_back(
'\xa');
2132 }
else if(
c ==
'@') {
2133 escaped.push_back(
'\x1');
2134 escaped.push_back(
'.');
2136 escaped.push_back(
c);
2144 return preferences_[prefs_list::remember_password].to_bool();
2149 preferences_[prefs_list::remember_password] = remember;
2163 }
else if(name.size() > 2 && name.front() ==
'@' && name.back() ==
'@') {
2164 name = name.substr(1, name.size() - 2);
2166 ERR_CFG <<
"malformed user credentials (did you manually edit the preferences file?)";
2176 auto login_clean =
login;
2179 preferences_[prefs_list::login] =
'@' + login_clean +
'@';
2184 DBG_CFG <<
"Retrieving password for server: '" << server <<
"', login: '" <<
login <<
"'";
2185 auto login_clean =
login;
2191 return std::string(temp.begin(), temp.end());
2197 return cred.server == server && cred.username == login_clean;
2203 return std::string(temp.begin(), temp.end());
2208 DBG_CFG <<
"Setting password for server: '" << server <<
"', login: '" <<
login <<
"'";
2209 auto login_clean =
login;
2219 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_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)
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.
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_countdown_turn_bonus(const std::chrono::seconds &value)
static constexpr std::array synced_children_
void set_options(const config &values)
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()
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()
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)
std::string get_chat_timestamp(const std::time_t &t)
void save_sample_rate(const unsigned int rate)
bool use_twelve_hour_clock_format()
static bool no_preferences_save
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 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 moved_orb_color
std::string unmoved_orb_color
std::string ally_orb_color
std::string enemy_orb_color
const version_info wesnoth_version(VERSION)
std::vector< server_info > server_list
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(const std::string &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)
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