16#define GETTEXT_DOMAIN "wesnoth-lib"
40#include "addon/manager.hpp"
56#define DBG_LB LOG_STREAM(debug, log_lobby)
57#define LOG_LB LOG_STREAM(info, log_lobby)
58#define ERR_LB LOG_STREAM(err, log_lobby)
59#define SCOPE_LB log_scope2(log_lobby, __func__)
67 return show_prompt(
_(
"Do you really want to log out?"));
73 , gamelistbox_(nullptr)
76 , filter_friends_(register_bool(
"filter_with_friends",
78 []() {
return prefs::get().fi_friends_in_game();},
79 [](
bool v) {
prefs::get().set_fi_friends_in_game(v);},
81 , filter_ignored_(register_bool(
"filter_with_ignored",
83 []() {
return prefs::get().fi_blocked_in_game();},
84 [](
bool v) {
prefs::get().set_fi_blocked_in_game(v);},
86 , filter_slots_(register_bool(
"filter_vacant_slots",
89 [](
bool v) {
prefs::get().set_fi_vacant_slots(v);},
91 , filter_invert_(register_bool(
"filter_invert",
96 , filter_auto_hosted_(
false)
97 , filter_game_presets_(
false)
98 , filter_text_(
nullptr)
102 , player_list_dirty_(
true)
103 , gamelist_dirty_(
true)
104 , last_lobby_update_()
105 , gamelist_diff_update_(
true)
106 , network_connection_(connection)
107 , lobby_update_timer_(0)
108 , gamelist_id_at_row_()
109 , delay_playerlist_update_(
false)
110 , delay_gamelist_update_(
false)
111 , joined_game_id_(joined_game)
112 , queue_game_server_preset_()
114 set_show_even_without_video(
true);
115 set_allow_plugin_skip(
false);
116 set_always_save_fields(
true);
123 [
this](
auto&&...) { show_preferences_button_callback();
return true; });
150 for(
const auto& v : map) {
151 const std::string& key = v.first;
164 for(
const auto & vv : strmap) {
165 if(vv.first ==
"label") {
167 }
else if(vv.first ==
"tooltip") {
168 c->set_tooltip(vv.second);
174bool handle_addon_requirements_gui(
const std::vector<mp::game_info::required_addon>& reqs,
mp::game_info::addon_req addon_outcome)
177 std::string e_title =
_(
"Incompatible User-made Content");
178 std::string err_msg =
_(
"This game cannot be joined because the host has out-of-date add-ons that are incompatible with your version. You might wish to suggest that the host’s add-ons be updated.");
181 err_msg +=
_(
"Details:");
193 std::string e_title =
_(
"Missing User-made Content");
194 std::string err_msg =
_(
"This game requires one or more user-made addons to be installed or updated in order to join.\nDo you want to try to install them?");
197 err_msg +=
_(
"Details:");
200 std::vector<std::string> needs_download;
205 needs_download.push_back(a.addon_id);
209 assert(needs_download.size() > 0);
245 LOG_LB <<
"Adding game to listbox (1)" <<
game.id;
269 int list_rows_deleted = 0;
273 std::vector<int> next_gamelist_id_at_row;
284 LOG_LB <<
"Adding game to listbox " <<
game.id;
288 DBG_LB <<
"Added a game listbox row not at the end" << list_i
299 next_gamelist_id_at_row.push_back(
game.id);
302 ERR_LB <<
"Ran out of listbox items -- triggering a full refresh";
308 ERR_LB <<
"gamelist_id_at_row_ overflow! " << list_i <<
" + "
311 <<
" -- triggering a full refresh";
317 if(
game.id != listbox_game_id) {
318 ERR_LB <<
"Listbox game id does not match expected id "
319 << listbox_game_id <<
" " <<
game.id <<
" (row " << list_i <<
")";
325 LOG_LB <<
"Modifying game in listbox " <<
game.id <<
" (row " << list_i <<
")";
330 next_gamelist_id_at_row.push_back(
game.id);
332 LOG_LB <<
"Deleting game from listbox " <<
game.id <<
" (row "
338 LOG_LB <<
"Clean game in listbox " <<
game.id <<
" (row " << list_i <<
")";
339 next_gamelist_id_at_row.push_back(
game.id);
345 for(
unsigned i = 0;
i < next_gamelist_id_at_row.size(); ++
i) {
353 ERR_LB <<
"Would select a row beyond the listbox" << select_row <<
" "
371 const std::string games_string =
VGETTEXT(
"Games: showing $num_shown out of $num_total", {
386 item[
"use_markup"] =
"true";
389 if(
game.vacant_slots > 0) {
393 const std::string scenario_text =
VGETTEXT(
"$game_name (Era: $era_name)", {
394 {
"game_name",
game.scenario},
395 {
"era_name",
game.era}
399 data.emplace(
"name", item);
402 data.emplace(
"scenario", item);
405 data.emplace(
"status", item);
420 std::ostringstream ss;
422 const auto mark_missing = [&ss]() {
435 auto mods =
game.mod_info;
438 ss <<
_(
"active_modifications^None") <<
"\n";
440 for(
const auto& mod : mods) {
452 const auto yes_or_no = [](
bool val) {
return val ?
_(
"yes") :
_(
"no"); };
455 ss <<
_(
"Experience modifier:") <<
" " <<
game.xp <<
"\n";
456 ss <<
_(
"Gold per village:") <<
" " <<
game.gold <<
"\n";
457 ss <<
_(
"Map size:") <<
" " <<
game.map_size_info <<
"\n";
458 ss <<
_(
"Reloaded:") <<
" " << yes_or_no(
game.reloaded) <<
"\n";
459 ss <<
_(
"Shared vision:") <<
" " <<
game.vision <<
"\n";
460 ss <<
_(
"Shuffle sides:") <<
" " << yes_or_no(
game.shuffle_sides) <<
"\n";
461 ss <<
_(
"Time limit:") <<
" " <<
game.time_limit <<
"\n";
462 ss <<
_(
"Use map settings:") <<
" " << yes_or_no(
game.use_map_settings);
466 if(!
game.have_era || !
game.have_all_mods || !
game.required_addons.empty()) {
467 info_icon.
set_label(
"icons/icon-info-error.png");
470 ss <<
_(
"One or more add-ons need to be installed\nin order to join this game.");
472 info_icon.
set_label(
"icons/icon-info.png");
482 if(
game.password_required) {
497 observer_icon.
set_label(
"misc/no_observer.png");
515 if(
game.game_preset) {
526 connect_signal_mouse_left_double_click(row_panel,
538 DBG_LB <<
"mp_lobby::update_gamelist_filter";
563 bool can_join =
false, can_observe =
false;
567 can_observe =
game.can_observe();
568 can_join =
game.can_join();
574 find_widget<button>(
"observe_global").set_active(can_observe);
575 find_widget<button>(
"join_global").set_active(can_join);
584 gamelistbox_ = find_widget<listbox>(
"game_list",
false,
true);
596 chatbox_ = find_widget<chatbox>(
"chat",
false,
true);
603 find_widget<button>(
"create").set_retval(
CREATE);
605 connect_signal_mouse_left_click(
606 find_widget<button>(
"show_preferences"),
609 connect_signal_mouse_left_click(
610 find_widget<button>(
"join_global"),
613 find_widget<button>(
"join_global").set_active(
false);
615 connect_signal_mouse_left_click(
616 find_widget<button>(
"observe_global"),
619 connect_signal_mouse_left_click(
620 find_widget<button>(
"server_info"),
623 find_widget<button>(
"observe_global").set_active(
false);
625 menu_button& replay_options = find_widget<menu_button>(
"replay_options");
635 connect_signal_notify_modified(replay_options,
638 filter_text_ = find_widget<text_box>(
"filter_text",
false,
true);
640 connect_signal_pre_key_press(
663 if(
panel* profile_panel = find_widget<panel>(
"profile",
false,
false)) {
665 [](
const auto& u) { return u.get_relation() == mp::user_info::user_relation::ME; });
668 profile_panel->find_widget<
label>(
"username").
set_label(your_info->name);
670 auto& profile_button = profile_panel->find_widget<
button>(
"view_profile");
673 auto& history_button = profile_panel->find_widget<
button>(
"view_match_history");
678 listbox& tab_bar = find_widget<listbox>(
"games_list_tab_bar");
682 button* queue_join_button = find_widget<button>(
"join_queue",
false,
true);
686 button* queue_leave_button = find_widget<button>(
"leave_queue",
false,
true);
724 if(info && info->forum_id != 0) {
731 listbox* queues_listbox = find_widget<listbox>(
"queue_list",
false,
true);
733 if(queues.size() >
static_cast<std::size_t
>(queues_listbox->
get_selected_row())) {
737 std::vector<mp::game_info::required_addon> missing;
744 missing.emplace_back(req);
748 if(!missing.empty()) {
758 ERR_LB <<
"Attempted to join queue but couldn't find queue info";
764 listbox* queues_listbox = find_widget<listbox>(
"queue_list",
false,
true);
766 if(queues.size() >
static_cast<std::size_t
>(queues_listbox->
get_selected_row())) {
770 ERR_LB <<
"Attempted to join queue but couldn't find queue info";
797 LOG_LB <<
"caught wesnothd_error in network_handler: " <<
e.message;
827 listbox* queues_listbox = find_widget<listbox>(
"queue_list",
false,
true);
828 queues_listbox->
clear();
831 std::sort(queues.begin(), queues.end(), [](
const mp::queue_info& q1,
const mp::queue_info& q2) { return q1.display_name < q2.display_name; });
837 item[
"label"] = info.current_players.count(
prefs::get().
login()) > 0 ?
"x" :
"o";
838 data.emplace(
"is_in_queue", item);
840 item[
"label"] = info.display_name;
841 data.emplace(
"queue_name", item);
843 item[
"label"] = std::to_string(info.current_players.size())+
"/"+std::to_string(info.players_required);
844 data.emplace(
"queue_player_count", item);
852 if(
auto error =
data.optional_child(
"error")) {
854 }
else if(
data.has_child(
"gamelist")) {
856 }
else if(
auto gamelist_diff =
data.optional_child(
"gamelist_diff")) {
858 }
else if(
auto info =
data.optional_child(
"message")) {
859 if(info[
"type"] ==
"server_info") {
862 }
else if(info[
"type"] ==
"announcements") {
866 }
else if(
auto create =
data.optional_child(
"create_game")) {
871 }
else if(
auto join_game =
data.optional_child(
"join_game")) {
874 }
else if(
auto queue_update =
data.optional_child(
"queue_update")) {
876 if(queue_update[
"action"].str() ==
"add") {
878 new_info.
id = queue_update[
"queue_id"].to_int();
880 new_info.
display_name = queue_update[
"display_name"].str();
883 if(info.id == queue_update[
"queue_id"].to_int()) {
884 if(queue_update[
"action"].str() ==
"remove") {
886 }
else if(queue_update[
"action"].str() ==
"update") {
887 if(queue_update->has_attribute(
"display_name")) {
888 info.display_name = queue_update[
"display_name"].str();
890 if(queue_update->has_attribute(
"players_required")) {
891 info.players_required = queue_update[
"players_required"].to_int();
893 if(queue_update->has_attribute(
"current_players")){
894 info.current_players =
utils::split_set(queue_update[
"current_players"].str());
896 if(queue_update->has_attribute(
"addons")){
919 DBG_LB <<
"Received gamelist";
929 DBG_LB <<
"Received gamelist diff";
932 ERR_LB <<
"process_gamelist_diff failed!";
935 const int joined =
data.child_count(
"insert_child");
936 const int left =
data.child_count(
"remove_child");
937 if(joined > 0 || left > 0) {
961 if(!
game.can_join()) {
962 ERR_LB <<
"Attempted to join a game with no vacant slots";
968 if(!
game.can_observe()) {
969 ERR_LB <<
"Attempted to observe a game with observers disabled";
975 if(
game.can_join()) {
977 }
else if(
game.can_observe()) {
980 DBG_LB <<
"Cannot join or observe a game.";
999 if(
game.required_addons.empty()) {
1000 gui2::show_error_message(
_(
"Something is wrong with the addon version check database supporting the multiplayer lobby. Please report this at https://bugs.wesnoth.org."));
1004 if(!handle_addon_requirements_gui(
game.required_addons,
game.addons_outcome)) {
1015 join_data[
"id"] = std::to_string(
game.id);
1016 join_data[
"observe"] = try_obsv;
1022 }
else if(!join_data.
empty() &&
game.password_required) {
1023 std::string password;
1025 if(!gui2::dialogs::mp_join_game_password_prompt::execute(password)) {
1029 join_data[
"password"] = password;
1032 join_data[
"mp_scenario"] =
game.scenario_id;
1050 ERR_LB <<
"Attempted to join/observe a game with an invalid id: " << game_id;
1084 gui2::dialogs::preferences_dialog::display();
1100 if(!info.match_string_filter(
s)) {
1137 if(key == SDLK_RETURN || key == SDLK_KP_ENTER) {
1158 if(info->game_id != 0) {
1173 const int value = find_widget<menu_button>(
"replay_options").get_value();
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
std::map< std::string, chatroom_log > default_chat_log
A config object defines a single node in a WML file, with access to child nodes.
bool has_attribute(std::string_view key) const
config & mandatory_child(std::string_view key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
lobby_chat_window * room_window_open(const std::string &room, const bool open_new, const bool allow_close=true)
Check if a room window for "room" is open, if open_new is true then it will be created if not found.
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
lobby_chat_window * whisper_window_open(const std::string &name, bool open_new)
Check if a whisper window for user "name" is open, if open_new is true then it will be created if not...
void switch_to_window(lobby_chat_window *t)
Switch to the window given by a valid pointer (e.g.
void process_network_data(const ::config &data)
void set_active_window_changed_callback(const std::function< void(void)> &f)
void load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
void active_window_changed()
bool result_open_whisper() const
@ yes_no_buttons
Shows a yes and no button.
@ auto_close
Enables auto close.
Abstract base class for all modal dialogs.
bool show(const unsigned auto_close_time=0)
Shows the window.
void enter_selected_game(JOIN_MODE mode)
Enter game by index, where index is the selected game listbox row.
void process_gamelist(const config &data)
field_bool * filter_slots_
void update_visible_games()
void update_selected_game()
virtual void post_show() override
Actions to be taken after the window has been shown.
mp::lobby_info & lobby_info_
lobby_player_list_helper player_list_
void skip_replay_changed_callback()
static std::string announcements_
bool delay_gamelist_update_
wesnothd_connection & network_connection_
void open_match_history()
void update_gamelist_filter()
bool gamelist_diff_update_
field_bool * filter_friends_
bool delay_playerlist_update_
void process_network_data(const config &data)
widget_data make_game_row_data(const mp::game_info &game)
void select_game_by_player(const mp::user_info *info)
field_bool * filter_ignored_
void game_filter_keypress_callback(const SDL_Keycode key)
field_bool * filter_invert_
void enter_game_by_id(const int game_id, JOIN_MODE mode)
Entry wrapper for enter_game, where game is located by game id.
void update_gamelist_diff()
void show_preferences_button_callback()
static std::string server_information_
void enter_game(const mp::game_info &game, JOIN_MODE mode)
Exits the lobby and enters the given game.
bool filter_game_presets_
void user_dialog_callback(const mp::user_info *info)
void tab_switch_callback()
mp_lobby(mp::lobby_info &info, wesnothd_connection &connection, int &joined_game)
void process_gamelist_diff(const config &data)
std::size_t lobby_update_timer_
Timer for updating the lobby.
config queue_game_server_preset_
virtual void pre_show() override
Actions to be taken before showing the window.
void adjust_game_row_contents(const mp::game_info &game, grid *grid, bool add_callbacks=true)
void delete_preset(const int game_id)
std::vector< int > gamelist_id_at_row_
std::chrono::steady_clock::time_point last_lobby_update_
void network_handler()
Network polling callback.
@ RELOAD_CONFIG
player clicked the Create button
static void display(const std::string &player_name, wesnothd_connection &connection, bool wait_for_response=true)
The display function.
std::unique_ptr< plugins_context > plugins_context_
static void display(const std::string &info, const std::string &announcements)
The display function.
void register_hotkey(const hotkey::HOTKEY_COMMAND id, Func &&function)
Registers a hotkey.
T get_widget_value()
Gets the value of the field.
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
void set_row_shown(const unsigned row, const bool shown)
Makes a row visible or invisible.
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
bool select_row(const unsigned row, const bool select=true)
Selects a row.
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
void clear()
Removes all the rows in the listbox, clearing it.
int get_selected_row() const
Returns the first selected row.
unsigned get_item_count() const
Returns the number of items in the listbox.
const mp::user_info * get_selected_info() const
void update(const std::vector< mp::user_info > &user_info, int focused_game)
Updates the tree contents based on the given user data.
void set_map_data(const std::string &map_data)
std::string get_value() const
void set_enter_disabled(const bool enter_disabled)
Disable the enter key.
void set_retval(const int retval, const bool close_window=true)
Sets there return value of the window.
show_mode mode() const
Returns the dialog mode for this window.
void keyboard_capture(widget *widget)
void set_exit_hook(exit_hook mode, const Func &hook)
Sets the window's exit hook.
This class represents the collective information the client has about the players and games on the se...
void add_game_filter(game_filter_func func)
Adds a new filter function to be considered when apply_game_filter is called.
void set_game_filter_invert(std::function< bool(bool)> value)
Sets whether the result of each game filter should be inverted.
const std::vector< user_info > & users() const
bool is_game_visible(const game_info &)
Returns whether the game would be visible after the game filters are applied.
void clear_game_filters()
Clears all game filter functions.
const std::vector< game_info * > & games() const
void process_gamelist(const config &data)
Process a full game list.
bool process_gamelist_diff(const config &data)
Process a gamelist diff.
std::function< void()> begin_state_sync()
Updates the game pointer list and returns a second stage cleanup function to be called after any acti...
const boost::dynamic_bitset & games_visibility() const
game_info * get_game_by_id(int id)
Returns info on a game with the given game ID.
const config & gamelist() const
Returns the raw game list config data.
bool gamelist_initialized() const
void apply_game_filter()
Generates a new list of games that match the current filter functions and inversion setting.
void remove_game_preset(int id)
optional_const_config get_game_preset(int id)
Implements a quit confirmation dialog.
static bool quit()
Shows the quit confirmation if needed.
A class that represents a TCP/IP connection to the wesnothd server.
bool receive_data(config &result)
Receives the next pending data pack from the server, if available.
Networked add-ons (campaignd) client interface.
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed.
static std::string _(const char *str)
static lg::log_domain log_lobby("lobby")
bool ad_hoc_addon_fetch_session(const std::vector< std::string > &addon_ids)
Conducts an ad-hoc add-ons server connection to download an add-on with a particular id and all it's ...
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
bool open_object(const std::string &path_or_url)
Opens the specified object with the default application configured for its type.
const color_t YELLOW_COLOR
const color_t TITLE_COLOR
std::string escape_text(std::string_view text)
Escapes the pango markup characters in a text.
const std::string unicode_bullet
std::chrono::milliseconds lobby_refresh
std::chrono::milliseconds lobby_network_timer
std::size_t add_timer(const std::chrono::milliseconds &interval, const std::function< void(std::size_t id)> &callback, const bool repeat)
Adds a new timer.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
bool remove_timer(const std::size_t id)
Removes a timer.
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
@ OK
Dialog was closed with the OK button.
@ CANCEL
Dialog was closed with the CANCEL button.
void show_help(const std::string &show_topic)
Open the help browser.
Functions to load and save images from/to disk.
std::string italic(Args &&... data)
Applies italic Pango markup to the input.
std::string span_color(const color_t &color, Args &&... data)
Applies Pango markup to the input specifying its display color.
std::string tag(std::string_view tag, Args &&... data)
Wraps the given data in the specified tag.
std::string span_size(std::string_view size, Args &&... data)
Applies Pango markup to the input specifying its display size.
void send_to_server(const config &data)
Attempts to send given data to server if a connection is open.
std::vector< queue_info > & get_server_queues()
Gets the list of server-side queues received on login.
std::string get_profile_link(int user_id)
Gets the forum profile link for the given user.
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
std::set< std::string > split_set(std::string_view s, char sep, const int flags)
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
void erase_if(Container &container, const Predicate &predicate)
Convenience wrapper for using std::remove_if on a container.
std::vector< std::string > split(const config_attribute_value &val)
Desktop environment interaction functions.
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
The basic class for representing 8-bit RGB or RGBA colour values.
lobby_delay_gamelist_update_guard(mp_lobby &l)
~lobby_delay_gamelist_update_guard()
This class represents the info a client has about a game on the server.
std::set< std::string > required_addons
This class represents the information a client has about another player.
An error occurred during when trying to communicate with the wesnothd server.
static map_location::direction s
Contains the gui2 timer routines.