Skip to content

Commit

Permalink
fix require_scenario & require_era
Browse files Browse the repository at this point in the history
previously both were broken:
1) 'require_scenario' was only checked if the scenario was installed
which obviously doesn't make any sense at all.
2) 'require_scenario' was read from the local scenario data instead from
the remote scenario.
3) 'require_era' was only checked when the scenario was not installed,
so people who do have an outated version of the era installed could not
join bacause it assumed require_era=yes in that case.
4) the server tried to read 'require_scenario' from the wrong wml node,
'require_scenario' is an attribute of [scenario] and not of savefile
toplevel.

(cherry-picked from commit eec8b67)
  • Loading branch information
gfgtdf committed Oct 7, 2018
1 parent 0181625 commit b5b1065
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/game_initialization/lobby_data.cpp
Expand Up @@ -259,17 +259,20 @@ game_info::game_info(const config& game, const std::vector<std::string>& install

if(!game["mp_era"].empty()) {
const config& era_cfg = game_config.find_child("era", "id", game["mp_era"]);
const bool require = game["require_era"].to_bool(true);
if(era_cfg) {
era = era_cfg["name"].str();
era_short = era_cfg["short_name"].str();
if(era_short.empty()) {
era_short = make_short_name(era);
}

ADDON_REQ result = check_addon_version_compatibility(era_cfg, game);
addons_outcome = std::max(addons_outcome, result); // Elevate to most severe error level encountered so far
if(require) {
ADDON_REQ result = check_addon_version_compatibility(era_cfg, game);
addons_outcome = std::max(addons_outcome, result); // Elevate to most severe error level encountered so far
}
} else {
have_era = !game["require_era"].to_bool(true);
have_era = !require;
era = game["mp_era_name"].str();
era_short = make_short_name(era);
verified = false;
Expand Down Expand Up @@ -339,6 +342,7 @@ game_info::game_info(const config& game, const std::vector<std::string>& install
if(!game["mp_scenario"].empty() && game["mp_campaign"].empty()) {
// Check if it's a multiplayer scenario
const config* level_cfg = &game_config.find_child("multiplayer", "id", game["mp_scenario"]);
const bool require = game["require_scenario"].to_bool(false);

// Check if it's a user map
if(!*level_cfg) {
Expand Down Expand Up @@ -371,11 +375,14 @@ game_info::game_info(const config& game, const std::vector<std::string>& install
}
}

if((*level_cfg)["require_scenario"].to_bool(false)) {
if(require) {
ADDON_REQ result = check_addon_version_compatibility((*level_cfg), game);
addons_outcome = std::max(addons_outcome, result); // Elevate to most severe error level encountered so far
}
} else {
if(require) {
addons_outcome = std::max(addons_outcome, NEED_DOWNLOAD); // Elevate to most severe error level encountered so far
}
scenario = formatter() << make_game_type_marker(_("scenario_abbreviation^S"), true) << game["mp_scenario_name"].str();
info_stream << scenario;
verified = false;
Expand Down
9 changes: 6 additions & 3 deletions src/server/server.cpp
Expand Up @@ -1553,8 +1553,11 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
// Update the game's description.
// If there is no shroud, then tell players in the lobby
// what the map looks like
const simple_wml::node& s = *wesnothd::game::starting_pos(g.level().root());
// fixme: the hanlder of [store_next_scenario] below searches for 'mp_shroud' in [scenario]
// at least of the these cosed is likely wrong.
if(!data["mp_shroud"].to_bool()) {
desc.set_attr_dup("map_data", (*wesnothd::game::starting_pos(data.root()))["map_data"]);
desc.set_attr_dup("map_data", s["map_data"]);
}

if(const simple_wml::node* e = data.child("era")) {
Expand All @@ -1563,7 +1566,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
}
}

if(data.attr("require_scenario").to_bool(false)) {
if(s["require_scenario"].to_bool(false)) {
desc.set_attr("require_scenario", "yes");
}

Expand Down Expand Up @@ -1658,7 +1661,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
}
}

if(data.attr("require_scenario").to_bool(false)) {
if(s["require_scenario"].to_bool(false)) {
desc.set_attr("require_scenario", "yes");
}

Expand Down

0 comments on commit b5b1065

Please sign in to comment.