Skip to content

Commit

Permalink
Revert "Campaignd: rename addon list response config tags"
Browse files Browse the repository at this point in the history
This reverts commit 98604a4. I've been told very soundly
that I didn't account for all cases and this should be postponed until 1.15.
  • Loading branch information
Vultraz committed Feb 10, 2018
1 parent 98604a4 commit b5b6783
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
10 changes: 4 additions & 6 deletions src/addon/client.cpp
Expand Up @@ -82,15 +82,13 @@ bool addons_client::request_addons_list(config& cfg)

config response_buf;

/** @todo FIXME: get rid of this legacy "campaign"/"campaigns" silliness
*/

this->send_simple_request("request_campaign_list", response_buf);
this->wait_for_transfer_done(_("Downloading list of add-ons..."));

// Legacy support. The response key used to be "campaigns".
if(response_buf.has_child("campaigns")) {
cfg = std::move(response_buf.child("campaigns"));
} else {
cfg = std::move(response_buf.child("addons"));
}
cfg = std::move(response_buf.child("campaigns"));

return !this->update_last_error(response_buf);
}
Expand Down
12 changes: 4 additions & 8 deletions src/addon/info.cpp
Expand Up @@ -199,14 +199,10 @@ void read_addons_list(const config& cfg, addons_list& dest)

unsigned order = 0;

std::string key = "addon";

// Legacy support. The entry key used to be "campaign".
if(!cfg.has_child(key)) {
key = "campaign";
}

