diff --git a/src/game_initialization/multiplayer.cpp b/src/game_initialization/multiplayer.cpp index a11359b195685..884be912331af 100644 --- a/src/game_initialization/multiplayer.cpp +++ b/src/game_initialization/multiplayer.cpp @@ -24,7 +24,6 @@ #include "gettext.hpp" #include "gui/dialogs/message.hpp" #include "gui/dialogs/multiplayer/lobby.hpp" -#include "gui/dialogs/multiplayer/mp_connect.hpp" #include "gui/dialogs/multiplayer/mp_create_game.hpp" #include "gui/dialogs/multiplayer/mp_join_game.hpp" #include "gui/dialogs/multiplayer/mp_login.hpp" @@ -48,34 +47,24 @@ static lg::log_domain log_mp("mp/main"); #define DBG_MP LOG_STREAM(debug, log_mp) /** Opens a new server connection and prompts the client for login credentials, if necessary. */ -static wesnothd_connection_ptr open_connection(CVideo& video, const std::string& original_host) +static wesnothd_connection_ptr open_connection(CVideo& video, std::string host) { DBG_MP << "opening connection" << std::endl; - std::string h = original_host; - if(h.empty()) { - gui2::dialogs::mp_connect dlg; - dlg.show(video); - - if(dlg.get_retval() != gui2::window::OK) { - return wesnothd_connection_ptr(); - } + wesnothd_connection_ptr sock; - h = preferences::network_host(); + if(host.empty()) { + return sock; } - wesnothd_connection_ptr sock; - - const int colon_index = h.find_first_of(":"); - std::string host; + const int colon_index = host.find_first_of(":"); unsigned int port; if(colon_index == -1) { - host = h; port = 15000; } else { - host = h.substr(0, colon_index); - port = lexical_cast_default(h.substr(colon_index + 1), 15000); + port = lexical_cast_default(host.substr(colon_index + 1), 15000); + host = host.substr(0, colon_index); } // shown_hosts is used to prevent the client being locked in a redirect loop. @@ -315,10 +304,6 @@ static wesnothd_connection_ptr open_connection(CVideo& video, const std::string& } // end login loop } while(!(data.child("join_lobby") || data.child("join_game"))); - if(h != preferences::server_list().front().address) { - preferences::set_network_host(h); - } - if(data.child("join_lobby")) { return sock; } diff --git a/src/game_launcher.cpp b/src/game_launcher.cpp index 14c543ce65d32..7f33570a3a627 100644 --- a/src/game_launcher.cpp +++ b/src/game_launcher.cpp @@ -31,6 +31,7 @@ #include "gui/dialogs/language_selection.hpp" // for language_selection #include "gui/dialogs/loading_screen.hpp" #include "gui/dialogs/message.hpp" //for show error message +#include "gui/dialogs/multiplayer/mp_connect.hpp" #include "gui/dialogs/multiplayer/mp_host_game_prompt.hpp" //for host game prompt #include "gui/dialogs/multiplayer/mp_method_selection.hpp" #include "gui/dialogs/outro.hpp" @@ -826,6 +827,21 @@ bool game_launcher::play_multiplayer(mp_selection res) } + + // If a server address wasn't specified, prompt for it now. + if(multiplayer_server_.empty()) { + if(!gui2::dialogs::mp_connect::execute(CVideo::get_singleton())) { + return false; + } + + // The prompt saves its input to preferences. + multiplayer_server_ = preferences::network_host(); + + if(multiplayer_server_ != preferences::server_list().front().address) { + preferences::set_network_host(multiplayer_server_); + } + } + //create_engine already calls game_config_manager::get()->load_config but maybe its better to have MULTIPLAYER defined while we are in the lobby. game_config_manager::get()->load_game_config_for_create(true); diff --git a/src/gui/dialogs/multiplayer/mp_connect.hpp b/src/gui/dialogs/multiplayer/mp_connect.hpp index fc349bbc7066b..cc52f69046e1d 100644 --- a/src/gui/dialogs/multiplayer/mp_connect.hpp +++ b/src/gui/dialogs/multiplayer/mp_connect.hpp @@ -29,6 +29,12 @@ class mp_connect : public modal_dialog public: mp_connect(); + /** The execute function. See @ref modal_dialog for more information. */ + static bool execute(CVideo& video) + { + return mp_connect().show(video); + } + private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ virtual const std::string& window_id() const override;