wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src game.cpp campaign_server/campaign_s...


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src game.cpp campaign_server/campaign_s...
Date: Tue, 28 Sep 2004 19:46:41 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    04/09/28 23:40:08

Modified files:
        src            : game.cpp 
        src/campaign_server: campaign_server.cpp 

Log message:
        made it possible to erase campaigns from the campaign server

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.139&tr2=1.140&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/campaign_server/campaign_server.cpp.diff?tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: wesnoth/src/campaign_server/campaign_server.cpp
diff -u wesnoth/src/campaign_server/campaign_server.cpp:1.5 
wesnoth/src/campaign_server/campaign_server.cpp:1.6
--- wesnoth/src/campaign_server/campaign_server.cpp:1.5 Sun Sep 19 20:42:35 2004
+++ wesnoth/src/campaign_server/campaign_server.cpp     Tue Sep 28 23:40:08 2004
@@ -124,6 +124,26 @@
                                                write_file(file_,cfg_.write());
                                                
network::send_data(construct_message("Campaign accepted."),sock);
                                        }
+                               } else if(const config* erase = 
data.child("delete")) {
+                                       config* const campaign = 
campaigns().find_child("campaign","name",(*erase)["name"]);
+                                       if(campaign == NULL) {
+                                               
network::send_data(construct_error("The campaign does not exist."),sock);
+                                               continue;
+                                       }
+
+                                       if((*campaign)["passphrase"] != 
(*erase)["passphrase"]) {
+                                               
network::send_data(construct_error("The passphrase is incorrect."),sock);
+                                               continue;
+                                       }
+
+                                       //erase the campaign
+                                       write_file((*campaign)["filename"],"");
+                                       
+                                       const config::child_list& 
campaigns_list = campaigns().get_children("campaign");
+                                       const size_t index = 
std::find(campaigns_list.begin(),campaigns_list.end(),campaign) - 
campaigns_list.begin();
+                                       
campaigns().remove_child("campaign",index);
+                                       write_file(file_,cfg_.write());
+                                       
network::send_data(construct_message("Campaign erased."),sock);
                                }
                        }
                } catch(network::error& e) {
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.139 wesnoth/src/game.cpp:1.140
--- wesnoth/src/game.cpp:1.139  Wed Sep 22 00:05:33 2004
+++ wesnoth/src/game.cpp        Tue Sep 28 23:40:07 2004
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.139 2004/09/22 00:05:33 cedricd Exp $ */
+/* $Id: game.cpp,v 1.140 2004/09/28 23:40:07 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -341,6 +341,7 @@
 
        void download_campaigns();
        void upload_campaign(const std::string& campaign, network::connection 
sock);
+       void delete_campaign(const std::string& campaign, network::connection 
sock);
 
        const int argc_;
        int arg_;
@@ -1013,19 +1014,31 @@
                std::vector<std::string> campaigns, options;
                options.push_back(_(",Name,Version,Author,Downloads"));
                const config::child_list& cmps = 
campaigns_cfg->get_children("campaign");
+               const std::vector<std::string>& publish_options = 
available_campaigns();
+
+               std::vector<std::string> delete_options;
+
                for(config::child_list::const_iterator i = cmps.begin(); i != 
cmps.end(); ++i) {
                        campaigns.push_back((**i)["name"]);
                        
                        std::string name = (**i)["name"];
+
+                       
if(std::count(publish_options.begin(),publish_options.end(),name) != 0) {
+                               delete_options.push_back(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);
                }
 
+               for(std::vector<std::string>::const_iterator d = 
delete_options.begin(); d != delete_options.end(); ++d) {
+                       options.push_back(std::string(",") + _("Delete 
campaign: ") + *d);
+               }
+
                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;
@@ -1036,6 +1049,11 @@
                        return;
                }
 
+               if(index >= int(campaigns.size() + publish_options.size())) {
+                       delete_campaign(delete_options[index - 
int(campaigns.size() + publish_options.size())],sock);
+                       return;
+               }
+
                if(index >= int(campaigns.size())) {
                        upload_campaign(publish_options[index - 
int(campaigns.size())],sock);
                        return;
@@ -1127,6 +1145,30 @@
        }
 }
 
+void game_controller::delete_campaign(const std::string& campaign, 
network::connection sock)
+{
+       config cfg;
+       get_campaign_info(campaign,cfg);
+
+       config msg;
+       msg["name"] = campaign;
+       msg["passphrase"] = cfg["passphrase"];
+
+       config data;
+       data.add_child("delete",msg);
+
+       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";




reply via email to

[Prev in Thread] Current Thread [Next in Thread]