Skip to content

Commit

Permalink
MP Lobby: fixed being prompted to download non-required addons when j…
Browse files Browse the repository at this point in the history
…oining a game.

Fixes #2476.

It turns out I had implemented 09f919e incorrectly.
All required addons, including those needed for modifications, were already added
to the game's config by the host before being sent to the server. There was no need
to parse the active list of modifications separately. I appear to have confused the
idea of addon type vs the modification itself and assumed one always equaled to the
other. Which is wrong. For example, you may have multiple mods active from the same
addon.
  • Loading branch information
Vultraz committed Feb 15, 2018
1 parent 89ad67b commit 43b3c9a
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/game_initialization/lobby_data.cpp
Expand Up @@ -224,18 +224,19 @@ game_info::game_info(const config& game, const config& game_config, const std::v
, required_addons()
, addons_outcome(SATISFIED)
{
const auto parse_requirements = [&](const config& c, const std::string& id_key) {
if(c.has_attribute(id_key)) {
if(std::find(installed_addons.begin(), installed_addons.end(), c[id_key].str()) == installed_addons.end()) {
// Parse the list of addons required to join this game.
for(const config& addon : game.child_range("addon")) {
if(addon.has_attribute("id")) {
if(std::find(installed_addons.begin(), installed_addons.end(), addon["id"].str()) == installed_addons.end()) {
required_addon r;
r.addon_id = c[id_key].str();
r.addon_id = addon["id"].str();
r.outcome = NEED_DOWNLOAD;

// Use addon name if provided, else fall back on the addon id.
if(c.has_attribute("name")) {
r.message = vgettext("Missing addon: $name", {{"name", c["name"].str()}});
if(addon.has_attribute("name")) {
r.message = vgettext("Missing addon: $name", {{"name", addon["name"].str()}});
} else {
r.message = vgettext("Missing addon: $id", {{"id", c[id_key].str()}});
r.message = vgettext("Missing addon: $id", {{"id", addon["id"].str()}});
}

required_addons.push_back(std::move(r));
Expand All @@ -245,18 +246,6 @@ game_info::game_info(const config& game, const config& game_config, const std::v
}
}
}
};

for(const config& addon : game.child_range("addon")) {
parse_requirements(addon, "id");
}

/*
* Modifications have a different format than addons. The id and addon_id are keys sent by the
* server, so we have to parse them separately here and add them to the required_addons vector.
*/
for(const config& mod : game.child_range("modification")) {
parse_requirements(mod, "addon_id");
}

if(!game["mp_era"].empty()) {
Expand Down

0 comments on commit 43b3c9a

Please sign in to comment.