mp: Improve display of wesnothd client errors in general
Besides replacing the "End of file" error when getting disconnected from
the server under unexpected circumstances (e.g. because the server died)
with a translatable and more intuitive message, this also makes it so
other network error messages ("Connection refused", "Host not found",
etcetera) are displayed in the UI in a slightly clearer fashion, and in
an error dialog that must be dismissed with a click on a button, instead
of a transient message that can be easily missed due to an accidental
misclick.
Closes #3005.
(cherry-picked from commit c503c2ce35
)
This commit is contained in:
parent
2dca2131b6
commit
bd8176dc42
5 changed files with 38 additions and 3 deletions
|
@ -65,6 +65,7 @@
|
|||
* Removed individual Join/Observe buttons for each game in the MP Lobby.
|
||||
* Highlight the titles of MP games with vacant slots.
|
||||
* Improved MP Lobby layout on low resolutions.
|
||||
* Improved reporting of network errors in the MP lobby (issue #3005).
|
||||
### WML engine
|
||||
* Support formula= key in [variable] ConditionalWML
|
||||
* Support to_location in [move_unit], taking a location ID
|
||||
|
|
|
@ -12,6 +12,7 @@ changelog: https://github.com/wesnoth/wesnoth/blob/master/changelog.md
|
|||
Spanish, Ukrainian.
|
||||
### User Interface
|
||||
* Implemented MP chat message history saving (issue #1194, issue #2802).
|
||||
* Improved reporting of network errors in the MP lobby (issue #3005).
|
||||
### Miscellaneous and bug fixes
|
||||
* Fixed minimap buttons not doing anything (bug #2681)
|
||||
* Fixed some hotkeys triggering multiple commands on GNU/Linux (bug #1736)
|
||||
|
|
|
@ -867,7 +867,26 @@ bool game_launcher::play_multiplayer(mp_selection res)
|
|||
} catch(wesnothd_error& e) {
|
||||
if(!e.message.empty()) {
|
||||
ERR_NET << "caught network error: " << e.message << std::endl;
|
||||
gui2::show_transient_message("", translation::gettext(e.message.c_str()));
|
||||
|
||||
std::string user_msg;
|
||||
auto conn_err = dynamic_cast<wesnothd_connection_error*>(&e);
|
||||
|
||||
if(conn_err) {
|
||||
// The wesnothd_connection_error subclass is only thrown with messages
|
||||
// from boost::system::error_code which we can't translate ourselves.
|
||||
// It's also the originator of the infamous EOF error that happens when
|
||||
// the server dies. <https://github.com/wesnoth/wesnoth/issues/3005>. It
|
||||
// will provide a translated string instead of that when it happens.
|
||||
user_msg = !conn_err->user_message.empty()
|
||||
? conn_err->user_message
|
||||
: _("Connection failed: ") + e.message;
|
||||
} else {
|
||||
// This will be a message from the server itself, which we can
|
||||
// probably translate.
|
||||
user_msg = translation::gettext(e.message.c_str());
|
||||
}
|
||||
|
||||
gui2::show_error_message(user_msg);
|
||||
} else {
|
||||
ERR_NET << "caught network error" << std::endl;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "wesnothd_connection.hpp"
|
||||
|
||||
#include "gui/dialogs/loading_screen.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "log.hpp"
|
||||
#include "serialization/parser.hpp"
|
||||
#include "utils/functional.hpp"
|
||||
|
@ -396,7 +397,13 @@ bool wesnothd_connection::receive_data(config& result)
|
|||
{
|
||||
std::lock_guard<std::mutex> lock(last_error_mutex_);
|
||||
if(last_error_) {
|
||||
throw error(last_error_);
|
||||
std::string user_msg;
|
||||
|
||||
if(last_error_ == boost::asio::error::eof) {
|
||||
user_msg = _("Disconnected from server.");
|
||||
}
|
||||
|
||||
throw error(last_error_, user_msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,13 @@ struct ingame_wesnothd_error : public wesnothd_error ,public lua_jailbreak_excep
|
|||
///TODO: find a short name
|
||||
struct wesnothd_connection_error : public wesnothd_error ,public lua_jailbreak_exception
|
||||
{
|
||||
wesnothd_connection_error(const boost::system::error_code& error) : wesnothd_error(error.message()) {}
|
||||
wesnothd_connection_error(const boost::system::error_code& error, const std::string& msg = "")
|
||||
: wesnothd_error(error.message())
|
||||
, user_message(msg)
|
||||
{}
|
||||
|
||||
/** User-friendly and potentially translated message for use in the UI. */
|
||||
std::string user_message;
|
||||
|
||||
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(wesnothd_connection_error)
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue