Skip to content

Commit

Permalink
remove uses of network::error and fix gui2 mp lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Jun 5, 2016
1 parent a6b114f commit dca57bd
Show file tree
Hide file tree
Showing 26 changed files with 104 additions and 127 deletions.
6 changes: 0 additions & 6 deletions src/addon/manager_ui.cpp
Expand Up @@ -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."));
Expand Down Expand Up @@ -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."));
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs.hpp
Expand Up @@ -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 {


Expand Down
7 changes: 0 additions & 7 deletions src/game_initialization/connect_engine.cpp
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/game_initialization/connect_engine.hpp
Expand Up @@ -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<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.
Expand Down
5 changes: 3 additions & 2 deletions src/game_initialization/mp_game_utils.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/game_initialization/mp_game_utils.hpp
Expand Up @@ -15,7 +15,6 @@
#define MP_GAME_UTILS_HPP_INCLUDED

#include "mp_game_settings.hpp"
#include "network.hpp"

class config;
class saved_game;
Expand Down
10 changes: 5 additions & 5 deletions src/game_initialization/multiplayer.cpp
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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)));
Expand Down
5 changes: 0 additions & 5 deletions src/game_initialization/multiplayer_connect.cpp
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/game_initialization/multiplayer_connect.hpp
Expand Up @@ -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&);
Expand Down
18 changes: 3 additions & 15 deletions src/game_initialization/multiplayer_ui.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions src/game_initialization/multiplayer_ui.hpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions src/game_launcher.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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 != "") {
Expand Down
3 changes: 1 addition & 2 deletions src/game_preferences.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -168,7 +167,7 @@ manager::manager() :
}
}

network::ping_timeout = get_ping_timeout();
//network::ping_timeout = get_ping_timeout();
}

manager::~manager()
Expand Down
1 change: 0 additions & 1 deletion src/gui/dialogs/lobby/data.cpp
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions src/gui/dialogs/lobby/info.cpp
Expand Up @@ -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");
Expand All @@ -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)
Expand All @@ -53,6 +52,7 @@ lobby_info::lobby_info(const config& game_config)
, game_filter_()
, game_filter_invert_(false)
, games_visibility_()
, wesnothd_connection_(wesnothd_connection)
{
}

Expand Down Expand Up @@ -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"));
Expand All @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down
5 changes: 3 additions & 2 deletions src/gui/dialogs/lobby/info.hpp
Expand Up @@ -17,15 +17,15 @@

#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
*/
class lobby_info
{
public:
explicit lobby_info(const config& game_config);
explicit lobby_info(const config& game_config, twesnothd_connection&);

~lobby_info();

Expand Down Expand Up @@ -113,6 +113,7 @@ class lobby_info
game_filter_and_stack game_filter_;
bool game_filter_invert_;
std::vector<bool> games_visibility_;
twesnothd_connection& wesnothd_connection_;
};

#endif

0 comments on commit dca57bd

Please sign in to comment.