[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src game.cpp
From: |
David White |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src game.cpp |
Date: |
Sat, 18 Sep 2004 23:36:12 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: David White <address@hidden> 04/09/19 03:29:44
Modified files:
src : game.cpp
Log message:
made it so Wesnoth doesn't have to be restarted after downloading a
campaign
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.133&tr2=1.134&r1=text&r2=text
Patches:
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.133 wesnoth/src/game.cpp:1.134
--- wesnoth/src/game.cpp:1.133 Sat Sep 18 23:12:20 2004
+++ wesnoth/src/game.cpp Sun Sep 19 03:29:44 2004
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.133 2004/09/18 23:12:20 gruikya Exp $ */
+/* $Id: game.cpp,v 1.134 2004/09/19 03:29:44 Sirp Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -339,6 +339,8 @@
game_controller(const game_controller&);
void operator=(const game_controller&);
+ void download_campaigns();
+
const int argc_;
int arg_;
const char* const * const argv_;
@@ -533,6 +535,8 @@
bool game_controller::init_config()
{
+ defines_map_.clear();
+
//load in the game's configuration files
defines_map_["NORMAL"] = preproc_define();
defines_map_["MEDIUM"] = preproc_define();
@@ -912,91 +916,8 @@
//get more campaigns from server
if(res == int(campaign_names.size()-1)) {
- std::string host = "campaigns.wesnoth.org";
- const int res = gui::show_dialog(disp(),NULL,_("Connect to
Server"),
- _("You will now connect to a campaign server to
download campaigns."),
- gui::OK_CANCEL,NULL,NULL,_("Server: "),&host);
- if(res != 0) {
- return false;
- }
-
- const std::vector<std::string> items = config::split(host,':');
- host = items.front();
-
- try {
- const network::manager net_manager;
- const network::connection sock =
network::connect(items.front(),lexical_cast_default<int>(items.back(),15002));
- if(!sock) {
-
gui::show_dialog(disp(),NULL,_("Error"),_("Could not connect to
host."),gui::OK_ONLY);
- return false;
- }
-
- config cfg;
- cfg.add_child("request_campaign_list");
- network::send_data(cfg,sock);
-
- network::connection res =
gui::network_data_dialog(disp(),_("Awaiting response from server"),cfg,sock);
- if(!res) {
- return false;
- }
-
- const config* const error = cfg.child("error");
- if(error != NULL) {
-
gui::show_dialog(disp(),NULL,_("Error"),(*error)["message"],gui::OK_ONLY);
- return false;
- }
-
- const config* const campaigns_cfg =
cfg.child("campaigns");
- if(campaigns_cfg == NULL) {
-
gui::show_dialog(disp(),NULL,_("Error"),_("Error communicating with the
server."),gui::OK_ONLY);
- return false;
- }
-
- std::vector<std::string> campaigns;
- const config::child_list& cmps =
campaigns_cfg->get_children("campaign");
- for(config::child_list::const_iterator i =
cmps.begin(); i != cmps.end(); ++i) {
- campaigns.push_back((**i)["name"]);
- }
-
- if(campaigns.empty()) {
-
gui::show_dialog(disp(),NULL,_("Error"),_("There are no campaigns available for
download from this server."),gui::OK_ONLY);
- return false;
- }
-
- const int index = gui::show_dialog(disp(),NULL,_("Get
Campaign"),_("Choose the campaign to download."),gui::OK_CANCEL,&campaigns);
- if(index < 0 || index >= int(campaigns.size())) {
- return false;
- }
-
- config request;
- request.add_child("request_campaign")["name"] =
campaigns[index];
- network::send_data(request,sock);
-
- res = gui::network_data_dialog(disp(),_("Downloading
campaign..."),cfg,sock);
- if(!res) {
- return false;
- }
-
- if(cfg.child("error") != NULL) {
-
gui::show_dialog(disp(),NULL,_("Error"),(*cfg.child("error"))["message"],gui::OK_ONLY);
- return false;
- }
-
- unarchive_campaign(cfg);
-
- gui::show_dialog(disp(),NULL,_("Campaign
Installed"),_("The campaign has been installed. You will have to restart
Wesnoth before you can play it."),gui::OK_ONLY);
- return false;
-
- } catch(config::error& e) {
- gui::show_dialog(disp(),NULL,_("Error"),_("Network
communication error."),gui::OK_ONLY);
- return false;
- } catch(network::error& e) {
- gui::show_dialog(disp(),NULL,_("Error"),_("Remote host
disconnected."),gui::OK_ONLY);
- return false;
- } catch(io_exception& e) {
- gui::show_dialog(disp(),NULL,_("Error"),_("There was a
problem creating the files necessary to install this campaign."),gui::OK_ONLY);
- return false;
- }
+ download_campaigns();
+ return new_campaign();
}
const config& campaign = *campaigns[res];
@@ -1031,6 +952,96 @@
return true;
}
+void game_controller::download_campaigns()
+{
+ std::string host = "campaigns.wesnoth.org";
+ const int res = gui::show_dialog(disp(),NULL,_("Connect to Server"),
+ _("You will now connect to a campaign server to download
campaigns."),
+ gui::OK_CANCEL,NULL,NULL,_("Server: "),&host);
+ if(res != 0) {
+ return;
+ }
+
+ const std::vector<std::string> items = config::split(host,':');
+ host = items.front();
+
+ try {
+ const network::manager net_manager;
+ const network::connection sock =
network::connect(items.front(),lexical_cast_default<int>(items.back(),15002));
+ if(!sock) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("Could not
connect to host."),gui::OK_ONLY);
+ return;
+ }
+
+ config cfg;
+ cfg.add_child("request_campaign_list");
+ network::send_data(cfg,sock);
+
+ network::connection res =
gui::network_data_dialog(disp(),_("Awaiting response from server"),cfg,sock);
+ if(!res) {
+ return;
+ }
+
+ const config* const error = cfg.child("error");
+ if(error != NULL) {
+
gui::show_dialog(disp(),NULL,_("Error"),(*error)["message"],gui::OK_ONLY);
+ return;
+ }
+
+ const config* const campaigns_cfg = cfg.child("campaigns");
+ if(campaigns_cfg == NULL) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("Error
communicating with the server."),gui::OK_ONLY);
+ return;
+ }
+
+ std::vector<std::string> campaigns;
+ const config::child_list& cmps =
campaigns_cfg->get_children("campaign");
+ for(config::child_list::const_iterator i = cmps.begin(); i !=
cmps.end(); ++i) {
+ campaigns.push_back((**i)["name"]);
+ }
+
+ if(campaigns.empty()) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("There are no
campaigns available for download from this server."),gui::OK_ONLY);
+ return;
+ }
+
+ const int index = gui::show_dialog(disp(),NULL,_("Get
Campaign"),_("Choose the campaign to download."),gui::OK_CANCEL,&campaigns);
+ if(index < 0 || index >= int(campaigns.size())) {
+ return;
+ }
+
+ config request;
+ request.add_child("request_campaign")["name"] =
campaigns[index];
+ network::send_data(request,sock);
+
+ res = gui::network_data_dialog(disp(),_("Downloading
campaign..."),cfg,sock);
+ if(!res) {
+ return;
+ }
+
+ if(cfg.child("error") != NULL) {
+
gui::show_dialog(disp(),NULL,_("Error"),(*cfg.child("error"))["message"],gui::OK_ONLY);
+ return;
+ }
+
+ unarchive_campaign(cfg);
+
+ //force a reload of configuration information
+ const bool old_cache = use_caching_;
+ use_caching_ = false;
+ init_config();
+ use_caching_ = old_cache;
+
+ gui::show_dialog(disp(),NULL,_("Campaign Installed"),_("The
campaign has been installed."),gui::OK_ONLY);
+ } catch(config::error& e) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("Network
communication error."),gui::OK_ONLY);
+ } catch(network::error& e) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("Remote host
disconnected."),gui::OK_ONLY);
+ } catch(io_exception& e) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("There was a problem
creating the files necessary to install this campaign."),gui::OK_ONLY);
+ }
+}
+
bool game_controller::play_multiplayer()
{
state_.campaign_type = "multiplayer";
- [Wesnoth-cvs-commits] wesnoth/src game.cpp, Yann Dirson, 2004/09/02
- [Wesnoth-cvs-commits] wesnoth/src game.cpp, David White, 2004/09/08
- [Wesnoth-cvs-commits] wesnoth/src game.cpp, David White, 2004/09/12
- [Wesnoth-cvs-commits] wesnoth/src game.cpp, David White, 2004/09/12
- [Wesnoth-cvs-commits] wesnoth/src game.cpp, Guillaume Melquiond, 2004/09/18
- [Wesnoth-cvs-commits] wesnoth/src game.cpp, Guillaume Melquiond, 2004/09/18
- [Wesnoth-cvs-commits] wesnoth/src game.cpp, Philippe Plantier, 2004/09/18
- [Wesnoth-cvs-commits] wesnoth/src game.cpp,
David White <=
- [Wesnoth-cvs-commits] wesnoth/src game.cpp, Guillaume Melquiond, 2004/09/19
- [Wesnoth-cvs-commits] wesnoth/src game.cpp, Yann Dirson, 2004/09/19