for(const config& addon_cfg : cfg.child_range(key)) {
/** @todo FIXME: get rid of this legacy "campaign"/"campaigns" silliness
*/
const config::const_child_itors &addon_cfgs = cfg.child_range("campaign");
for(const config& addon_cfg : addon_cfgs) {
const std::string& id = addon_cfg["name"].str();
if(dest.find(id) != dest.end()) {
ERR_AC << "add-ons list has multiple entries for '" << id << "', not good; ignoring them" << std::endl;
Expand Down
32 changes: 16 additions & 16 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -130,7 +130,7 @@ server::server(const std::string& cfg_file)

// Ensure all campaigns to use secure hash passphrase storage
if(!read_only_) {
for(config& campaign : addons().child_range("addon")) {
for(config& campaign : campaigns().child_range("campaign")) {
// Campaign already has a hashed password
if(campaign["passphrase"].empty()) {
continue;
Expand Down Expand Up @@ -207,7 +207,7 @@ void server::load_config()

// Ensure the campaigns list WML exists even if empty, other functions
// depend on its existence.
cfg_.child_or_add("addons");
cfg_.child_or_add("campaigns");

// Certain config values are saved to WML again so that a given server
// instance's parameters remain constant even if the code defaults change
Expand Down Expand Up @@ -303,7 +303,7 @@ void server::handle_read_from_fifo(const boost::system::error_code& error, std::
} else {
const std::string& addon_id = ctl[1];
const std::string& newpass = ctl[2];
config& campaign = get_addon(addon_id);
config& campaign = get_campaign(addon_id);

if(!campaign) {
ERR_CS << "Add-on '" << addon_id << "' not found, cannot set passphrase\n";
Expand Down Expand Up @@ -505,7 +505,7 @@ void server::handle_request_campaign_list(const server::request& req)
const std::string& name = req.cfg["name"];
const std::string& lang = req.cfg["language"];

for(const config& i : addons().child_range("addon"))
for(const config& i : campaigns().child_range("campaign"))
{
if(!name.empty() && name != i["name"]) {
continue;
Expand Down Expand Up @@ -536,10 +536,10 @@ void server::handle_request_campaign_list(const server::request& req)
}
}

campaign_list.add_child("addon", i);
campaign_list.add_child("campaign", i);
}

for(config& j : campaign_list.child_range("addon"))
for(config& j : campaign_list.child_range("campaign"))
{
j["passphrase"] = "";
j["passhash"] = "";
Expand All @@ -560,7 +560,7 @@ void server::handle_request_campaign_list(const server::request& req)
}

config response;
response.add_child("addons", std::move(campaign_list));
response.add_child("campaigns", std::move(campaign_list));

std::ostringstream ostr;
write(ostr, response);
Expand All @@ -575,7 +575,7 @@ void server::handle_request_campaign(const server::request& req)
{
LOG_CS << "sending campaign '" << req.cfg["name"] << "' to " << req.addr << " using gzip\n";

config& campaign = get_addon(req.cfg["name"]);
config& campaign = get_campaign(req.cfg["name"]);

if(!campaign) {
send_error("Add-on '" + req.cfg["name"].str() + "' not found.", req.sock);
Expand Down Expand Up @@ -644,7 +644,7 @@ void server::handle_upload(const server::request& req)
const std::string& lc_name = utf8::lowercase(name);
passed_name_utf8_check = true;

for(config& c : addons().child_range("addon"))
for(config& c : campaigns().child_range("campaign"))
{
if(utf8::lowercase(c["name"]) == lc_name) {
campaign = &c;
Expand Down Expand Up @@ -747,7 +747,7 @@ void server::handle_upload(const server::request& req)
std::string message = "Add-on accepted.";

if(campaign == nullptr) {
campaign = &addons().add_child("addon");
campaign = &campaigns().add_child("campaign");
(*campaign)["original_timestamp"] = upload_ts;
}

Expand Down Expand Up @@ -826,16 +826,16 @@ void server::handle_delete(const server::request& req)

LOG_CS << "deleting campaign '" << erase["name"] << "' requested from " << req.addr << "\n";

config& campaign = get_addon(erase["name"]);
config& campaign = get_campaign(erase["name"]);

if(!campaign) {
send_error("The add-on does not exist.", req.sock);
return;
}

if(!authenticate(campaign, erase["passphrase"])
&& (addons()["master_password"].empty()
|| addons()["master_password"] != erase["passphrase"]))
&& (campaigns()["master_password"].empty()
|| campaigns()["master_password"] != erase["passphrase"]))
{
send_error("The passphrase is incorrect.", req.sock);
return;
Expand All @@ -849,11 +849,11 @@ void server::handle_delete(const server::request& req)
<< '\n';
}

config::child_itors itors = addons().child_range("addon");
config::child_itors itors = campaigns().child_range("campaign");
for(size_t index = 0; !itors.empty(); ++index, itors.pop_front())
{
if(&campaign == &itors.front()) {
addons().remove_child("addon", index);
campaigns().remove_child("campaign", index);
break;
}
}
Expand All @@ -876,7 +876,7 @@ void server::handle_change_passphrase(const server::request& req)
return;
}

config& campaign = get_addon(cpass["name"]);
config& campaign = get_campaign(cpass["name"]);

if(!campaign) {
send_error("No add-on with that name exists.", req.sock);
Expand Down
6 changes: 3 additions & 3 deletions src/campaign_server/campaign_server.hpp
Expand Up @@ -135,13 +135,13 @@ class server : public server_base
void fire(const std::string& hook, const std::string& addon);

/** Retrieves the contents of the [campaigns] WML node. */
const config& addons() const { return cfg_.child("addons"); }
const config& campaigns() const { return cfg_.child("campaigns"); }

/** Retrieves the contents of the [campaigns] WML node. */
config& addons() { return cfg_.child("addons"); }
config& campaigns() { return cfg_.child("campaigns"); }

/** Retrieves a campaign by id if found, or a null config otherwise. */
config& get_addon(const std::string& id) { return addons().find_child("addon", "name", id); }
config& get_campaign(const std::string& id) { return campaigns().find_child("campaign", "name", id); }

/** Retrieves the contents of the [server_info] WML node. */
const config& server_info() const { return cfg_.child("server_info"); }
Expand Down

0 comments on commit b5b6783

Please sign in to comment.