[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src game.cpp publish_campaign.cpp publi...
From: |
David White |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src game.cpp publish_campaign.cpp publi... |
Date: |
Sun, 19 Sep 2004 01:54:35 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: David White <address@hidden> 04/09/19 05:48:18
Modified files:
src : game.cpp publish_campaign.cpp
publish_campaign.hpp
src/campaign_server: campaign_server.cpp
Log message:
added more fields to campaign server; added GPL requirements notice;
added way to upload campaigns from the GUI
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.134&tr2=1.135&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/publish_campaign.cpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/publish_campaign.hpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/campaign_server/campaign_server.cpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
Patches:
Index: wesnoth/src/campaign_server/campaign_server.cpp
diff -u wesnoth/src/campaign_server/campaign_server.cpp:1.3
wesnoth/src/campaign_server/campaign_server.cpp:1.4
--- wesnoth/src/campaign_server/campaign_server.cpp:1.3 Wed Sep 15 02:43:11 2004
+++ wesnoth/src/campaign_server/campaign_server.cpp Sun Sep 19 05:48:18 2004
@@ -72,7 +72,7 @@
response.add_child("campaigns",campaign_list);
network::send_data(response,sock);
} else if(const config* req =
data.child("request_campaign")) {
- const config* const campaign =
campaigns().find_child("campaign","name",(*req)["name"]);
+ config* const campaign =
campaigns().find_child("campaign","name",(*req)["name"]);
if(campaign == NULL) {
network::send_data(construct_error("Campaign not found."),sock);
} else {
@@ -80,7 +80,13 @@
compression_schema schema;
cfg.read_compressed(read_file((*campaign)["filename"]),schema);
network::queue_data(cfg,sock);
+
+ const int downloads =
lexical_cast_default<int>((*campaign)["downloads"],0)+1;
+ (*campaign)["downloads"] =
lexical_cast<std::string>(downloads);
}
+
+ } else if(data.child("request_terms") != NULL) {
+
network::send_data(construct_message("All campaigns uploaded to this server
must be licensed under the terms of the GNU General Public License (GPL). By
uploading content to this server, you certify that you have the right to place
the content under the conditions of the GPL, and choose to do so."),sock);
} else if(const config* upload =
data.child("upload")) {
config* campaign =
campaigns().find_child("campaign","name",(*upload)["name"]);
if(campaign != NULL &&
(*campaign)["passphrase"] != (*upload)["passphrase"]) {
@@ -95,6 +101,14 @@
(*campaign)["name"] =
(*upload)["name"];
(*campaign)["filename"] =
(*upload)["name"];
(*campaign)["passphrase"] =
(*upload)["passphrase"];
+ (*campaign)["author"] =
(*upload)["author"];
+ (*campaign)["description"] =
(*upload)["description"];
+ (*campaign)["version"] =
(*upload)["version"];
+ (*campaign)["icon"] =
(*upload)["icon"];
+
+
if((*campaign)["downloads"].empty()) {
+
(*campaign)["downloads"] = "0";
+ }
const config* const data =
upload->child("data");
if(data != NULL) {
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.134 wesnoth/src/game.cpp:1.135
--- wesnoth/src/game.cpp:1.134 Sun Sep 19 03:29:44 2004
+++ wesnoth/src/game.cpp Sun Sep 19 05:48:18 2004
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.134 2004/09/19 03:29:44 Sirp Exp $ */
+/* $Id: game.cpp,v 1.135 2004/09/19 05:48:18 Sirp Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -340,6 +340,7 @@
void operator=(const game_controller&);
void download_campaigns();
+ void upload_campaign(const std::string& campaign, network::connection
sock);
const int argc_;
int arg_;
@@ -994,19 +995,34 @@
return;
}
- std::vector<std::string> campaigns;
+ std::vector<std::string> campaigns, options;
+ options.push_back(_(",Name,Version,Author,Downloads"));
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"]);
+
+ std::string name = (**i)["name"];
+ std::replace(name.begin(),name.end(),'_',' ');
+ options.push_back("&" + (**i)["icon"] + "," + name +
"," + (**i)["version"] + "," + (**i)["author"] + "," + (**i)["downloads"]);
+ }
+
+ const std::vector<std::string>& publish_options =
available_campaigns();
+ for(std::vector<std::string>::const_iterator j =
publish_options.begin(); j != publish_options.end(); ++j) {
+ options.push_back(std::string(",") + _("Publish
campaign: ") + *j);
}
- if(campaigns.empty()) {
+ if(campaigns.empty() && publish_options.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())) {
+ const int index = gui::show_dialog(disp(),NULL,_("Get
Campaign"),_("Choose the campaign to download."),gui::OK_CANCEL,&options) - 1;
+ if(index < 0) {
+ return;
+ }
+
+ if(index >= int(campaigns.size())) {
+ upload_campaign(publish_options[index -
int(campaigns.size())],sock);
return;
}
@@ -1042,6 +1058,60 @@
}
}
+void game_controller::upload_campaign(const std::string& campaign,
network::connection sock)
+{
+ config request_terms;
+ request_terms.add_child("request_terms");
+ network::send_data(request_terms,sock);
+ config data;
+ sock = network::receive_data(data,sock,60000);
+ if(!sock) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("Connection timed
out"),gui::OK_ONLY);
+ return;
+ } else if(data.child("error")) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("The server responded
with an error: \"") + (*data.child("error"))["message"] + "\"",gui::OK_ONLY);
+ return;
+ } else if(data.child("message")) {
+ const int res =
gui::show_dialog(disp(),NULL,_("Terms"),(*data.child("message"))["message"],gui::OK_CANCEL);
+ if(res != 0) {
+ return;
+ }
+ }
+
+ config cfg;
+ get_campaign_info(campaign,cfg);
+
+ std::string& passphrase = cfg["passphrase"];
+ if(passphrase.empty()) {
+ passphrase.resize(8);
+ for(size_t n = 0; n != 8; ++n) {
+ passphrase[n] = 'a' + (rand()%26);
+ }
+
+ set_campaign_info(campaign,cfg);
+ }
+
+ cfg["name"] = campaign;
+
+ config campaign_data;
+ archive_campaign(campaign,campaign_data);
+
+ data.clear();
+ data.add_child("upload",cfg).add_child("data",campaign_data);
+
+ std::cerr << "uploading campaign...\n";
+ network::send_data(data,sock);
+
+ sock = network::receive_data(data,sock,60000);
+ if(!sock) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("Connection timed
out"),gui::OK_ONLY);
+ } else if(data.child("error")) {
+ gui::show_dialog(disp(),NULL,_("Error"),_("The server responded
with an error: \"") + (*data.child("error"))["message"] + "\"",gui::OK_ONLY);
+ } else if(data.child("message")) {
+
gui::show_dialog(disp(),NULL,_("Response"),(*data.child("message"))["message"],gui::OK_ONLY);
+ }
+}
+
bool game_controller::play_multiplayer()
{
state_.campaign_type = "multiplayer";
@@ -1254,66 +1324,6 @@
}
p = q;
}
- } else if(val == "--publish-campaign") {
- if(arg+3 != argc && arg+4 != argc && arg+5 != argc) {
- std::cerr << "usage: --publish-campaign
<campaign> <passphrase> [<server> [<port>]]\n";
- return 0;
- }
-
- const std::string& campaign = argv[++arg];
- const std::string& passphrase = argv[++arg];
- std::string host = "campaigns.wesnoth.org", port =
"15002";
- if(++arg != argc) {
- host = argv[arg];
- if(++arg != argc) {
- port = argv[arg];
- }
- }
-
- const std::vector<std::string>& campaigns =
available_campaigns();
-
if(std::find(campaigns.begin(),campaigns.end(),campaign) == campaigns.end()) {
- std::cerr << "Campaign not found. Available
campaigns are:\n";
-
std::copy(campaigns.begin(),campaigns.end(),std::ostream_iterator<std::string>(std::cerr,"\n"));
- return 0;
- }
-
- if(campaign_name_legal(campaign) == false) {
- std::cerr << "Not a legal campaign name.\n";
- }
-
- config cfg;
- archive_campaign(campaign,cfg);
-
- std::cerr << "connecting to server...\n";
-
- const network::manager net_manager;
- network::connection sock =
network::connect(host,lexical_cast_default<int>(port,15002));
- if(!sock) {
- std::cerr << "Could not connect to server\n";
- return 0;
- }
-
- std::cerr << "connected to server. Building
campaign...\n";
-
- config data;
- config& upload = data.add_child("upload");
- upload["name"] = campaign;
- upload["passphrase"] = passphrase;
- upload.add_child("data",cfg);
-
- std::cerr << "uploading campaign...\n";
- network::send_data(data,sock);
-
- sock = network::receive_data(data,sock,60000);
- if(!sock) {
- std::cerr << "Connection timed out\n";
- } else if(data.child("error")) {
- std::cerr << "Server responded with an error:
'" << (*data.child("error"))["message"] << "'\n";
- } else if(data.child("message")) {
- std::cerr <<
(*data.child("message"))["message"] << "\n";
- }
-
- return 0;
}
}
Index: wesnoth/src/publish_campaign.cpp
diff -u wesnoth/src/publish_campaign.cpp:1.3
wesnoth/src/publish_campaign.cpp:1.4
--- wesnoth/src/publish_campaign.cpp:1.3 Tue Sep 14 11:47:28 2004
+++ wesnoth/src/publish_campaign.cpp Sun Sep 19 05:48:18 2004
@@ -21,6 +21,16 @@
}
+void get_campaign_info(const std::string& campaign_name, config& cfg)
+{
+ cfg.read(read_file(campaign_dir() + "/" + campaign_name + ".pbl"));
+}
+
+void set_campaign_info(const std::string& campaign_name, const config& cfg)
+{
+ write_file(campaign_dir() + "/" + campaign_name + ".pbl", cfg.write());
+}
+
std::vector<std::string> available_campaigns()
{
std::vector<std::string> res;
@@ -30,7 +40,9 @@
for(std::vector<std::string>::const_iterator i = dirs.begin(); i !=
dirs.end(); ++i) {
const std::string cfg_file = *i + ".cfg";
- if(std::find(files.begin(),files.end(),cfg_file) !=
files.end()) {
+ const std::string publish_file = *i + ".pbl";
+ if(std::find(files.begin(),files.end(),cfg_file) != files.end()
&&
+ std::find(files.begin(),files.end(),publish_file) !=
files.end()) {
res.push_back(*i);
}
}
Index: wesnoth/src/publish_campaign.hpp
diff -u wesnoth/src/publish_campaign.hpp:1.1
wesnoth/src/publish_campaign.hpp:1.2
--- wesnoth/src/publish_campaign.hpp:1.1 Sun Sep 12 22:08:22 2004
+++ wesnoth/src/publish_campaign.hpp Sun Sep 19 05:48:18 2004
@@ -4,6 +4,9 @@
#include <string>
#include <vector>
+void get_campaign_info(const std::string& campaign_name, class config& cfg);
+void set_campaign_info(const std::string& campaign_name, const class config&
cfg);
+
std::vector<std::string> available_campaigns();
void archive_campaign(const std::string& campaign_name, class config& cfg);
void unarchive_campaign(const class config& cfg);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src game.cpp publish_campaign.cpp publi...,
David White <=