From fdf95a9bd9e2e98072b4ff34266f1b377af18622 Mon Sep 17 00:00:00 2001 From: tigercat2000 Date: Thu, 21 Jun 2018 23:35:16 -0700 Subject: [PATCH] Reenable fixed config (and also fix 511 compile) --- code/game/machinery/telecomms/ntsl2.dm | 41 +++++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/code/game/machinery/telecomms/ntsl2.dm b/code/game/machinery/telecomms/ntsl2.dm index 306d788ad6e..0bde59bce11 100644 --- a/code/game/machinery/telecomms/ntsl2.dm +++ b/code/game/machinery/telecomms/ntsl2.dm @@ -76,7 +76,7 @@ GLOBAL_DATUM_INIT(ntsl2_config, /datum/ntsl2_configuration, new()) /* Tables */ regex = list() - /* Arrays */ + /* Arrays */ firewall = list() @@ -91,23 +91,23 @@ GLOBAL_DATUM_INIT(ntsl2_config, /datum/ntsl2_configuration, new()) /datum/ntsl2_configuration/proc/ntsl_serialize() . = list() for(var/variable in to_serialize) - .[variable] = json_encode(vars[variable]) + .[variable] = vars[variable] . = json_encode(.) // This loads a configuration from a JSON string. // Fucking broken as shit, someone help me fix this. -// /datum/ntsl2_configuration/proc/ntsl_deserialize(text, obj/machinery/computer/telecomms/traffic/source) -// var/list/var_list = json_decode(text) -// for(var/variable in var_list) -// if(variable in to_serialize) // Don't just accept any random vars jesus christ! -// if(requires_unlock[variable] && (source && !source.unlocked)) -// continue -// var/sanitize_method = serialize_sanitize[variable] -// var/variable_value = var_list[variable] -// variable_value = sanitize(variable_value, sanitize_method) -// if(variable_value) -// vars[variable] = var_list[variable_value] +/datum/ntsl2_configuration/proc/ntsl_deserialize(text, obj/machinery/computer/telecomms/traffic/source) + var/list/var_list = json_decode(text) + for(var/variable in var_list) + if(variable in to_serialize) // Don't just accept any random vars jesus christ! + if(requires_unlock[variable] && (source && !source.unlocked)) + continue + var/sanitize_method = serialize_sanitize[variable] + var/variable_value = var_list[variable] + variable_value = sanitize(variable_value, sanitize_method) + if(variable_value) + vars[variable] = variable_value // Sanitizing user input. Don't blindly trust the JSON. /datum/ntsl2_configuration/proc/sanitize(variable, sanitize_method) @@ -160,7 +160,8 @@ GLOBAL_DATUM_INIT(ntsl2_config, /datum/ntsl2_configuration, new()) // Replace everything with HONK! if(toggle_honk) - var/honklength = splittext(signal.data["message"], " ").len + var/list/split = splittext(signal.data["message"], " ") + var/honklength = split.len var/new_message = "" for(var/i in 1 to honklength) new_message += pick("HoNK!", "HONK", "HOOOoONK", "HONKHONK!", "HoNnnkKK!!!", "HOOOOOOOOOOONK!!!!11!", "henk!") @@ -228,14 +229,16 @@ GLOBAL_DATUM_INIT(ntsl2_config, /datum/ntsl2_configuration, new()) var/new_value = input(user, "Provide a new value for the key [new_key]", "New Row") as text|null if(new_value == null) return - vars[href_list["table"]][new_key] = new_value + var/list/table = vars[href_list["table"]] + table[new_key] = new_value to_chat(user, "Added row [new_key] -> [new_value].") if(href_list["delete_row"]) if(href_list["table"] && href_list["table"] in tables) if(requires_unlock[href_list["table"]] && !source.unlocked) return - vars[href_list["table"]].Remove(href_list["delete_row"]) + var/list/table = vars[href_list["table"]] + table.Remove(href_list["delete_row"]) to_chat(user, "Removed row [href_list["delete_row"]] from [href_list["table"]]") // Arrays @@ -246,14 +249,16 @@ GLOBAL_DATUM_INIT(ntsl2_config, /datum/ntsl2_configuration, new()) var/new_value = input(user, "Provide a value for the new index.", "New Index") as text|null if(new_value == null) return - vars[href_list["array"]].Add(new_value) + var/list/array = vars[href_list["array"]] + array.Add(new_value) to_chat(user, "Added row [new_value].") if(href_list["delete_item"]) if(href_list["array"] && href_list["array"] in arrays) if(requires_unlock[href_list["array"]] && !source.unlocked) return - vars[href_list["array"]].Remove(href_list["delete_item"]) + var/list/array = vars[href_list["array"]] + array.Remove(href_list["delete_item"]) to_chat(user, "Removed [href_list["delete_item"]] from [href_list["array"]]") // Spit out the serialized config to the user