Opened 8 years ago

Last modified 4 years ago

#3883 closed defect

[PATCH] Persist match settings should only save some settings — at Version 14

Reported by: elexis Owned by: Imarok
Priority: Must Have Milestone: Alpha 24
Component: UI – Game setup Keywords: patch
Cc: Patch:

Description (last modified by elexis)

Currently the persist-matchsettings function (see gamesetup.js) store all mapsettings and load it the nexttime.

But some tags shouldn't be saved.

  • For example this author tag removed in r17980 was present in every replay due to this bug once the map was started once.
  • Another example is DisabledTemplates. Belgian Uplands is the only map that disables the ptolemian lighthouse. But the persistmatchsettings will save this value and when selecting a map that doesn't set it, it actually disables them due to the remains in the persistmatchsettings-file.

Only known settings (which can be changed by the host) should be restored - every other setting ignored (notice on skirmish and scenario maps, less settings can be changed).

As mentioned in comment:7, this issue is not limited to persist-matchsettings but also applies to selecting maps itself.

Change History (25)

by elexis, 8 years ago

Attachment: roughsketch.patch added

In order to remove unintended tags, loadPersistMatchSettings() in gamesetup.js needs to delete all properties of the attrs object which can't be changed by the user.

comment:1 by Imarok, 8 years ago

Is this patch not working or is something missing? Are you working on this patch? If not I would try to make a patch/finish your patch.

comment:2 by elexis, 8 years ago

The patch is only a rough sketch of how I imagine this specific thing to work. It should only load settings from that file that are allowed by a whitelist. The construction of the whitelist depends on the maptype (as the user can't change all settings on skirmish/scenario maps for example) and is not correct nor complete in that patch. Knock yourself out on that one.

comment:3 by Imarok, 8 years ago

Owner: set to Imarok

by Imarok, 8 years ago

Only restore the settings the user can change (Based on elexis' roughsketch.patch)

comment:4 by Imarok, 8 years ago

Keywords: review patch added
Summary: Persist match settings should only save some settings[PATCH] Persist match settings should only save some settings

comment:5 by elexis, 8 years ago

Settings like ceasefire can be changed on both skirmish and random maps. So you should add those only once if mapType == "skirmish" || mapType == "random". This way you omit the duplicate array entries.

by Imarok, 8 years ago

omit duplicate array entries

by Imarok, 8 years ago

cleanup

by Imarok, 8 years ago

added one parenthesis, because ! has a higher precedence then ... in ...

by Imarok, 8 years ago

by Imarok, 8 years ago

by Imarok, 8 years ago

comment:6 by Imarok, 8 years ago

Milestone: BacklogAlpha 21

by Imarok, 8 years ago

Removed an else and added the ugly !! ;)

comment:7 by elexis, 8 years ago

Keywords: review removed

For the persist-match-settings, the patch seems okay.

However the problem described in the ticket is bigger, as the examples mentioned also occur when changing the map. selectMap basically persists matchsettings as well.

For example pick the random map "belgian uplands". By typing warn(uneval(g_GameAttributes.settings.DisabledTemplate)); to the JS console, you will see that the ptolemian lighthouse is disabled. If you change to a different map, that attribute will still be remaining, even if the map does not specify it.

The whitelist-filter should become a global function that is used by both selectMap and loadPersistMatchSettings. Be careful as there might be some pitfalls.

by Imarok, 8 years ago

remove the settings the user can not change also when changing the map

comment:8 by Imarok, 8 years ago

Keywords: review added

by Imarok, 8 years ago

removed some unneeded code and renamed cleanUpSettings

comment:9 by wraitii, 8 years ago

Any reason for the "load file" comment and the !! thing?

comment:10 by elexis, 8 years ago

The idea behind the !! was to not have the RatingEnabled variable in the gameattributes if its not true. So it would be undefined and thus throw an error without !!.

comment:11 by elexis, 8 years ago

  • With the latest sketch of #3994 we can nicely decide whether a given setting can be changed on a maptype, so that one array would become obsolescent.
  • I'm not completely excited about the fact that we check whether the option can be changed, but that we don't test whether the option can actually be changed to the given attribute.

The linked rewrite also doesn't provide a method to derive the changed attribute from the gameAttributes name (with which one could call the dropdown methods to verify the integrity of that setting). In #3806 you run into the exact same issue.

Using a mapping g_GameAttributes.settings.PlayerData[i].Color -> playerColorPicker to do that seems ugly.

A hopefully less ugly alternative is to change the persist-matchsettings to not save gameattributes directly but only the current GUI object names and the values it sets things to, for example `[{"mapType":"skirmish"}, {"playerColor": "red", "idx": 4}, {"mapSize": 320}].

in reply to:  11 comment:12 by Imarok, 8 years ago

Replying to elexis:

A hopefully less ugly alternative is to change the persist-matchsettings to not save gameattributes directly but only the current GUI object names and the values it sets things to, for example `[{"mapType":"skirmish"}, {"playerColor": "red", "idx": 4}, {"mapSize": 320}].

This sounds like a very good idea. Also increases readability of stored settings

comment:13 by elexis, 8 years ago

Keywords: review removed

Removing review as we would have to rewrite the specific code again if we also want to check for the integrity of the values, though the patch probably works as advertized and solves the original issues reported in the ticket. If #3806 will fail for any reason, we can take another look, but the rewrite should be merged asap.

comment:14 by elexis, 8 years ago

Description: modified (diff)

Same as #2803

Note: See TracTickets for help on using tickets.