Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocd-cleanup.ash uses the wrong data file? #58

Open
pastelmind opened this issue May 23, 2021 · 1 comment
Open

ocd-cleanup.ash uses the wrong data file? #58

pastelmind opened this issue May 23, 2021 · 1 comment
Assignees
Labels
status: need more info Needs more information to progress type: bug Something isn't working

Comments

@pastelmind
Copy link
Contributor

pastelmind commented May 23, 2021

Original report copied from the ASS discord:

yo, heads up- philter's new UI is behaving SUPER DANGEROUSLY around multiple accounts
I'm not 100% sure but it looks like it's storing what data file to use globally
it definitely just tried to use the datafile for phillectric while logged in as phillammon, which is not ideal
(classic ui works fine)

I tried to reproduce the issue, but could not. But I suspect it may be related to the way relay_Philter_Manager.js runs ZLib.

How we use ZLib

  • When ocd-cleanup.ash is run for the first time, it sets the default value of BaleOCD_DataFile (a ZLib variable) to the current player's name. Let's say alice.
  • ZLib stores this default value in data/vars_defaults.txt, which is then used across all of your accounts.
    If you login as bob, your BaleOCD_DataFile would still be alice until you change it.

How ZLib works

ZLib manages two maps, vars and vardefaults.

vars is a global variable. It is loaded whenever ZLib is invoked, so it should be "fresh".

vardefaults is a static global variable. It is loaded when ZLib is invoked for the first time (per character), so it could become stale. But I cannot find evidence that it actually does go stale.

What happens when Philter Manager saves your config

  1. relay_Philter_Manager.js calls _update_Zlib_vars() with the new config values:

    export function saveCleanupConfig(config: PhilterConfig) {
    const serializedConfig: Record<string, string> = {};
    for (const key of Object.keys(config)) {
    const varName: string | undefined =
    CONFIG_NAMES[key as keyof typeof CONFIG_NAMES];
    if (varName === undefined) {
    throw new Error(`Cannot find ZLib config name for config key '${key}'`);
    }
    serializedConfig[varName] = String(config[key as keyof typeof config]);
    }
    _updateZlibVars(serializedConfig);
    }

  2. _update_Zlib_vars() updates vars if getvar(config) is different from the new value. <-- Could this be the cause? 👀
    Then it calls updatevars():

    void _update_Zlib_vars(string [string] new_vars) {
    int changed_var_count = 0;
    foreach varname, value in new_vars {
    if (getvar(varname) != value) {
    vars[varname] = value;
    ++changed_var_count;
    }
    }
    if (changed_var_count > 0) {
    updatevars();
    }
    }

  3. updatevars() compares vars and vardefaults and writes the difference to data/vars_<username>.txt

    // writes local vars map
    boolean updatevars() {
       string[string] newvars;
       foreach pref,val in vars {    // won't need this later
          if (vardefaults contains pref && val == vardefaults[pref].val) continue;
          newvars[pref] = val;
       }
       return map_to_file(newvars,"vars_"+replace_string(my_name()," ","_")+".txt");
    }
@pastelmind pastelmind added type: bug Something isn't working status: need more info Needs more information to progress labels May 23, 2021
@pastelmind pastelmind self-assigned this May 23, 2021
@Rinn
Copy link
Contributor

Rinn commented May 23, 2021

I'm pretty sure something like this has been happening for ages. I remember this being a problem so much that I added

cli_execute("zlib BaleOCD_DataFile = " + my_name());
cli_execute("zlib BaleOCD_StockFile = " + my_name());

to my login script to force the vars to be set for the current character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: need more info Needs more information to progress type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants