diff --git a/src/addon/manager_ui.cpp b/src/addon/manager_ui.cpp index 672022a0cadc..e310f0934bb7 100644 --- a/src/addon/manager_ui.cpp +++ b/src/addon/manager_ui.cpp @@ -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& 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.")); diff --git a/src/dialogs.hpp b/src/dialogs.hpp index 5c97bfb4f043..ac35495a6a51 100644 --- a/src/dialogs.hpp +++ b/src/dialogs.hpp @@ -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 namespace dialogs { diff --git a/src/game_initialization/connect_engine.cpp b/src/game_initialization/connect_engine.cpp index 2fcbef2f4dac..ca163a97557c 100644 --- a/src/game_initialization/connect_engine.cpp +++ b/src/game_initialization/connect_engine.cpp @@ -760,13 +760,6 @@ std::pair 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; diff --git a/src/game_initialization/connect_engine.hpp b/src/game_initialization/connect_engine.hpp index ae57d8c6e363..c79149299160 100644 --- a/src/game_initialization/connect_engine.hpp +++ b/src/game_initialization/connect_engine.hpp @@ -75,7 +75,6 @@ class connect_engine // Return pair first element specifies whether to leave the game // and second element whether to silently update UI. std::pair 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. diff --git a/src/game_initialization/mp_game_utils.cpp b/src/game_initialization/mp_game_utils.cpp index 0151288a5d0d..470f51c297a7 100644 --- a/src/game_initialization/mp_game_utils.cpp +++ b/src/game_initialization/mp_game_utils.cpp @@ -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"]); } } diff --git a/src/game_initialization/mp_game_utils.hpp b/src/game_initialization/mp_game_utils.hpp index dccd40142d6d..71664eac6af5 100644 --- a/src/game_initialization/mp_game_utils.hpp +++ b/src/game_initialization/mp_game_utils.hpp @@ -15,7 +15,6 @@ #define MP_GAME_UTILS_HPP_INCLUDED #include "mp_game_settings.hpp" -#include "network.hpp" class config; class saved_game; diff --git a/src/game_initialization/multiplayer.cpp b/src/game_initialization/multiplayer.cpp index 066f7f3beb01..6a78c7fe8e17 100644 --- a/src/game_initialization/multiplayer.cpp +++ b/src/game_initialization/multiplayer.cpp @@ -168,7 +168,7 @@ static std::unique_ptr 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 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 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))); diff --git a/src/game_initialization/multiplayer_connect.cpp b/src/game_initialization/multiplayer_connect.cpp index b4c15ef312a4..5b0acad2663a 100644 --- a/src/game_initialization/multiplayer_connect.cpp +++ b/src/game_initialization/multiplayer_connect.cpp @@ -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; diff --git a/src/game_initialization/multiplayer_connect.hpp b/src/game_initialization/multiplayer_connect.hpp index dce4d48ec7cb..4ae89ea024bd 100644 --- a/src/game_initialization/multiplayer_connect.hpp +++ b/src/game_initialization/multiplayer_connect.hpp @@ -110,7 +110,6 @@ class connect : public mp::ui 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&); diff --git a/src/game_initialization/multiplayer_ui.cpp b/src/game_initialization/multiplayer_ui.cpp index 53d52ca08fa6..636cc1f91021 100644 --- a/src/game_initialization/multiplayer_ui.cpp +++ b/src/game_initialization/multiplayer_ui.cpp @@ -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); diff --git a/src/game_initialization/multiplayer_ui.hpp b/src/game_initialization/multiplayer_ui.hpp index 019741517444..dca862242eb0 100644 --- a/src/game_initialization/multiplayer_ui.hpp +++ b/src/game_initialization/multiplayer_ui.hpp @@ -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 @@ class ui : public gui::widget, private events::chat_handler, private font::float */ 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. diff --git a/src/game_launcher.cpp b/src/game_launcher.cpp index 2ab79088a067..54fbdb4689b1 100644 --- a/src/game_launcher.cpp +++ b/src/game_launcher.cpp @@ -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 // 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 != "") { diff --git a/src/game_preferences.cpp b/src/game_preferences.cpp index 4b92a65f0f4c..a78f55b36334 100644 --- a/src/game_preferences.cpp +++ b/src/game_preferences.cpp @@ -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() diff --git a/src/gui/dialogs/lobby/data.cpp b/src/gui/dialogs/lobby/data.cpp index bc18786bdc86..73fe7a6ecc8e 100644 --- a/src/gui/dialogs/lobby/data.cpp +++ b/src/gui/dialogs/lobby/data.cpp @@ -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" diff --git a/src/gui/dialogs/lobby/info.cpp b/src/gui/dialogs/lobby/info.cpp index 87f92149604d..2b7336b31fa2 100644 --- a/src/gui/dialogs/lobby/info.cpp +++ b/src/gui/dialogs/lobby/info.cpp @@ -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 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")); diff --git a/src/gui/dialogs/lobby/info.hpp b/src/gui/dialogs/lobby/info.hpp index d8343a1d23d3..be31f29c2d24 100644 --- a/src/gui/dialogs/lobby/info.hpp +++ b/src/gui/dialogs/lobby/info.hpp @@ -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 @@ class lobby_info game_filter_and_stack game_filter_; bool game_filter_invert_; std::vector games_visibility_; + twesnothd_connection& wesnothd_connection_; }; #endif diff --git a/src/gui/dialogs/lobby/lobby.cpp b/src/gui/dialogs/lobby/lobby.cpp index 252cadf6c33d..3c63ef6c5326 100644 --- a/src/gui/dialogs/lobby/lobby.cpp +++ b/src/gui/dialogs/lobby/lobby.cpp @@ -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 diff --git a/src/gui/dialogs/lobby/lobby.hpp b/src/gui/dialogs/lobby/lobby.hpp index 9779154ea3f4..06480bc4c3c9 100644 --- a/src/gui/dialogs/lobby/lobby.hpp +++ b/src/gui/dialogs/lobby/lobby.hpp @@ -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 @@ class tlobby_main : public tdialog, private events::chat_handler CVideo& video_; + twesnothd_connection &wesnothd_connection_; + /** Timer for updating the lobby. */ size_t lobby_update_timer_; diff --git a/src/playmp_controller.cpp b/src/playmp_controller.cpp index 838adbe9278b..45651f035976 100644 --- a/src/playmp_controller.cpp +++ b/src/playmp_controller.cpp @@ -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; } diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index 46971a6e41cf..14b79a5b5c61 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -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(&e)) { return LEVEL_RESULT::QUIT; + } else { + throw; } } diff --git a/src/playturn.cpp b/src/playturn.cpp index 8032b60d1670..746406726ed7 100644 --- a/src/playturn.cpp +++ b/src/playturn.cpp @@ -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; diff --git a/src/playturn_network_adapter.cpp b/src/playturn_network_adapter.cpp index 7f8e015289cf..d38a88b6977f 100644 --- a/src/playturn_network_adapter.cpp +++ b/src/playturn_network_adapter.cpp @@ -1,5 +1,4 @@ #include "playturn_network_adapter.hpp" -#include "network.hpp" #include "config_assign.hpp" #include "log.hpp" diff --git a/src/synced_context.cpp b/src/synced_context.cpp index 2e64436cb8c8..b06327530e63 100644 --- a/src/synced_context.cpp +++ b/src/synced_context.cpp @@ -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() diff --git a/src/wesnoth.cpp b/src/wesnoth.cpp index a36f490d4088..051f821301bd 100644 --- a/src/wesnoth.cpp +++ b/src/wesnoth.cpp @@ -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" diff --git a/src/wesnothd_connection.hpp b/src/wesnothd_connection.hpp index 1f63b154d3f4..f583db8213af 100644 --- a/src/wesnothd_connection.hpp +++ b/src/wesnothd_connection.hpp @@ -32,6 +32,7 @@ #include #include #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. diff --git a/src/wesnothd_connection_error.hpp b/src/wesnothd_connection_error.hpp new file mode 100644 index 000000000000..ee7bbacb9e53 --- /dev/null +++ b/src/wesnothd_connection_error.hpp @@ -0,0 +1,43 @@ +/* + Copyright (C) 2011 - 2016 by Sergey Popov + 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 +#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) +}; +