Skip to content

Commit

Permalink
lock handling (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob authored Nov 12, 2023
1 parent 650d293 commit f7af5ef
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
4 changes: 4 additions & 0 deletions code/controllers/configuration/entries/general.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion code/game/objects/effects/landmarks/freed_mob_spawner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
69 changes: 58 additions & 11 deletions code/modules/client/preferences_savefile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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)
Expand All @@ -115,10 +115,27 @@
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."))

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 = "/"

S["version"] >> savefile_version
Expand Down Expand Up @@ -297,6 +314,8 @@

S["remembered_key_bindings"] << GLOB.keybindings_by_name

S.Unlock()

if(toggles_chat & SHOW_TYPING)
owner.typing_indicators = FALSE
else
Expand All @@ -313,6 +332,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
Expand Down Expand Up @@ -399,15 +421,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
Expand Down Expand Up @@ -485,6 +521,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)
Expand Down Expand Up @@ -556,9 +594,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
Expand Down Expand Up @@ -630,7 +675,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()
Expand Down

0 comments on commit f7af5ef

Please sign in to comment.