From 6c2a6e8d647a98ea8b1967aacc7bdad9bd8d3ced Mon Sep 17 00:00:00 2001 From: AnturK Date: Sun, 7 Jul 2019 21:28:21 +0200 Subject: [PATCH] Supresses policy file runtime but messages admins about it. --- code/__HELPERS/text.dm | 7 +++++++ code/controllers/configuration/configuration.dm | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index 3ab97a8634e..e5292fd25e5 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -819,3 +819,10 @@ GLOBAL_LIST_INIT(binary, list("0","1")) #define is_alpha(X) ((text2ascii(X) <= 122) && (text2ascii(X) >= 97)) #define is_digit(X) ((length(X) == 1) && (length(text2num(X)) == 1)) + +//json decode that will return null on parse error instead of runtiming. +/proc/safe_json_decode(data) + try + return json_decode(data) + catch + return \ No newline at end of file diff --git a/code/controllers/configuration/configuration.dm b/code/controllers/configuration/configuration.dm index 3453669ac51..5d012bceff5 100644 --- a/code/controllers/configuration/configuration.dm +++ b/code/controllers/configuration/configuration.dm @@ -154,7 +154,7 @@ var/good_update = istext(new_value) log_config("Entry [entry] is deprecated and will be removed soon. Migrate to [new_ver.name]![good_update ? " Suggested new value is: [new_value]" : ""]") if(!warned_deprecated_configs) - addtimer(CALLBACK(GLOBAL_PROC, /proc/message_admins, "This server is using deprecated configuration settings. Please check the logs and update accordingly."), 0) + DelayedMessageAdmins("This server is using deprecated configuration settings. Please check the logs and update accordingly.") warned_deprecated_configs = TRUE if(good_update) value = new_value @@ -271,9 +271,10 @@ Example config: policy = list() var/rawpolicy = file2text("[directory]/policy.json") if(rawpolicy) - var/parsed = json_decode(rawpolicy) + var/parsed = safe_json_decode(rawpolicy) if(!parsed) log_config("JSON parsing failure for policy.json") + DelayedMessageAdmins("JSON parsing failure for policy.json") else policy = parsed @@ -417,3 +418,7 @@ Example config: ic_filter_regex = in_character_filter.len ? regex("\\b([jointext(in_character_filter, "|")])\\b", "i") : null syncChatRegexes() + +//Message admins when you can. +/datum/controller/configuration/proc/DelayedMessageAdmins(text) + addtimer(CALLBACK(GLOBAL_PROC, /proc/message_admins, text), 0) \ No newline at end of file