The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
preferences.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2024 - 2025
3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY.
11
12 See the COPYING file for more details.
13*/
14
15#pragma once
16
17#include "config.hpp"
19#include "filesystem.hpp"
20#include "game_config.hpp"
21#include "gui/sort_order.hpp"
24#include "team.hpp"
26#include "lua/wrapper_lua.h" // for lua_State arguments to friend functions
27#include "log.hpp"
28#include <set>
29
30struct point;
31class unit_map;
32class game_board;
33class terrain_type;
34
36{
37const int min_window_width = 1280;
38const int min_window_height = 720;
39
40const int def_window_width = 1920;
41const int def_window_height = 1080;
42
43const int max_window_width = 1920;
44const int max_window_height = 1080;
45
46const int min_font_scaling = 80;
47const int max_font_scaling = 150;
48
49const int min_pixel_scale = 1;
50const int max_pixel_scale = 4;
51
56
57const unsigned char CREDENTIAL_SEPARATOR = '\f';
58const std::string EMPTY_LOGIN = "@@";
59
60const int INFINITE_AUTO_SAVES = 61;
61
62const std::string default_addons_server = "add-ons.wesnoth.org";
63
65
67};
68
69namespace sound { class volume; }
70namespace preferences
71{
73{
74public:
76 {
77 }
78
79 explicit acquaintance(const config& cfg)
80 {
81 nick_ = cfg["nick"].str();
82 status_ = cfg["status"].str();
83 notes_ = cfg["notes"].str();
84 }
85
86 acquaintance(const std::string& nick, const std::string& status, const std::string& notes)
87 : nick_(nick)
88 , status_(status)
89 , notes_(notes)
90 {
91 }
92
93 const std::string& get_nick() const { return nick_; }
94 const std::string& get_status() const { return status_; }
95 const std::string& get_notes() const { return notes_; }
96
97 void save(config& item)
98 {
99 item["nick"] = nick_;
100 item["status"] = status_;
101 item["notes"] = notes_;
102 }
103
104private:
105 /** acquaintance's MP nick */
106 std::string nick_;
107
108 /**status (e.g., "friend", "ignore") */
109 std::string status_;
110
111 /** notes on the acquaintance */
112 std::string notes_;
113};
114
115class secure_buffer : public std::vector<unsigned char>
116{
117public:
118 template<typename... T> secure_buffer(T&&... args)
119 : vector<unsigned char>(std::forward<T>(args)...)
120 {}
122 {
123 std::fill(begin(), end(), '\0');
124 }
125};
126
128{
129 std::string username, server;
131 login_info(const std::string& username, const std::string& server, const secure_buffer& key)
133 {}
134 login_info(const std::string& username, const std::string& server)
136 {}
137 std::size_t size() const
138 {
139 return 3 + username.size() + server.size() + key.size();
140 }
141};
142
143struct option
144{
145 option(const config& pref)
146 : type()
147 , name(pref["name"].t_str())
148 , description(pref["description"].t_str())
149 , field(pref["field"].str())
150 , cfg(pref)
151 {
152 const std::string p_type = cfg["type"];
153
154 if(p_type == "boolean") {
156 } else if(p_type == "int") {
158 } else if(p_type == "combo") {
160 } else if(p_type == "custom") {
162 } else {
163 throw std::invalid_argument("Unknown type '" + p_type + "' for advanced preference " + name);
164 }
165 }
166
167 enum class avd_type { TOGGLE, SLIDER, COMBO, SPECIAL };
168
169 /** The preference type. */
171
172 /** Displayed name. */
174
175 /** Displayed description. */
177
178 /** The actual field saved in the prefs file and by which this preference may be accessed. */
179 std::string field;
180
181 /** The full config, including type-specific options. */
183};
184};
185
186#define PREF_GETTER_SETTER(pref, type, def) \
187void set_##pref(const type& value) { \
188 preferences_[prefs_list::pref] = value; \
189} \
190type pref() const { \
191 return preferences_[prefs_list::pref].to(def); \
192}
193
194class prefs
195{
197 friend int impl_preferences_set(lua_State* L);
198 friend int impl_preferences_get(lua_State* L);
199
200public:
201 static prefs& get()
202 {
203 static prefs prefs_manager;
204 return prefs_manager;
205 }
206
207 ~prefs();
208
209 void write_preferences();
211 void migrate_preferences(const std::string& prefs_dir);
212 void set_campaign_rng_mode_default_for_migration(); // TODO: remove after 1.20. (Not used after that. Needs no replacement.)
214 void reload_preferences();
215 std::set<std::string> all_attributes();
216
217 // Proxies for preferences_dialog
218 void load_hotkeys();
219 void save_hotkeys();
220 void clear_hotkeys();
221
222 // not actually preferences
223 bool show_fps();
224 void set_show_fps(bool value);
225
226 bool message_private();
227 void set_message_private(bool value);
228
230 no_preferences_save = true;
231 }
232
233 static bool preferences_save() {
234 return no_preferences_save;
235 }
236
237 // getter-only
238 bool message_bell();
240 /** Gets the threshold for when to scroll. This scrolling happens when the mouse is in the application and near the border. */
244 sort_order::type addon_manager_saved_order_direction();
245 void set_addon_manager_saved_order_direction(sort_order::type value);
246 bool get_show_deprecation(bool def);
247 bool get_scroll_when_mouse_outside(bool def);
249 bool show_combat();
250 std::string get_chat_timestamp(const std::chrono::system_clock::time_point& t);
252 std::vector<std::string>* get_history(const std::string& id);
253 const std::vector<preferences::option>& get_advanced_preferences() { return advanced_prefs_; }
254
255 // non-trivial getters+setters
257 void set_resolution(const point& res);
258
259 int pixel_scale();
260 void set_pixel_scale(const int scale);
261
262 bool turbo();
263 void set_turbo(bool ison);
264
265 int font_scaling();
266 void set_font_scaling(int scale);
267 int font_scaled(int size);
268
269 int keepalive_timeout();
270 void keepalive_timeout(int seconds);
271
272 bool sound();
273 bool set_sound(bool ison);
274
277
280
283
284 bool music_on();
285 bool set_music(bool ison);
286
289
290 bool turn_bell();
291 bool set_turn_bell(bool ison);
292
293 bool ui_sound_on();
294 bool set_ui_sound(bool ison);
295
296 void add_alias(const std::string& alias, const std::string& command);
298
299 std::string allied_color();
300 void set_allied_color(const std::string& color_id);
301
302 std::string enemy_color();
303 void set_enemy_color(const std::string& color_id);
304
305 std::string unmoved_color();
306 void set_unmoved_color(const std::string& color_id);
307
308 std::string partial_color();
309 void set_partial_color(const std::string& color_id);
310
311 std::string moved_color();
312 void set_moved_color(const std::string& color_id);
313
314 std::string reach_map_color();
315 void set_reach_map_color(const std::string& color_id);
316
317 std::string reach_map_enemy_color();
318 void set_reach_map_enemy_color(const std::string& color_id);
319
321 void set_reach_map_border_opacity(const int new_opacity);
322
324 void set_reach_map_tint_opacity(const int new_opacity);
325
327 void set_reach_map_darken_opacity(const int new_opacity);
328
330 void set_reach_map_darken_tex(const bool value);
331
332 int scroll_speed();
333 void set_scroll_speed(const int scroll);
334
335 void set_dir_bookmarks(const config& cfg);
337
338 std::size_t editor_mru_limit();
339 std::vector<std::string> do_read_editor_mru();
340 void do_commit_editor_mru(const std::vector<std::string>& mru);
341 /** Retrieves the list of recently opened files. */
342 std::vector<std::string> recent_files();
343 /** Adds an entry to the recent files list. */
344 void add_recent_files_entry(const std::string& path);
345
346 bool use_color_cursors();
347 void set_color_cursors(bool value);
348
351
353 bool show_theme_dialog();
354
355 void set_theme(const std::string& theme);
356 std::string theme();
357
358 void set_mp_server_program_name(const std::string&);
359 std::string get_mp_server_program_name();
360
361 bool parse_should_show_lobby_join(const std::string& sender, const std::string& message);
364
365 const std::map<std::string, preferences::acquaintance>& get_acquaintances();
366 const std::string get_ignored_delim();
367 std::map<std::string, std::string> get_acquaintances_nice(const std::string& filter);
368 std::pair<preferences::acquaintance*, bool> add_acquaintance(const std::string& nick, const std::string& mode, const std::string& notes);
369 void add_completed_campaign(const std::string&campaign_id, const std::string& difficulty_level);
370 bool remove_acquaintance(const std::string& nick);
371 bool is_friend(const std::string& nick);
372 bool is_ignored(const std::string& nick);
373 bool is_campaign_completed(const std::string& campaign_id);
374 bool is_campaign_completed(const std::string& campaign_id, const std::string& difficulty_level);
375
376 void add_game_preset(config&& preset_data);
377 void remove_game_preset(int id);
380
381 const std::vector<game_config::server_info>& builtin_servers_list();
382 std::vector<game_config::server_info> user_servers_list();
383 void set_user_servers_list(const std::vector<game_config::server_info>& value);
384
385 std::string network_host();
386 void set_network_host(const std::string& host);
387
388 std::string campaign_server();
389 void set_campaign_server(const std::string& host);
390
391 const config& options();
392 void set_options(const config& values);
393
394 std::chrono::seconds countdown_init_time();
395 void set_countdown_init_time(const std::chrono::seconds& value);
397
398 std::chrono::seconds countdown_turn_bonus();
399 void set_countdown_turn_bonus(const std::chrono::seconds& value);
401
402 std::chrono::seconds countdown_reservoir_time();
403 void set_countdown_reservoir_time(const std::chrono::seconds& value);
405
406 std::chrono::seconds countdown_action_bonus();
407 void set_countdown_action_bonus(const std::chrono::seconds& value);
409
410 std::chrono::minutes chat_message_aging();
411 void set_chat_message_aging(const std::chrono::minutes& value);
412
413 int village_gold();
414 void set_village_gold(int value);
415
416 int village_support();
417 void set_village_support(int value);
418
419 int xp_modifier();
420 void set_xp_modifier(int value);
421
422 bool remember_password();
423 void set_remember_password(bool remember);
424
425 std::string login();
426 void set_login(const std::string& login);
427
428 std::string password(const std::string& server, const std::string& login);
429 void set_password(const std::string& server, const std::string& login, const std::string& key);
430
431 const std::vector<std::string>& modifications(bool mp = true);
432 void set_modifications(const std::vector<std::string>& value, bool mp = true);
433
434 std::set<std::string>& encountered_units();
435 std::set<t_translation::terrain_code>& encountered_terrains();
436
437 // Ask for end turn confirmation
438 bool yellow_confirm();
439 bool green_confirm();
440 bool confirm_no_moves();
441
442 // Add all recruitable units as encountered so that information
443 // about them are displayed to the user in the help system.
444 void encounter_recruitable_units(const std::vector<team>& teams);
445
446 // Add all units that exist at the start to the encountered units so
447 // that information about them are displayed to the user in the help
448 // system.
449 void encounter_start_units(const unit_map& units);
450
451 // Add all units that are recallable as encountered units.
452 void encounter_recallable_units(const std::vector<team>& teams);
453
454 // Add all terrains on the map as encountered terrains.
455 void encounter_map_terrain(const gamemap& map);
456
457 // Mark the given terrain type as encountered.
458 void encounter_map_terrain(const terrain_type& terrain);
459
460 // Calls all of the above functions on the current game board
461 void encounter_all_content(const game_board& gb);
462
463 /**
464 * @param content_for The achievement group the achievement is part of.
465 * @param id The ID of the achievement within the achievement group.
466 * @return True if the achievement exists and is completed, false otherwise.
467 */
468 bool achievement(const std::string& content_for, const std::string& id);
469 /**
470 * Marks the specified achievement as completed.
471 *
472 * @param content_for The achievement group the achievement is part of.
473 * @param id The ID of the achievement within the achievement group.
474 */
475 void set_achievement(const std::string& content_for, const std::string& id);
476
477 /**
478 * Increments the achievement's current progress by @a amount if it hasn't already been completed.
479 * If you only want to check the achievement's current progress, then omit the last three arguments.
480 * @a amount defaults to 0, which will result in the current progress value being returned without being changed (x + 0 == x).
481 *
482 * Note that this uses the same [in_progress] as is used for set_sub_achievement().
483 *
484 * @param content_for The id of the achievement group this achievement is in.
485 * @param id The id for the specific achievement in the achievement group.
486 * @param limit The maximum value that a specific call to this function can increase the achievement progress value.
487 * @param max_progress The value when the achievement is considered completed.
488 * @param amount The amount to progress the achievement.
489 * @return The achievement's current progress, or -1 if it has already been completed.
490 */
491 int progress_achievement(const std::string& content_for, const std::string& id, int limit = 999999, int max_progress = 999999, int amount = 0);
492
493 /**
494 * @param content_for The achievement group the achievement is part of.
495 * @param id The ID of the achievement within the achievement group.
496 * @param sub_id The ID of the sub-achievement within the achievement.
497 * @return True if the sub-achievement exists and is completed, false otherwise.
498 */
499 bool sub_achievement(const std::string& content_for, const std::string& id, const std::string& sub_id);
500
501 /**
502 * Marks the specified sub-achievement as completed.
503 *
504 * Note that this uses the same [in_progress] as is used for progress_achievement().
505 *
506 * @param content_for The achievement group the achievement is part of.
507 * @param id The ID of the achievement within the achievement group.
508 * @param sub_id The ID of the sub-achievement within the achievement.
509 */
510 void set_sub_achievement(const std::string& content_for, const std::string& id, const std::string& sub_id);
511
512 PREF_GETTER_SETTER(addon_icons, bool, true)
513 PREF_GETTER_SETTER(show_ally_orb, bool, game_config::show_ally_orb)
514 PREF_GETTER_SETTER(show_status_on_ally_orb, bool, game_config::show_status_on_ally_orb)
515 PREF_GETTER_SETTER(show_enemy_orb, bool, game_config::show_enemy_orb)
516 PREF_GETTER_SETTER(show_moved_orb, bool, game_config::show_moved_orb)
517 PREF_GETTER_SETTER(show_unmoved_orb, bool, game_config::show_unmoved_orb)
518 PREF_GETTER_SETTER(show_partial_orb, bool, game_config::show_partial_orb)
519 PREF_GETTER_SETTER(show_disengaged_orb, bool, game_config::show_disengaged_orb)
520 PREF_GETTER_SETTER(core, std::string, std::string("default"))
521 PREF_GETTER_SETTER(scroll_to_action, bool, true)
522 PREF_GETTER_SETTER(auto_pixel_scale, bool, true)
523 PREF_GETTER_SETTER(maximized, bool, !fullscreen())
524 PREF_GETTER_SETTER(fullscreen, bool, true)
525 PREF_GETTER_SETTER(vsync, bool, true)
526 PREF_GETTER_SETTER(turbo_speed, double, 2.0)
527 PREF_GETTER_SETTER(idle_anim, bool, true)
528 PREF_GETTER_SETTER(idle_anim_rate, int, 0)
529 PREF_GETTER_SETTER(locale, std::string, std::string(""))
530 PREF_GETTER_SETTER(gui2_theme, std::string, std::string(""))
531 PREF_GETTER_SETTER(show_tips, bool, true)
532 PREF_GETTER_SETTER(stop_music_in_background, bool, false)
533 PREF_GETTER_SETTER(tile_size, unsigned, 0)
534 PREF_GETTER_SETTER(mouse_scrolling, bool, true)
535 PREF_GETTER_SETTER(refresh_rate, int, -1)
536 PREF_GETTER_SETTER(animate_map, bool, true)
537 PREF_GETTER_SETTER(animate_water, bool, true)
538 PREF_GETTER_SETTER(minimap_movement_coding, bool, true)
539 PREF_GETTER_SETTER(minimap_terrain_coding, bool, true)
540 PREF_GETTER_SETTER(minimap_draw_units, bool, true)
541 PREF_GETTER_SETTER(minimap_draw_villages, bool, true)
542 PREF_GETTER_SETTER(minimap_draw_terrain, bool, true)
543 PREF_GETTER_SETTER(show_side_colors, bool, true)
544 PREF_GETTER_SETTER(grid, bool, false)
545 PREF_GETTER_SETTER(disable_auto_moves, bool, false)
546 PREF_GETTER_SETTER(damage_prediction_allow_monte_carlo_simulation, bool, true)
547 PREF_GETTER_SETTER(campaign_rng_mode, std::string, std::string("biased"))
548 PREF_GETTER_SETTER(addon_manager_saved_order_name, std::string, std::string(""))
549 PREF_GETTER_SETTER(selected_achievement_group, std::string, std::string(""))
550 /** The most recently selected add-on id from the editor. May be an empty string. */
551 PREF_GETTER_SETTER(editor_chosen_addon, std::string, std::string(""))
552 PREF_GETTER_SETTER(_last_cache_cleaned_ver, std::string, std::string(""))
553 PREF_GETTER_SETTER(lobby_whisper_friends_only, bool, false)
554 PREF_GETTER_SETTER(fi_invert, bool, false)
555 PREF_GETTER_SETTER(fi_vacant_slots, bool, false)
556 PREF_GETTER_SETTER(fi_friends_in_game, bool, false)
557 PREF_GETTER_SETTER(fi_blocked_in_game, bool, false)
558 PREF_GETTER_SETTER(editor_auto_update_transitions, int, pref_constants::TRANSITION_UPDATE_PARTIAL)
559 PREF_GETTER_SETTER(editor_draw_terrain_codes, bool, false)
560 PREF_GETTER_SETTER(editor_draw_hex_coordinates, bool, false)
561 PREF_GETTER_SETTER(editor_draw_num_of_bitmaps, bool, false)
562 PREF_GETTER_SETTER(turn_dialog, bool, false)
563 PREF_GETTER_SETTER(enable_planning_mode_on_start, bool, false)
564 PREF_GETTER_SETTER(hide_whiteboard, bool, false)
565 PREF_GETTER_SETTER(allow_observers, bool, true)
566 PREF_GETTER_SETTER(shuffle_sides, bool, false)
567 PREF_GETTER_SETTER(random_faction_mode, std::string, std::string(""))
568 PREF_GETTER_SETTER(mp_use_map_settings, bool, true)
569 PREF_GETTER_SETTER(mp_server_warning_disabled, int, 0)
570 PREF_GETTER_SETTER(mp_random_start_time, bool, true)
571 PREF_GETTER_SETTER(mp_fog, bool, true)
572 PREF_GETTER_SETTER(mp_shroud, bool, true)
573 PREF_GETTER_SETTER(mp_turns, int, 0)
574 PREF_GETTER_SETTER(skip_mp_replay, bool, false)
575 PREF_GETTER_SETTER(blindfold_replay, bool, false)
576 PREF_GETTER_SETTER(mp_countdown, bool, false)
577 PREF_GETTER_SETTER(mp_era, std::string, std::string(""))
578 PREF_GETTER_SETTER(mp_level, std::string, std::string(""))
579 PREF_GETTER_SETTER(mp_level_type, int, 0)
580 PREF_GETTER_SETTER(mp_connect_type, int, 0)
581 PREF_GETTER_SETTER(skip_ai_moves, bool, false)
582 PREF_GETTER_SETTER(save_replays, bool, true)
583 PREF_GETTER_SETTER(delete_saves, bool, false)
584 PREF_GETTER_SETTER(ask_delete, bool, true)
585 PREF_GETTER_SETTER(ally_sighted_interrupts, bool, true)
586 PREF_GETTER_SETTER(auto_save_max, int, 10)
587 PREF_GETTER_SETTER(floating_labels, bool, true)
588 PREF_GETTER_SETTER(chat_timestamp, bool, false)
589 PREF_GETTER_SETTER(chat_lines, int, 6)
590 PREF_GETTER_SETTER(show_all_units_in_help, bool, false)
591 PREF_GETTER_SETTER(custom_command, std::string, std::string(""))
592 PREF_GETTER_SETTER(player_joins_sound, bool, true)
593 PREF_GETTER_SETTER(player_joins_lobby, bool, false)
594 PREF_GETTER_SETTER(player_joins_notif, bool, false)
595 PREF_GETTER_SETTER(player_leaves_sound, bool, true)
596 PREF_GETTER_SETTER(player_leaves_lobby, bool, false)
597 PREF_GETTER_SETTER(player_leaves_notif, bool, false)
598 PREF_GETTER_SETTER(private_message_sound, bool, true)
599 PREF_GETTER_SETTER(private_message_lobby, bool, desktop::notifications::available())
600 PREF_GETTER_SETTER(private_message_notif, bool, true)
601 PREF_GETTER_SETTER(friend_message_sound, bool, false)
602 PREF_GETTER_SETTER(friend_message_lobby, bool, false)
603 PREF_GETTER_SETTER(friend_message_notif, bool, false)
604 PREF_GETTER_SETTER(public_message_sound, bool, false)
605 PREF_GETTER_SETTER(public_message_lobby, bool, false)
606 PREF_GETTER_SETTER(public_message_notif, bool, false)
607 PREF_GETTER_SETTER(server_message_sound, bool, true)
608 PREF_GETTER_SETTER(server_message_lobby, bool, false)
609 PREF_GETTER_SETTER(server_message_notif, bool, true)
610 PREF_GETTER_SETTER(ready_for_start_sound, bool, true)
611 PREF_GETTER_SETTER(ready_for_start_lobby, bool, desktop::notifications::available())
612 PREF_GETTER_SETTER(ready_for_start_notif, bool, false)
613 PREF_GETTER_SETTER(game_has_begun_sound, bool, true)
614 PREF_GETTER_SETTER(game_has_begun_lobby, bool, desktop::notifications::available())
615 PREF_GETTER_SETTER(game_has_begun_notif, bool, false)
616 PREF_GETTER_SETTER(turn_changed_sound, bool, true)
617 PREF_GETTER_SETTER(turn_changed_lobby, bool, desktop::notifications::available())
618 PREF_GETTER_SETTER(turn_changed_notif, bool, false)
619 PREF_GETTER_SETTER(game_created_sound, bool, true)
620 PREF_GETTER_SETTER(game_created_lobby, bool, desktop::notifications::available())
621 PREF_GETTER_SETTER(game_created_notif, bool, true)
622 PREF_GETTER_SETTER(editor_help_text_shown, bool, true)
623 PREF_GETTER_SETTER(show_attack_miss_indicator, bool, false)
624 PREF_GETTER_SETTER(simd_enabled, bool, true)
625#undef PREF_GETTER_SETTER
627
628private:
629 prefs();
630 // don't move, assign, or copy a singleton
631 prefs(const prefs& p) = delete;
632 prefs& operator=(const prefs& p) = delete;
633 prefs(const prefs&& p) = delete;
634 prefs& operator=(const prefs&& p) = delete;
635
636 inline static bool no_preferences_save = false;
637
639 bool fps_;
640 std::map<std::string, std::set<std::string>> completed_campaigns_;
641 std::set<std::string> encountered_units_set_;
642 std::set<t_translation::terrain_code> encountered_terrains_set_;
643 std::map<std::string, std::vector<std::string>> history_map_;
644 std::map<std::string, preferences::acquaintance> acquaintances_;
647 std::vector<std::string> mp_modifications_;
649 std::vector<std::string> sp_modifications_;
652 std::vector<preferences::login_info> credentials_;
653 std::vector<preferences::option> advanced_prefs_;
654
655 void load_preferences();
657 void load_credentials();
658 void save_credentials();
659 void clear_credentials();
660
661 void set_child(const std::string& key, const config& val);
662 optional_const_config get_child(const std::string &key);
663 std::string get(const std::string& key, const std::string& def);
664 config::attribute_value get_as_attribute(const std::string& key);
665
666 std::string get_system_username();
667 /**
668 * Encrypts the value of @a text using @a key and a hard coded IV using AES.
669 * Max size of @a text must not be larger than 1008 bytes.
670 *
671 * NOTE: This is not meant to provide strong protections against a determined attacker.
672 * This is meant to hide the passwords from malware scanning files for passwords, family/friends poking around, etc.
673 *
674 * @param text The original unencrypted data.
675 * @param key The value to use to encrypt the data. See build_key() for key generation.
676 * @return secure_buffer The encrypted data.
677 */
679 /**
680 * Same as aes_encrypt(), except of course it takes encrypted data as an argument and returns decrypted data.
681 */
683 /**
684 * Fills a secure_buffer with 32 bytes of deterministically generated bytes, then overwrites it with the system login name, server login name, and server name.
685 * If this is more than 32 bytes, then it's truncated. If it's less than 32 bytes, then the pre-generated bytes are used to pad it.
686 *
687 * @param server The server being logged into.
688 * @param login The username being used to login.
689 * @return secure_buffer The data to be used as the encryption key.
690 */
691 preferences::secure_buffer build_key(const std::string& server, const std::string& login);
694
695 std::set<std::string> unknown_synced_attributes_;
696 std::set<std::string> unknown_unsynced_attributes_;
697 std::set<std::string> unknown_synced_children_;
698 std::set<std::string> unknown_unsynced_children_;
699
700 // a bit verbose, but it being a compile time error if a preference hasn't been added is nice
701 static constexpr std::array synced_attributes_{
702 prefs_list::player_joins_sound,
703 prefs_list::player_joins_notif,
704 prefs_list::player_joins_lobby,
705 prefs_list::player_leaves_sound,
706 prefs_list::player_leaves_notif,
707 prefs_list::player_leaves_lobby,
708 prefs_list::private_message_sound,
709 prefs_list::private_message_notif,
710 prefs_list::private_message_lobby,
711 prefs_list::friend_message_sound,
712 prefs_list::friend_message_notif,
713 prefs_list::friend_message_lobby,
714 prefs_list::public_message_sound,
715 prefs_list::public_message_notif,
716 prefs_list::public_message_lobby,
717 prefs_list::server_message_sound,
718 prefs_list::server_message_notif,
719 prefs_list::server_message_lobby,
720 prefs_list::ready_for_start_sound,
721 prefs_list::ready_for_start_notif,
722 prefs_list::ready_for_start_lobby,
723 prefs_list::game_has_begun_sound,
724 prefs_list::game_has_begun_notif,
725 prefs_list::game_has_begun_lobby,
726 prefs_list::turn_changed_sound,
727 prefs_list::turn_changed_notif,
728 prefs_list::turn_changed_lobby,
729 prefs_list::game_created_sound,
730 prefs_list::game_created_notif,
731 prefs_list::game_created_lobby,
732 prefs_list::_last_cache_cleaned_ver,
733 prefs_list::addon_manager_saved_order_direction,
734 prefs_list::addon_manager_saved_order_name,
735 prefs_list::alias,
736 prefs_list::allow_observers,
737 prefs_list::ally_orb_color,
738 prefs_list::ally_sighted_interrupts,
739 prefs_list::auto_save_max,
740 prefs_list::blindfold_replay,
741 prefs_list::campaign_rng_mode,
742 prefs_list::campaign_server,
743 prefs_list::chat_lines,
744 prefs_list::chat_timestamp,
745 prefs_list::confirm_end_turn,
746 prefs_list::custom_command,
747 prefs_list::delete_saves,
748 prefs_list::disable_auto_moves,
749 prefs_list::editor_auto_update_transitions,
750 prefs_list::editor_draw_hex_coordinates,
751 prefs_list::editor_draw_num_of_bitmaps,
752 prefs_list::editor_draw_terrain_codes,
753 prefs_list::enable_planning_mode_on_start,
754 prefs_list::encountered_terrain_list,
755 prefs_list::encountered_units,
756 prefs_list::enemy_orb_color,
757 prefs_list::fi_blocked_in_game,
758 prefs_list::fi_friends_in_game,
759 prefs_list::fi_invert,
760 prefs_list::fi_vacant_slots,
761 prefs_list::floating_labels,
762 prefs_list::grid,
763 prefs_list::hide_whiteboard,
764 prefs_list::host,
765 prefs_list::idle_anim,
766 prefs_list::idle_anim_rate,
767 prefs_list::lobby_joins,
768 prefs_list::lobby_whisper_friends_only,
769 prefs_list::locale,
770 prefs_list::login,
771 prefs_list::message_bell,
772 prefs_list::minimap_draw_terrain,
773 prefs_list::minimap_draw_units,
774 prefs_list::minimap_draw_villages,
775 prefs_list::minimap_movement_coding,
776 prefs_list::minimap_terrain_coding,
777 prefs_list::moved_orb_color,
778 prefs_list::mp_countdown,
779 prefs_list::mp_countdown_action_bonus,
780 prefs_list::mp_countdown_init_time,
781 prefs_list::mp_countdown_reservoir_time,
782 prefs_list::mp_countdown_turn_bonus,
783 prefs_list::mp_fog,
784 prefs_list::mp_level_type,
785 prefs_list::mp_connect_type,
786 prefs_list::mp_random_start_time,
787 prefs_list::mp_server_warning_disabled,
788 prefs_list::mp_shroud,
789 prefs_list::mp_turns,
790 prefs_list::mp_use_map_settings,
791 prefs_list::mp_village_gold,
792 prefs_list::mp_village_support,
793 prefs_list::mp_xp_modifier,
794 prefs_list::music,
795 prefs_list::partial_orb_color,
796 prefs_list::random_faction_mode,
797 prefs_list::remember_password,
798 prefs_list::save_replays,
799 prefs_list::scroll,
800 prefs_list::scroll_threshold,
801 prefs_list::show_ally_orb,
802 prefs_list::show_disengaged_orb,
803 prefs_list::show_enemy_orb,
804 prefs_list::show_moved_orb,
805 prefs_list::show_partial_orb,
806 prefs_list::show_side_colors,
807 prefs_list::show_status_on_ally_orb,
808 prefs_list::show_unmoved_orb,
809 prefs_list::shuffle_sides,
810 prefs_list::skip_ai_moves,
811 prefs_list::skip_mp_replay,
812 prefs_list::sound,
813 prefs_list::stop_music_in_background,
814 prefs_list::turbo,
815 prefs_list::turbo_speed,
816 prefs_list::turn_bell,
817 prefs_list::turn_dialog,
818 prefs_list::ui_sound,
819 prefs_list::unit_standing_animations,
820 prefs_list::unmoved_orb_color,
821 prefs_list::ask_delete,
822 prefs_list::chat_message_aging,
823 prefs_list::color_cursors,
824 prefs_list::compress_saves,
825 prefs_list::confirm_load_save_from_different_version,
826 prefs_list::damage_prediction_allow_monte_carlo_simulation,
827 prefs_list::editor_max_recent_files,
828 prefs_list::keepalive_timeout,
829 prefs_list::lobby_auto_open_whisper_windows,
830 prefs_list::middle_click_scrolls,
831 prefs_list::mouse_scrolling,
832 prefs_list::scroll_to_action,
833 prefs_list::scroll_when_mouse_outside,
834 prefs_list::show_all_units_in_help,
835 prefs_list::show_combat,
836 prefs_list::show_deprecation,
837 prefs_list::show_attack_miss_indicator,
838 prefs_list::use_twelve_hour_clock_format,
839 prefs_list::mp_era,
840 prefs_list::mp_level,
841 prefs_list::mp_modifications,
842 prefs_list::selected_achievement_group,
843 prefs_list::sp_modifications,
844 prefs_list::animate_map,
845 prefs_list::animate_water,
846 prefs_list::addon_icons,
847 prefs_list::reach_map_border_opacity,
848 prefs_list::reach_map_tint_opacity,
849 prefs_list::reach_map_darken_opacity,
850 prefs_list::reach_map_darken_tex,
851 prefs_list::reach_map_color,
852 prefs_list::reach_map_enemy_color,
853 };
854 static constexpr std::array synced_children_{
855 prefs_list::acquaintance,
856 prefs_list::achievements,
857 prefs_list::completed_campaigns,
858 prefs_list::history,
859 prefs_list::hotkey,
860 prefs_list::options,
861 prefs_list::server,
862 prefs_list::game_preset,
863 };
864 static constexpr std::array unsynced_attributes_{
865 prefs_list::auto_pixel_scale,
866 prefs_list::core,
867 prefs_list::refresh_rate,
868 prefs_list::editor_chosen_addon,
869 prefs_list::gui2_theme,
870 prefs_list::show_tips,
871 prefs_list::mp_server_program_name,
872 prefs_list::pixel_scale,
873 prefs_list::theme,
874 prefs_list::tile_size,
875 prefs_list::vsync,
876 prefs_list::xresolution,
877 prefs_list::yresolution,
878 prefs_list::font_scale,
879 prefs_list::bell_volume,
880 prefs_list::music_volume,
881 prefs_list::simd_enabled,
882 prefs_list::sound_volume,
883 prefs_list::ui_volume,
884 prefs_list::fullscreen,
885 prefs_list::maximized,
886 };
887 static constexpr std::array unsynced_children_{
888 prefs_list::editor_recent_files,
889 prefs_list::dir_bookmarks,
890 };
891 static_assert(synced_attributes_.size() + synced_children_.size() + unsynced_attributes_.size() + unsynced_children_.size() == prefs_list::values.size(), "attribute missing from lists of synced or unsynced preferences!");
892};
893
894//
895// might be overkill, but it does best limit the private functionality being exposed
896//
897
899{
900 friend class preferences_dialog;
901
902 static void set(const std::string& pref, bool value)
903 {
904 prefs::get().preferences_[pref] = value;
905 }
906 static void set(const std::string& pref, int value)
907 {
908 prefs::get().preferences_[pref] = value;
909 }
910 static void set(const std::string& pref, const std::string& value)
911 {
912 prefs::get().preferences_[pref] = value;
913 }
914
915 static bool get(const std::string& pref, bool def)
916 {
917 return prefs::get().preferences_[pref].to_bool(def);
918 }
919 static int get(const std::string& pref, int def)
920 {
921 return prefs::get().preferences_[pref].to_int(def);
922 }
923 static std::string get(const std::string& pref, const std::string& def)
924 {
925 return prefs::get().get(pref, def);
926 }
927};
double t
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
boost::iterator_range< child_iterator > child_itors
Definition config.hpp:280
void clear()
Definition config.cpp:802
Game board class.
A class grating read only view to a vector of config objects, viewed as one config with all children ...
Encapsulates the map of the game.
Definition map.hpp:176
const std::string & get_notes() const
const std::string & get_status() const
std::string nick_
acquaintance's MP nick
void save(config &item)
acquaintance(const std::string &nick, const std::string &status, const std::string &notes)
std::string notes_
notes on the acquaintance
const std::string & get_nick() const
std::string status_
status (e.g., "friend", "ignore")
acquaintance(const config &cfg)
void set_lobby_joins(pref_constants::lobby_joins show)
std::string enemy_color()
const std::vector< preferences::option > & get_advanced_preferences()
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()
const config & options()
bool set_music(bool ison)
void set_remember_password(bool remember)
const std::map< std::string, preferences::acquaintance > & get_acquaintances()
optional_const_config get_alias()
bool show_theme_dialog()
void set_turbo(bool ison)
static prefs & get()
std::string get_system_username()
sound::volume music_volume()
prefs(const prefs &&p)=delete
void set_sound_volume(sound::volume vol)
bool mp_modifications_initialized_
std::map< std::string, std::vector< std::string > > history_map_
void save_hotkeys()
int village_support()
void set_addon_manager_saved_order_direction(sort_order::type value)
std::chrono::seconds countdown_turn_bonus()
bool middle_click_scrolls()
bool turn_bell()
void set_countdown_reservoir_time(const std::chrono::seconds &value)
void remove_game_preset(int id)
std::set< std::string > & encountered_units()
void add_alias(const std::string &alias, const std::string &command)
void write_preferences()
void clear_preferences()
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_
sound::volume sound_volume()
int reach_map_darken_opacity()
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)
void set_initial_gui2_theme()
const std::string get_ignored_delim()
std::map< std::string, preferences::acquaintance > acquaintances_
friend int impl_preferences_set(lua_State *L)
The __newindex metamethod.
static constexpr std::array unsynced_children_
sound::volume bell_volume()
bool fps_
config::child_itors get_game_presets()
int scroll_speed()
bool message_private()
void encounter_recallable_units(const std::vector< team > &teams)
std::map< std::string, std::set< std::string > > completed_campaigns_
bool show_combat()
std::string theme()
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 reach_map_darken_tex()
bool sound()
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()
bool green_confirm()
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_
std::set< std::string > unknown_synced_attributes_
void set_enemy_color(const std::string &color_id)
void save_credentials()
std::chrono::seconds countdown_init_time()
void set_password(const std::string &server, const std::string &login, const std::string &key)
void clear_credentials()
std::vector< preferences::login_info > credentials_
std::vector< std::string > do_read_editor_mru()
prefs & operator=(const prefs &p)=delete
void encounter_recruitable_units(const std::vector< team > &teams)
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
static bool preferences_save()
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_
void set_reach_map_tint_opacity(const int new_opacity)
sound::volume ui_volume()
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)
void load_credentials()
std::string unmoved_color()
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()
bool show_fps()
void load_hotkeys()
void set_chat_message_aging(const std::chrono::minutes &value)
optional_const_config get_game_preset(int id)
void encounter_map_terrain(const gamemap &map)
void set_campaign_rng_mode_default_for_migration()
int font_scaling()
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()
bool confirm_no_moves()
void set_font_scaling(int scale)
bool use_color_cursors()
bool yellow_confirm()
config option_values_
void migrate_preferences(const std::string &prefs_dir)
bool message_bell()
void set_dir_bookmarks(const config &cfg)
bool message_private_on_
std::set< t_translation::terrain_code > encountered_terrains_set_
friend int impl_preferences_get(lua_State *L)
The __index metamethod.
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 ...
int village_gold()
config preferences_
void clear_countdown_turn_bonus()
std::string login()
bool music_on()
int font_scaled(int size)
void set_scroll_speed(const int scroll)
void set_music_volume(sound::volume vol)
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
prefs(const prefs &p)=delete
bool ui_sound_on()
bool options_initialized_
int pixel_scale()
std::string partial_color()
preferences::secure_buffer unescape(const preferences::secure_buffer &text)
void set_resolution(const point &res)
static void disable_preferences_save()
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_reach_map_darken_opacity(const int new_opacity)
bool turbo()
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_
prefs & operator=(const prefs &&p)=delete
std::string get_mp_server_program_name()
std::string reach_map_enemy_color()
void add_game_preset(config &&preset_data)
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()
int keepalive_timeout()
void set_mp_server_program_name(const std::string &)
void set_bell_volume(sound::volume vol)
bool remember_password()
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)
point resolution()
bool use_twelve_hour_clock_format()
static bool no_preferences_save
int reach_map_border_opacity()
void set_reach_map_darken_tex(const bool value)
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 clear_hotkeys()
int xp_modifier()
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()
void load_preferences()
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()
void set_ui_volume(sound::volume vol)
Container associating units to locations.
Definition map.hpp:98
Definitions for the interface to Wesnoth Markup Language (WML).
const config * cfg
Declarations for File-IO.
Standard logging facilities (interface).
Game configuration data as global variables.
Main entry points of multiplayer mode.
const int min_window_height
const int TRANSITION_UPDATE_ON
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 TRANSITION_UPDATE_COUNT
const int min_window_width
const int TRANSITION_UPDATE_OFF
const int max_font_scaling
const int max_window_height
const int max_window_width
const int def_window_height
const int INFINITE_AUTO_SAVES
const unsigned char CREDENTIAL_SEPARATOR
const int TRANSITION_UPDATE_PARTIAL
Modify, read and display user preferences.
Audio output for sound and music.
STL namespace.
#define PREF_GETTER_SETTER(pref, type, def)
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
Definition sound.cpp:139
Represents a single achievement and its data.
Holds a 2D point.
Definition point.hpp:25
login_info(const std::string &username, const std::string &server, const secure_buffer &key)
std::size_t size() const
login_info(const std::string &username, const std::string &server)
t_string description
Displayed description.
avd_type type
The preference type.
option(const config &pref)
t_string name
Displayed name.
std::string field
The actual field saved in the prefs file and by which this preference may be accessed.
config cfg
The full config, including type-specific options.
static void set(const std::string &pref, int value)
static void set(const std::string &pref, const std::string &value)
static int get(const std::string &pref, int def)
static std::string get(const std::string &pref, const std::string &def)
static bool get(const std::string &pref, bool def)
static void set(const std::string &pref, bool value)
The base template for associating string values with enum values.
Definition enum_base.hpp:33
Represents a distinct sub-achievement within another achievement.
mock_party p