bool game_launcher::play_multiplayer(mp_selection res) { state_ = saved_game(); state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER; try { if (res == MP_HOST) { try { start_wesnothd(); } catch(game::mp_server_error&) { preferences::show_wesnothd_server_search(video()); try { start_wesnothd(); } catch(game::mp_server_error&) { return false; } } } //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); events::discard_input(); // prevent the "keylogger" effect cursor::set(cursor::NORMAL); if(res == MP_LOCAL) { mp::start_local_game(video(), game_config_manager::get()->game_config(), state_); } else { mp::start_client(video(), game_config_manager::get()->game_config(), state_, multiplayer_server_); multiplayer_server_.clear(); } } catch(game::mp_server_error& e) { gui2::show_error_message(video(), _("Error while starting server: ") + e.message); } catch(game::load_game_failed& e) { gui2::show_error_message(video(), _("The game could not be loaded: ") + e.message); } catch(game::game_error& e) { gui2::show_error_message(video(), _("Error while playing the game: ") + e.message); } catch (mapgen_exception& e) { gui2::show_error_message(video(), _("Map generator error: ") + e.message); } catch(wesnothd_error& e) { if(e.message != "") { 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; } } catch(config::error& e) { if(e.message != "") { ERR_CONFIG << "caught config::error: " << e.message << std::endl; gui2::show_transient_message(video(), "", e.message); } else { ERR_CONFIG << "caught config::error" << std::endl; } } catch(incorrect_map_format_error& e) { gui2::show_error_message(video(), _("The game map could not be loaded: ") + e.message); } catch (savegame::load_game_exception & e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); //this will make it so next time through the title screen loop, this game is loaded } catch(wml_exception& e) { e.show(video()); } catch (game::error & e) { std::cerr << "caught game::error...\n"; gui2::show_error_message(video(), _("Error: ") + e.message); } return false; }
bool game_launcher::play_multiplayer() { int res; state_ = saved_game(); state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER; //Print Gui only if the user hasn't specified any server if( multiplayer_server_.empty() ){ int start_server; do { start_server = 0; gui2::tmp_method_selection dlg; dlg.show(video()); if(dlg.get_retval() == gui2::twindow::OK) { res = dlg.get_choice(); } else { return false; } if (res == 2 && preferences::mp_server_warning_disabled() < 2) { start_server = !gui2::tmp_host_game_prompt::execute(video()); } } while (start_server); if (res < 0) { return false; } }else{ res = 4; } try { if (res == 2) { try { start_wesnothd(); } catch(game::mp_server_error&) { preferences::show_wesnothd_server_search(video()); try { start_wesnothd(); } catch(game::mp_server_error&) { return false; } } } //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); events::discard_input(); // prevent the "keylogger" effect cursor::set(cursor::NORMAL); if(res == 3) { mp::start_local_game(video(), game_config_manager::get()->game_config(), state_); } else if((res >= 0 && res <= 2) || res == 4) { std::string host; if(res == 0) { host = preferences::server_list().front().address; }else if(res == 2) { host = "localhost"; }else if(res == 4){ host = multiplayer_server_; multiplayer_server_ = ""; } mp::start_client(video(), game_config_manager::get()->game_config(), state_, host); } } catch(game::mp_server_error& e) { gui2::show_error_message(video(), _("Error while starting server: ") + e.message); } catch(game::load_game_failed& e) { gui2::show_error_message(video(), _("The game could not be loaded: ") + e.message); } catch(game::game_error& e) { 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) { if(e.message != "") { 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; } } catch(config::error& e) { if(e.message != "") { ERR_CONFIG << "caught config::error: " << e.message << std::endl; gui2::show_transient_message(video(), "", e.message); } else { ERR_CONFIG << "caught config::error" << std::endl; } } catch(incorrect_map_format_error& e) { gui2::show_error_message(video(), std::string(_("The game map could not be loaded: ")) + e.message); } catch (game::load_game_exception &) { //this will make it so next time through the title screen loop, this game is loaded } catch(twml_exception& e) { e.show(video()); } catch (game::error & e) { std::cerr << "caught game::error...\n"; gui2::show_error_message(video(), _("Error: ") + e.message); } return false; }