remove uses of network::error and fix gui2 mp lobby
This commit is contained in:
parent
a6b114f6ae
commit
dca57bd5b0
26 changed files with 104 additions and 127 deletions
|
@ -1049,9 +1049,6 @@ bool addons_manager_ui(CVideo& v, const std::string& remote_address)
|
|||
} catch(const config::error& e) {
|
||||
ERR_CFG << "config::error thrown during transaction with add-on server; \""<< e.message << "\"" << std::endl;
|
||||
gui2::show_error_message(v, _("Network communication error."));
|
||||
} catch(const network::error& e) {
|
||||
ERR_NET << "network::error thrown during transaction with add-on server; \""<< e.message << "\"" << std::endl;
|
||||
gui2::show_error_message(v, _("Remote host disconnected."));
|
||||
} catch(const network_asio::error& e) {
|
||||
ERR_NET << "network_asio::error thrown during transaction with add-on server; \""<< e.what() << "\"" << std::endl;
|
||||
gui2::show_error_message(v, _("Remote host disconnected."));
|
||||
|
@ -1262,9 +1259,6 @@ bool ad_hoc_addon_fetch_session(CVideo& v, const std::vector<std::string>& addon
|
|||
} catch(const config::error& e) {
|
||||
ERR_CFG << "config::error thrown during transaction with add-on server; \""<< e.message << "\"" << std::endl;
|
||||
gui2::show_error_message(v, _("Network communication error."));
|
||||
} catch(const network::error& e) {
|
||||
ERR_NET << "network::error thrown during transaction with add-on server; \""<< e.message << "\"" << std::endl;
|
||||
gui2::show_error_message(v, _("Remote host disconnected."));
|
||||
} catch(const network_asio::error& e) {
|
||||
ERR_NET << "network_asio::error thrown during transaction with add-on server; \""<< e.what() << "\"" << std::endl;
|
||||
gui2::show_error_message(v, _("Remote host disconnected."));
|
||||
|
|
|
@ -25,10 +25,10 @@ class terrain_type;
|
|||
class twesnothd_connection;
|
||||
#include "map/location.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "network.hpp"
|
||||
#include "units/ptr.hpp"
|
||||
#include "ai/lua/aspect_advancements.hpp"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
namespace dialogs {
|
||||
|
||||
|
||||
|
|
|
@ -760,13 +760,6 @@ std::pair<bool, bool> connect_engine::process_network_data(const config& data)
|
|||
return result;
|
||||
}
|
||||
|
||||
void connect_engine::process_network_error(network::error& error)
|
||||
{
|
||||
// The problem isn't related to any specific connection and
|
||||
// it's a general error. So we should just re-throw the error.
|
||||
throw network::error(error.message);
|
||||
}
|
||||
|
||||
int connect_engine::find_user_side_index_by_id(const std::string& id) const
|
||||
{
|
||||
size_t i = 0;
|
||||
|
|
|
@ -75,7 +75,6 @@ public:
|
|||
// Return pair first element specifies whether to leave the game
|
||||
// and second element whether to silently update UI.
|
||||
std::pair<bool, bool> process_network_data(const config& data);
|
||||
void process_network_error(network::error& error);
|
||||
|
||||
// Returns the side which is taken by a given user,
|
||||
// or -1 if none was found.
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "mp_options.hpp"
|
||||
#include "savegame.hpp"
|
||||
#include "units/id.hpp"
|
||||
#include "wesnothd_connection_error.hpp"
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
|
@ -131,11 +132,11 @@ void level_to_gamestate(const config& level, saved_game& state)
|
|||
void check_response(bool res, const config& data)
|
||||
{
|
||||
if (!res) {
|
||||
throw network::error(_("Connection timed out"));
|
||||
throw wesnothd_error(_("Connection timed out"));
|
||||
}
|
||||
|
||||
if (const config& err = data.child("error")) {
|
||||
throw network::error(err["message"]);
|
||||
throw wesnothd_error(err["message"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#define MP_GAME_UTILS_HPP_INCLUDED
|
||||
|
||||
#include "mp_game_settings.hpp"
|
||||
#include "network.hpp"
|
||||
|
||||
class config;
|
||||
class saved_game;
|
||||
|
|
|
@ -168,7 +168,7 @@ static std::unique_ptr<twesnothd_connection> open_connection(CVideo& video, cons
|
|||
i18n_symbols["version1"] = version;
|
||||
i18n_symbols["version2"] = game_config::version;
|
||||
const std::string errorstring = vgettext("The server accepts versions '$version1' while you are using version '$version2'", i18n_symbols);
|
||||
throw network::error(errorstring);
|
||||
throw wesnothd_error(errorstring);
|
||||
}
|
||||
|
||||
// Check for "redirect" messages
|
||||
|
@ -178,7 +178,7 @@ static std::unique_ptr<twesnothd_connection> open_connection(CVideo& video, cons
|
|||
port =redirect["port"].to_int(15000);
|
||||
|
||||
if(shown_hosts.find(hostpair(host,port)) != shown_hosts.end()) {
|
||||
throw network::error(_("Server-side redirect loop"));
|
||||
throw wesnothd_error(_("Server-side redirect loop"));
|
||||
}
|
||||
shown_hosts.insert(hostpair(host, port));
|
||||
sock.release();
|
||||
|
@ -284,7 +284,7 @@ static std::unique_ptr<twesnothd_connection> open_connection(CVideo& video, cons
|
|||
const std::string salt = (*error)["salt"];
|
||||
|
||||
if (salt.length() < 12) {
|
||||
throw network::error(_("Bad data received from server"));
|
||||
throw wesnothd_error(_("Bad data received from server"));
|
||||
}
|
||||
|
||||
sp["password"] = util::create_hash(util::create_hash(password, util::get_salt(salt),
|
||||
|
@ -641,7 +641,7 @@ static void enter_lobby_mode(CVideo& video, const config& game_config,
|
|||
sound::empty_playlist();
|
||||
sound::stop_music();
|
||||
}
|
||||
lobby_info li(game_config);
|
||||
lobby_info li(game_config, *wesnothd_connection);
|
||||
|
||||
// Force a black background
|
||||
const Uint32 color = SDL_MapRGBA(video.getSurface()->format
|
||||
|
@ -653,7 +653,7 @@ static void enter_lobby_mode(CVideo& video, const config& game_config,
|
|||
sdl::fill_rect(video.getSurface(), nullptr, color);
|
||||
|
||||
if(preferences::new_lobby()) {
|
||||
gui2::tlobby_main dlg(game_config, li, video);
|
||||
gui2::tlobby_main dlg(game_config, li, video, *wesnothd_connection);
|
||||
dlg.set_preferences_callback(
|
||||
std::bind(do_preferences_dialog,
|
||||
std::ref(video), std::ref(game_config)));
|
||||
|
|
|
@ -582,11 +582,6 @@ void connect::process_network_data(const config& data)
|
|||
}
|
||||
}
|
||||
|
||||
void connect::process_network_error(network::error& error)
|
||||
{
|
||||
engine_.process_network_error(error);
|
||||
}
|
||||
|
||||
void connect::update_playerlist_state(bool silent)
|
||||
{
|
||||
DBG_MP << "updating player list state" << std::endl;
|
||||
|
|
|
@ -110,7 +110,6 @@ protected:
|
|||
virtual void hide_children(bool hide = true);
|
||||
|
||||
virtual void process_network_data(const config& data);
|
||||
virtual void process_network_error(network::error& error);
|
||||
|
||||
private:
|
||||
connect(const connect&);
|
||||
|
|
|
@ -217,12 +217,8 @@ ui::ui(CVideo& video, twesnothd_connection* wesnothd_connection, const std::stri
|
|||
void ui::process_network()
|
||||
{
|
||||
config data;
|
||||
try {
|
||||
if(receive_from_server(data)) {
|
||||
process_network_data(data);
|
||||
}
|
||||
} catch(network::error& e) {
|
||||
process_network_error(e);
|
||||
if(receive_from_server(data)) {
|
||||
process_network_data(data);
|
||||
}
|
||||
|
||||
//apply diffs at a set interval
|
||||
|
@ -517,7 +513,7 @@ void ui::process_message(const config& msg, const bool whisper) {
|
|||
void ui::process_network_data(const config& data)
|
||||
{
|
||||
if (const config &c = data.child("error")) {
|
||||
throw network::error(c["message"]);
|
||||
throw wesnothd_error(c["message"]);
|
||||
} else if (const config &c = data.child("message")) {
|
||||
process_message(c);
|
||||
} else if (const config &c = data.child("whisper")) {
|
||||
|
@ -580,14 +576,6 @@ void ui::process_network_data(const config& data)
|
|||
}
|
||||
}
|
||||
|
||||
void ui::process_network_error(network::error& error)
|
||||
{
|
||||
ERR_NW << "Caught networking error: " << error.message << std::endl;
|
||||
|
||||
// Default behavior is to re-throw the error. May be overridden.
|
||||
throw error;
|
||||
}
|
||||
|
||||
void ui::hide_children(bool hide)
|
||||
{
|
||||
title_.hide(hide);
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "chat_events.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "hotkey/command_executor.hpp"
|
||||
#include "network.hpp"
|
||||
#include "preferences_display.hpp"
|
||||
#include "scripting/plugins/context.hpp"
|
||||
#include "widgets/combo.hpp"
|
||||
|
@ -149,12 +148,6 @@ protected:
|
|||
*/
|
||||
virtual void process_network_data(const config& data);
|
||||
|
||||
/**
|
||||
* Processes any pending network error. Called by the public
|
||||
* process_network() method. Overridden by subclasses.
|
||||
*/
|
||||
virtual void process_network_error(network::error& error);
|
||||
|
||||
/**
|
||||
* Hides or shows all gui::widget children of this widget. Should be
|
||||
* overridden by subclasses which add their own children.
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
#include "tstring.hpp" // for operator==, operator!=
|
||||
#include "util.hpp" // for lexical_cast_default
|
||||
#include "video.hpp" // for CVideo
|
||||
#include "wesnothd_connection_error.hpp"
|
||||
#include "wml_exception.hpp" // for twml_exception
|
||||
|
||||
#include <algorithm> // for copy, max, min, stable_sort
|
||||
|
@ -925,14 +926,14 @@ bool game_launcher::play_multiplayer()
|
|||
gui2::show_error_message(video(), _("Error while playing the game: ") + e.message);
|
||||
} catch (mapgen_exception& e) {
|
||||
gui2::show_error_message(video(), std::string(_("Map generator error: ") + e.message));
|
||||
} catch(network::error& e) {
|
||||
} catch(wesnothd_error& e) {
|
||||
if(e.message != "") {
|
||||
ERR_NET << "caught network::error: " << e.message << std::endl;
|
||||
ERR_NET << "caught network error: " << e.message << std::endl;
|
||||
gui2::show_transient_message(video()
|
||||
, ""
|
||||
, translation::gettext(e.message.c_str()));
|
||||
} else {
|
||||
ERR_NET << "caught network::error" << std::endl;
|
||||
ERR_NET << "caught network error" << std::endl;
|
||||
}
|
||||
} catch(config::error& e) {
|
||||
if(e.message != "") {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "gettext.hpp"
|
||||
#include "log.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "network.hpp" // ping_timeout
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "serialization/unicode_cast.hpp"
|
||||
#include "settings.hpp"
|
||||
|
@ -168,7 +167,7 @@ manager::manager() :
|
|||
}
|
||||
}
|
||||
|
||||
network::ping_timeout = get_ping_timeout();
|
||||
//network::ping_timeout = get_ping_timeout();
|
||||
}
|
||||
|
||||
manager::~manager()
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "filesystem.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "network.hpp"
|
||||
#include "log.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "map/exception.hpp"
|
||||
|
|
|
@ -18,12 +18,11 @@
|
|||
#include "game_preferences.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "network.hpp"
|
||||
#include "log.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "map/exception.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
#include "wesnothd_connection.hpp"
|
||||
#include <iterator>
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
|
@ -39,7 +38,7 @@ static lg::log_domain log_lobby("lobby");
|
|||
#define SCOPE_LB log_scope2(log_lobby, __func__)
|
||||
|
||||
|
||||
lobby_info::lobby_info(const config& game_config)
|
||||
lobby_info::lobby_info(const config& game_config, twesnothd_connection& wesnothd_connection)
|
||||
: game_config_(game_config)
|
||||
, gamelist_()
|
||||
, gamelist_initialized_(false)
|
||||
|
@ -53,6 +52,7 @@ lobby_info::lobby_info(const config& game_config)
|
|||
, game_filter_()
|
||||
, game_filter_invert_(false)
|
||||
, games_visibility_()
|
||||
, wesnothd_connection_(wesnothd_connection)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ bool lobby_info::process_gamelist_diff(const config& data)
|
|||
{
|
||||
ERR_LB << "Error while applying the gamelist diff: '" << e.message
|
||||
<< "' Getting a new gamelist.\n";
|
||||
network::send_data(config("refresh_lobby"), 0);
|
||||
wesnothd_connection_.send_data(config("refresh_lobby"));
|
||||
return false;
|
||||
}
|
||||
DBG_LB << "postdiff " << dump_games_config(gamelist_.child("gamelist"));
|
||||
|
@ -144,7 +144,7 @@ bool lobby_info::process_gamelist_diff(const config& data)
|
|||
int game_id = c["id"];
|
||||
if(game_id == 0) {
|
||||
ERR_LB << "game with id 0 in gamelist config" << std::endl;
|
||||
network::send_data(config("refresh_lobby"), 0);
|
||||
wesnothd_connection_.send_data(config("refresh_lobby"));
|
||||
return false;
|
||||
}
|
||||
game_info_map::iterator current_i = games_by_id_.find(game_id);
|
||||
|
@ -183,7 +183,7 @@ bool lobby_info::process_gamelist_diff(const config& data)
|
|||
{
|
||||
ERR_LB << "Error while applying the gamelist diff (2): '" << e.message
|
||||
<< "' Getting a new gamelist.\n";
|
||||
network::send_data(config("refresh_lobby"), 0);
|
||||
wesnothd_connection_.send_data(config("refresh_lobby"));
|
||||
return false;
|
||||
}
|
||||
DBG_LB << "postclean " << dump_games_config(gamelist_.child("gamelist"));
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "config.hpp"
|
||||
#include "gui/dialogs/lobby/data.hpp"
|
||||
|
||||
class twesnothd_connection;
|
||||
/**
|
||||
* This class represents the collective information the client has
|
||||
* about the players and games on the server
|
||||
|
@ -25,7 +25,7 @@
|
|||
class lobby_info
|
||||
{
|
||||
public:
|
||||
explicit lobby_info(const config& game_config);
|
||||
explicit lobby_info(const config& game_config, twesnothd_connection&);
|
||||
|
||||
~lobby_info();
|
||||
|
||||
|
@ -113,6 +113,7 @@ private:
|
|||
game_filter_and_stack game_filter_;
|
||||
bool game_filter_invert_;
|
||||
std::vector<bool> games_visibility_;
|
||||
twesnothd_connection& wesnothd_connection_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include "gettext.hpp"
|
||||
#include "lobby_preferences.hpp"
|
||||
#include "log.hpp"
|
||||
#include "network.hpp"
|
||||
#include "wesnothd_connection.hpp"
|
||||
#include "playmp_controller.hpp"
|
||||
#include "mp_ui_alerts.hpp"
|
||||
|
||||
|
@ -173,7 +173,7 @@ void tlobby_main::send_chat_message(const std::string& message,
|
|||
|
||||
add_chat_message(time(nullptr), preferences::login(), 0, message); // local
|
||||
// echo
|
||||
network::send_data(data, 0);
|
||||
wesnothd_connection_.send_data(data);
|
||||
}
|
||||
|
||||
void tlobby_main::user_relation_changed(const std::string& /*name*/)
|
||||
|
@ -338,7 +338,7 @@ void tlobby_main::do_notify(t_notify_mode mode, const std::string & sender, cons
|
|||
|
||||
tlobby_main::tlobby_main(const config& game_config,
|
||||
lobby_info& info,
|
||||
CVideo& video)
|
||||
CVideo& video, twesnothd_connection &wesnothd_connection)
|
||||
: legacy_result_(QUIT)
|
||||
, game_config_(game_config)
|
||||
, gamelistbox_(nullptr)
|
||||
|
@ -363,6 +363,7 @@ tlobby_main::tlobby_main(const config& game_config,
|
|||
, last_gamelist_update_(0)
|
||||
, gamelist_diff_update_(true)
|
||||
, video_(video)
|
||||
, wesnothd_connection_(wesnothd_connection)
|
||||
, lobby_update_timer_(0)
|
||||
, preferences_wrapper_()
|
||||
, gamelist_id_at_row_()
|
||||
|
@ -552,7 +553,7 @@ void tlobby_main::update_gamelist_diff()
|
|||
if(list_i >= gamelistbox_->get_item_count()) {
|
||||
ERR_LB << "Ran out of listbox items -- triggering a full "
|
||||
"refresh\n";
|
||||
network::send_data(config("refresh_lobby"), 0);
|
||||
wesnothd_connection_.send_data(config("refresh_lobby"));
|
||||
return;
|
||||
}
|
||||
if(list_i + list_rows_deleted >= gamelist_id_at_row_.size()) {
|
||||
|
@ -560,7 +561,7 @@ void tlobby_main::update_gamelist_diff()
|
|||
<< list_rows_deleted
|
||||
<< " >= " << gamelist_id_at_row_.size()
|
||||
<< " -- triggering a full refresh\n";
|
||||
network::send_data(config("refresh_lobby"), 0);
|
||||
wesnothd_connection_.send_data(config("refresh_lobby"));
|
||||
return;
|
||||
}
|
||||
int listbox_game_id
|
||||
|
@ -569,7 +570,7 @@ void tlobby_main::update_gamelist_diff()
|
|||
ERR_LB << "Listbox game id does not match expected id "
|
||||
<< listbox_game_id << " " << game.id << " (row "
|
||||
<< list_i << ")\n";
|
||||
network::send_data(config("refresh_lobby"), 0);
|
||||
wesnothd_connection_.send_data(config("refresh_lobby"));
|
||||
return;
|
||||
}
|
||||
if(game.display_status == game_info::UPDATED) {
|
||||
|
@ -1252,7 +1253,7 @@ void tlobby_main::close_window(size_t idx)
|
|||
msg["room"] = t.name;
|
||||
msg["player"] = preferences::login();
|
||||
data.add_child("room_part", msg);
|
||||
network::send_data(data, 0);
|
||||
wesnothd_connection_.send_data(data);
|
||||
}
|
||||
if(active_window_ == open_windows_.size() - 1) {
|
||||
active_window_--;
|
||||
|
@ -1290,14 +1291,13 @@ void tlobby_main::network_handler()
|
|||
try
|
||||
{
|
||||
config data;
|
||||
const network::connection sock = network::receive_data(data);
|
||||
if(sock) {
|
||||
if(wesnothd_connection_.receive_data(data)) {
|
||||
process_network_data(data);
|
||||
}
|
||||
}
|
||||
catch(network::error& e)
|
||||
catch(wesnothd_error& e)
|
||||
{
|
||||
LOG_LB << "caught network::error in network_handler: " << e.message
|
||||
LOG_LB << "caught wesnothd_error in network_handler: " << e.message
|
||||
<< "\n";
|
||||
throw;
|
||||
}
|
||||
|
@ -1306,7 +1306,7 @@ void tlobby_main::network_handler()
|
|||
void tlobby_main::process_network_data(const config& data)
|
||||
{
|
||||
if(const config& c = data.child("error")) {
|
||||
throw network::error(c["message"]);
|
||||
throw wesnothd_error(c["message"]);
|
||||
} else if(const config& c = data.child("message")) {
|
||||
process_message(c);
|
||||
} else if(const config& c = data.child("whisper")) {
|
||||
|
@ -1556,7 +1556,7 @@ bool tlobby_main::do_game_join(int idx, bool observe)
|
|||
|
||||
join["password"] = password;
|
||||
}
|
||||
network::send_data(response, 0);
|
||||
wesnothd_connection_.send_data(response);
|
||||
if(observe && game.started) {
|
||||
// playmp_controller::set_replay_last_turn(game.current_turn);
|
||||
}
|
||||
|
@ -1606,7 +1606,7 @@ void tlobby_main::create_button_callback(gui2::twindow& window)
|
|||
|
||||
void tlobby_main::refresh_button_callback(gui2::twindow& /*window*/)
|
||||
{
|
||||
network::send_data(config("refresh_lobby"), 0);
|
||||
wesnothd_connection_.send_data(config("refresh_lobby"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1622,7 +1622,7 @@ void tlobby_main::show_preferences_button_callback(gui2::twindow& window)
|
|||
*/
|
||||
window.invalidate_layout();
|
||||
|
||||
network::send_data(config("refresh_lobby"), 0);
|
||||
wesnothd_connection_.send_data(config("refresh_lobby"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1757,7 +1757,7 @@ void tlobby_main::user_dialog_callback(user_info* info)
|
|||
// update_gamelist();
|
||||
delay_playerlist_update_ = false;
|
||||
player_list_dirty_ = true;
|
||||
network::send_data(config("refresh_lobby"), 0);
|
||||
wesnothd_connection_.send_data(config("refresh_lobby"));
|
||||
}
|
||||
|
||||
void tlobby_main::skip_replay_changed_callback(twidget& w)
|
||||
|
@ -1767,7 +1767,7 @@ void tlobby_main::skip_replay_changed_callback(twidget& w)
|
|||
}
|
||||
void tlobby_main::send_to_server(const config& cfg)
|
||||
{
|
||||
network::send_data(cfg, 0);
|
||||
wesnothd_connection_.send_data(cfg);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -27,6 +27,7 @@ class display;
|
|||
#ifdef GUI2_EXPERIMENTAL_LISTBOX
|
||||
#include "gui/widgets/list.hpp"
|
||||
#endif
|
||||
class twesnothd_connection;
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
|
@ -84,7 +85,7 @@ struct tplayer_list
|
|||
class tlobby_main : public tdialog, private events::chat_handler
|
||||
{
|
||||
public:
|
||||
tlobby_main(const config& game_config, lobby_info& info, CVideo& video);
|
||||
tlobby_main(const config& game_config, lobby_info& info, CVideo& video, twesnothd_connection &wesnothd_connection);
|
||||
|
||||
~tlobby_main();
|
||||
|
||||
|
@ -417,6 +418,8 @@ private:
|
|||
|
||||
CVideo& video_;
|
||||
|
||||
twesnothd_connection &wesnothd_connection_;
|
||||
|
||||
/** Timer for updating the lobby. */
|
||||
size_t lobby_update_timer_;
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ void playmp_controller::linger()
|
|||
LOG_NG << "caught load-game-exception" << std::endl;
|
||||
// this should not happen, the option to load a game is disabled
|
||||
throw;
|
||||
} catch (network::error&) {
|
||||
} catch (ingame_wesnothd_error&) {
|
||||
LOG_NG << "caught network-error-exception" << std::endl;
|
||||
quit = false;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include "units/unit.hpp"
|
||||
#include "units/animation.hpp"
|
||||
#include "util.hpp"
|
||||
#include "wesnothd_connection_error.hpp"
|
||||
#include "whiteboard/manager.hpp"
|
||||
#include "hotkey/hotkey_item.hpp"
|
||||
|
||||
|
@ -325,20 +326,15 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
|||
saved_game_ = saved_game();
|
||||
}
|
||||
throw;
|
||||
} catch(network::error& e) {
|
||||
bool disconnect = false;
|
||||
if(e.socket) {
|
||||
e.disconnect();
|
||||
disconnect = true;
|
||||
}
|
||||
} catch(wesnothd_error& e) {
|
||||
|
||||
scoped_savegame_snapshot snapshot(*this);
|
||||
savegame::ingame_savegame save(saved_game_, *gui_, preferences::save_compression_format());
|
||||
save.save_game_interactive(gui_->video(), _("A network disconnection has occurred, and the game cannot continue. Do you want to save the game?"), gui::YES_NO);
|
||||
if(disconnect) {
|
||||
throw network::error();
|
||||
} else {
|
||||
if(dynamic_cast<ingame_wesnothd_error*>(&e)) {
|
||||
return LEVEL_RESULT::QUIT;
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "log.hpp" // for LOG_STREAM, logger, etc
|
||||
#include "utils/make_enum.hpp" // for bad_enum_cast
|
||||
#include "map/label.hpp"
|
||||
#include "network.hpp" // for error
|
||||
#include "play_controller.hpp" // for play_controller
|
||||
#include "playturn_network_adapter.hpp" // for playturn_network_adapter
|
||||
#include "preferences.hpp" // for message_bell
|
||||
|
@ -38,6 +37,7 @@
|
|||
#include "team.hpp" // for team, team::CONTROLLER::AI, etc
|
||||
#include "tstring.hpp" // for operator==
|
||||
#include "util.hpp" // for lexical_cast
|
||||
#include "wesnothd_connection_error.hpp"
|
||||
#include "whiteboard/manager.hpp" // for manager
|
||||
#include "widgets/button.hpp" // for button
|
||||
|
||||
|
@ -155,7 +155,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
|
|||
resources::screen->get_chat_manager().remove_observer(ob["name"]);
|
||||
}
|
||||
else if (cfg.child("leave_game")) {
|
||||
throw network::error("");
|
||||
throw ingame_wesnothd_error("");
|
||||
}
|
||||
else if (const config &turn = cfg.child("turn"))
|
||||
{
|
||||
|
@ -217,13 +217,13 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
|
|||
|
||||
if (index >= resources::teams->size()) {
|
||||
ERR_NW << "unknown side " << side_drop << " is dropping game" << std::endl;
|
||||
throw network::error("");
|
||||
throw ingame_wesnothd_error("");
|
||||
}
|
||||
|
||||
team::CONTROLLER ctrl;
|
||||
if(!ctrl.parse(side_drop_c["controller"])) {
|
||||
ERR_NW << "unknown controller type issued from server on side drop: " << side_drop_c["controller"] << std::endl;
|
||||
throw network::error("");
|
||||
throw ingame_wesnothd_error("");
|
||||
}
|
||||
|
||||
if (ctrl == team::CONTROLLER::AI) {
|
||||
|
@ -233,7 +233,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
|
|||
//null controlled side cannot be dropped becasue they aren't controlled by anyone.
|
||||
else if (ctrl != team::CONTROLLER::HUMAN) {
|
||||
ERR_NW << "unknown controller type issued from server on side drop: " << ctrl.to_cstring() << std::endl;
|
||||
throw network::error("");
|
||||
throw ingame_wesnothd_error("");
|
||||
}
|
||||
|
||||
int action = 0;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "playturn_network_adapter.hpp"
|
||||
#include "network.hpp"
|
||||
#include "config_assign.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "synced_checkup.hpp"
|
||||
#include "game_data.hpp"
|
||||
#include "game_board.hpp"
|
||||
#include "network.hpp"
|
||||
#include "log.hpp"
|
||||
#include "lua_jailbreak_exception.hpp"
|
||||
#include "play_controller.hpp"
|
||||
|
@ -246,29 +245,9 @@ int synced_context::get_unit_id_diff()
|
|||
return resources::gameboard->unit_id_manager().get_save_id() - last_unit_id_;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class lua_network_error : public network::error , public tlua_jailbreak_exception
|
||||
{
|
||||
public:
|
||||
lua_network_error(network::error base)
|
||||
: network::error(base), tlua_jailbreak_exception()
|
||||
{}
|
||||
private:
|
||||
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(lua_network_error)
|
||||
};
|
||||
}
|
||||
|
||||
void synced_context::pull_remote_user_input()
|
||||
{
|
||||
try{
|
||||
syncmp_registry::pull_remote_choice();
|
||||
}
|
||||
catch(network::error& err)
|
||||
{
|
||||
throw lua_network_error(err);
|
||||
}
|
||||
|
||||
syncmp_registry::pull_remote_choice();
|
||||
}
|
||||
|
||||
void synced_context::send_user_choice()
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include "help/help.hpp" // for help_manager
|
||||
#include "image.hpp" // for flush_cache, etc
|
||||
#include "log.hpp" // for LOG_STREAM, general, logger, etc
|
||||
#include "network.hpp" // for describe_versions
|
||||
#include "preferences.hpp" // for core_id, etc
|
||||
#include "scripting/application_lua_kernel.hpp"
|
||||
#include "scripting/plugins/context.hpp"
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <deque>
|
||||
#include <list>
|
||||
#include "exceptions.hpp"
|
||||
#include "wesnothd_connection_error.hpp"
|
||||
|
||||
class config;
|
||||
|
||||
|
@ -39,11 +40,7 @@ class config;
|
|||
class twesnothd_connection : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
struct error : public game::error
|
||||
{
|
||||
error(const boost::system::error_code& error) : game::error(error.message()) {}
|
||||
};
|
||||
using error = wesnothd_connection_error;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
43
src/wesnothd_connection_error.hpp
Normal file
43
src/wesnothd_connection_error.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
Copyright (C) 2011 - 2016 by Sergey Popov <loonycyborg@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include "exceptions.hpp"
|
||||
#include "lua_jailbreak_exception.hpp"
|
||||
///An error occured during when trying to coommunicate with the wesnothd server.
|
||||
struct wesnothd_error : public game::error
|
||||
{
|
||||
wesnothd_error(const std::string& error) : game::error(error) {}
|
||||
};
|
||||
|
||||
///We received invalid data from wesnothd during a game
|
||||
///This means we cannot continue with the game but we can stay connected to wesnothd and start a new game
|
||||
///TODO: find a short name
|
||||
struct ingame_wesnothd_error : public wesnothd_error ,public tlua_jailbreak_exception
|
||||
{
|
||||
ingame_wesnothd_error(const std::string& error) : wesnothd_error(error) {}
|
||||
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(ingame_wesnothd_error)
|
||||
};
|
||||
|
||||
|
||||
///an error occured inside the underlying network comminication code (boost asio)
|
||||
///TODO: find a short name
|
||||
struct wesnothd_connection_error : public wesnothd_error ,public tlua_jailbreak_exception
|
||||
{
|
||||
wesnothd_connection_error(const boost::system::error_code& error) : wesnothd_error(error.message()) {}
|
||||
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(wesnothd_connection_error)
|
||||
};
|
||||
|
Loading…
Add table
Reference in a new issue