mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-31 12:01:47 +00:00
I have been trying to load Tram station to show Lemon the smoother tram for a few hours now only to find out someone broke things big time. I'm adding a sanitize_filepath proc to fix the flunky. For those ignorant about the issue: Someone has recently modified the procs in the string_list file so they'd sanitize filenames, as a security precaution. Unfortunately, it turns out these procs are also used with filepaths as argument, which use the / as a delimiter between nodes. Because the SANITIZE_FILENAME macro also purges delimiters (it's supposed to be used on filenames, not paths), this meant file paths were not being loaded correctly. Basically, it has broken map rotation, tcg and wound strings. At least the server hasn't been updated yet. Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
46 lines
1.6 KiB
Plaintext
46 lines
1.6 KiB
Plaintext
#define pick_list(FILE, KEY) (pick(strings(FILE, KEY)))
|
|
#define pick_list_weighted(FILE, KEY) (pick_weight(strings(FILE, KEY)))
|
|
#define pick_list_replacements(FILE, KEY) (strings_replacement(FILE, KEY))
|
|
#define json_load(FILE) (json_decode(file2text(FILE)))
|
|
|
|
GLOBAL_LIST(string_cache)
|
|
GLOBAL_VAR(string_filename_current_key)
|
|
|
|
|
|
/proc/strings_replacement(filepath, key)
|
|
filepath = sanitize_filepath(filepath)
|
|
load_strings_file(filepath)
|
|
|
|
if((filepath in GLOB.string_cache) && (key in GLOB.string_cache[filepath]))
|
|
var/response = pick(GLOB.string_cache[filepath][key])
|
|
var/regex/r = regex("@pick\\((\\D+?)\\)", "g")
|
|
response = r.Replace(response, /proc/strings_subkey_lookup)
|
|
return response
|
|
else
|
|
CRASH("strings list not found: [STRING_DIRECTORY]/[filepath], index=[key]")
|
|
|
|
/proc/strings(filepath as text, key as text)
|
|
filepath = sanitize_filepath(filepath)
|
|
load_strings_file(filepath)
|
|
if((filepath in GLOB.string_cache) && (key in GLOB.string_cache[filepath]))
|
|
return GLOB.string_cache[filepath][key]
|
|
else
|
|
CRASH("strings list not found: [STRING_DIRECTORY]/[filepath], index=[key]")
|
|
|
|
/proc/strings_subkey_lookup(match, group1)
|
|
return pick_list(GLOB.string_filename_current_key, group1)
|
|
|
|
/proc/load_strings_file(filepath)
|
|
filepath = sanitize_filepath(filepath) // in case we're called directly
|
|
GLOB.string_filename_current_key = filepath
|
|
if(filepath in GLOB.string_cache)
|
|
return //no work to do
|
|
|
|
if(!GLOB.string_cache)
|
|
GLOB.string_cache = new
|
|
|
|
if(fexists("[STRING_DIRECTORY]/[filepath]"))
|
|
GLOB.string_cache[filepath] = json_load("[STRING_DIRECTORY]/[filepath]")
|
|
else
|
|
CRASH("file not found: [STRING_DIRECTORY]/[filepath]")
|