From 993440210257e3d244a59e3169e6f535b370b58b Mon Sep 17 00:00:00 2001 From: harryob <55142896+harryob@users.noreply.github.com> Date: Tue, 7 Nov 2023 13:51:42 +0000 Subject: [PATCH 1/3] lock handling --- .../configuration/entries/general.dm | 4 ++ code/modules/client/preferences_savefile.dm | 62 +++++++++++++++---- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm index 4e0fb9422c..4ff82381f9 100644 --- a/code/controllers/configuration/entries/general.dm +++ b/code/controllers/configuration/entries/general.dm @@ -612,3 +612,7 @@ This maintains a list of ip addresses that are able to bypass topic filtering. protection = CONFIG_ENTRY_HIDDEN|CONFIG_ENTRY_LOCKED /datum/config_entry/flag/guest_ban + +/datum/config_entry/string/playersave_path + config_entry_value = "data/player_saves" + protection = CONFIG_ENTRY_HIDDEN|CONFIG_ENTRY_LOCKED diff --git a/code/modules/client/preferences_savefile.dm b/code/modules/client/preferences_savefile.dm index aa02e580b5..abb76dc362 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -94,7 +94,7 @@ /datum/preferences/proc/load_path(ckey,filename="preferences.sav") if(!ckey) return - path = "data/player_saves/[copytext(ckey,1,2)]/[ckey]/[filename]" + path = "[CONFIG_GET(string/playersave_path)]/[copytext(ckey,1,2)]/[ckey]/[filename]" savefile_version = SAVEFILE_VERSION_MAX /proc/sanitize_keybindings(value) @@ -108,10 +108,20 @@ return base_bindings /datum/preferences/proc/load_preferences() - if(!path) return 0 - if(!fexists(path)) return 0 + if(!path) + return FALSE + + if(!fexists(path)) + return FALSE + var/savefile/S = new /savefile(path) - if(!S) return 0 + if(!S) + return FALSE + + if(!S.Lock()) + to_chat(owner, SPAN_BOLDWARNING("Failed to load your preferences file - it may be in use by another process. Please try again.")) + return FALSE + S.cd = "/" S["version"] >> savefile_version @@ -290,6 +300,8 @@ S["remembered_key_bindings"] << GLOB.keybindings_by_name + S.Unlock() + if(toggles_chat & SHOW_TYPING) owner.typing_indicators = FALSE else @@ -306,6 +318,9 @@ var/savefile/S = new /savefile(path) if(!S) return FALSE + if(!S.Lock()) + to_chat(owner, SPAN_BOLDWARNING("Failed to save your preferences file - it may be in use by another process. Please try again.")) + return FALSE S.cd = "/" S["version"] << savefile_version @@ -392,15 +407,29 @@ S["no_radial_labels_preference"] << no_radial_labels_preference S["custom_cursors"] << custom_cursors + S.Unlock() + return TRUE /datum/preferences/proc/load_character(slot) - if(!path) return 0 - if(!fexists(path)) return 0 + if(!path) + return FALSE + + if(!fexists(path)) + return FALSE + var/savefile/S = new /savefile(path) - if(!S) return 0 + if(!S) + return FALSE + + if(!S.Lock()) + to_chat(owner, SPAN_BOLDWARNING("Failed to load your character slot - it may be in use by another process. Please try again.")) + return FALSE + S.cd = "/" - if(!slot) slot = default_slot + + if(!slot) + slot = default_slot slot = sanitize_integer(slot, 1, MAX_SAVE_SLOTS, initial(default_slot)) if(slot != default_slot) default_slot = slot @@ -478,6 +507,8 @@ S["uplinklocation"] >> uplinklocation S["exploit_record"] >> exploit_record + S.Unlock() + //Sanitize metadata = sanitize_text(metadata, initial(metadata)) real_name = reject_bad_name(real_name) @@ -549,9 +580,16 @@ return 1 /datum/preferences/proc/save_character() - if(!path) return 0 + if(!path) + return FALSE var/savefile/S = new /savefile(path) - if(!S) return 0 + if(!S) + return FALSE + + if(!S.Lock()) + to_chat(owner, SPAN_BOLDWARNING("Failed to save your character slot - it may be in use by another process. Please try again.")) + return FALSE + S.cd = "/character[default_slot]" //Character @@ -623,7 +661,9 @@ S["uplinklocation"] << uplinklocation S["exploit_record"] << exploit_record - return 1 + S.Unlock() + + return TRUE /// checks through keybindings for outdated unbound keys and updates them /datum/preferences/proc/check_keybindings() From 158409681b7c5c8dfd60e1ce73d30194d63f6e9f Mon Sep 17 00:00:00 2001 From: harryob <55142896+harryob@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:02:37 +0000 Subject: [PATCH 2/3] retry on failure --- code/modules/client/preferences_savefile.dm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/code/modules/client/preferences_savefile.dm b/code/modules/client/preferences_savefile.dm index abb76dc362..bbd82dbcbb 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -119,7 +119,14 @@ return FALSE if(!S.Lock()) - to_chat(owner, SPAN_BOLDWARNING("Failed to load your preferences file - it may be in use by another process. Please try again.")) + to_chat(owner, SPAN_BOLDWARNING("Failed to load your preferences file. It may be in use by another process. Please try again.")) + + var/options = tgui_alert(owner, "Failed to load your preferences file. It may be in use by another process. Please try again.", "Failed to Load", list("Retry", "Disconnect"), timeout = FALSE) + if(options != "Retry") + qdel(owner, force = TRUE) + return FALSE + + load_preferences() return FALSE S.cd = "/" From 9ac128a684a12bd7dd228c33a170589879bed240 Mon Sep 17 00:00:00 2001 From: harryob <55142896+harryob@users.noreply.github.com> Date: Thu, 9 Nov 2023 04:06:55 +0000 Subject: [PATCH 3/3] marks freed mob spawners as async --- code/game/objects/effects/landmarks/freed_mob_spawner.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/game/objects/effects/landmarks/freed_mob_spawner.dm b/code/game/objects/effects/landmarks/freed_mob_spawner.dm index c0e34eed54..7841e99df2 100644 --- a/code/game/objects/effects/landmarks/freed_mob_spawner.dm +++ b/code/game/objects/effects/landmarks/freed_mob_spawner.dm @@ -6,7 +6,7 @@ /obj/effect/landmark/freed_mob_spawner/Initialize() . = ..() - spawn_freed_mob() + INVOKE_ASYNC(src, PROC_REF(spawn_freed_mob)) return INITIALIZE_HINT_QDEL /obj/effect/landmark/freed_mob_spawner/Destroy()