From 06ea7de46b5738d2bac13d0e5110eb98b4c399fd Mon Sep 17 00:00:00 2001 From: deathride58 Date: Mon, 13 May 2019 21:49:33 -0400 Subject: [PATCH] [S] Fixes a fairly huge vector for server crashes --- code/__DEFINES/misc.dm | 4 +++- code/modules/client/preferences.dm | 6 ++++++ code/modules/client/preferences_savefile.dm | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index 709a4daeba..be58b64f41 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -474,4 +474,6 @@ GLOBAL_LIST_INIT(pda_styles, list(MONO, VT, ORBITRON, SHARE)) #define CLIENT_FROM_VAR(I) (ismob(I) ? I:client : (istype(I, /client) ? I : (istype(I, /datum/mind) ? I:current?:client : null))) #define AREASELECT_CORNERA "corner A" -#define AREASELECT_CORNERB "corner B" \ No newline at end of file +#define AREASELECT_CORNERB "corner B" + +#define PREF_SAVELOAD_COOLDOWN 5 \ No newline at end of file diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index b1ab4e6886..8e4891fb70 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -21,6 +21,12 @@ GLOBAL_LIST_EMPTY(preferences_datums) var/last_ip var/last_id + //Cooldowns for saving/loading. These are four are all separate due to loading code calling these one after another + var/saveprefcooldown + var/loadprefcooldown + var/savecharcooldown + var/loadcharcooldown + //game-preferences var/lastchangelog = "" //Saved changlog filesize to detect if there was a change var/ooccolor = null diff --git a/code/modules/client/preferences_savefile.dm b/code/modules/client/preferences_savefile.dm index 6d165bc531..39b44f1ab9 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -58,6 +58,11 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car /datum/preferences/proc/load_preferences() if(!path) return 0 + if(world.time < loadprefcooldown) + if(istype(parent)) + to_chat(parent, "You're attempting to load your preferences a little too fast. Wait half a second, then try again.") + return 0 + loadprefcooldown = world.time + PREF_SAVELOAD_COOLDOWN if(!fexists(path)) return 0 @@ -152,6 +157,11 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car /datum/preferences/proc/save_preferences() if(!path) return 0 + if(world.time < saveprefcooldown) + if(istype(parent)) + to_chat(parent, "You're attempting to save your preferences a little too fast. Wait half a second, then try again.") + return 0 + saveprefcooldown = world.time + PREF_SAVELOAD_COOLDOWN var/savefile/S = new /savefile(path) if(!S) return 0 @@ -204,6 +214,11 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car /datum/preferences/proc/load_character(slot) if(!path) return 0 + if(world.time < loadcharcooldown) //This is before the check to see if the filepath exists to ensure that BYOND can't get hung up on read attempts when the hard drive is a little slow + if(istype(parent)) + to_chat(parent, "You're attempting to load your character a little too fast. Wait half a second, then try again.") + return "SLOW THE FUCK DOWN" //the reason this isn't null is to make sure that people don't have their character slots overridden by random chars if they accidentally double-click a slot + loadcharcooldown = world.time + PREF_SAVELOAD_COOLDOWN if(!fexists(path)) return 0 var/savefile/S = new /savefile(path) @@ -418,6 +433,11 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car /datum/preferences/proc/save_character() if(!path) return 0 + if(world.time < savecharcooldown) + if(istype(parent)) + to_chat(parent, "You're attempting to save your character a little too fast. Wait half a second, then try again.") + return 0 + savecharcooldown = world.time + PREF_SAVELOAD_COOLDOWN var/savefile/S = new /savefile(path) if(!S) return 0