From 9143d5077a4220d30061d8fdea0ad64548488523 Mon Sep 17 00:00:00 2001 From: skull132 Date: Mon, 7 Mar 2016 19:00:28 +0200 Subject: [PATCH] webint_procs.dm Initial Commit Starting to create a bit of a library to hold functions related to the web interface. --- baystation12.dme | 1 + code/modules/web_interface/webint_procs.dm | 35 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 code/modules/web_interface/webint_procs.dm diff --git a/baystation12.dme b/baystation12.dme index aede49368ad..7b37efa3483 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -1715,6 +1715,7 @@ #include "code\modules\virus2\helpers.dm" #include "code\modules\virus2\isolator.dm" #include "code\modules\virus2\items_devices.dm" +#include "code\modules\web_interface\webint_procs.dm" #include "code\TriDimension\controller.dm" #include "code\TriDimension\controller_presets.dm" #include "code\TriDimension\Movement.dm" diff --git a/code/modules/web_interface/webint_procs.dm b/code/modules/web_interface/webint_procs.dm new file mode 100644 index 00000000000..236a0ae0623 --- /dev/null +++ b/code/modules/web_interface/webint_procs.dm @@ -0,0 +1,35 @@ +/* + * Contains general purpose procs used with Aurora's web interface and related functions. + */ + +/* + * /proc/validate_webint_attributes() + * Used to validate parametres sent to procs that are meant to communicate with the web interface. + * Most commonly in Topic() calls, so that href tomfoolery is negated. + * + * Arguments: + * - var/list/required_attributes - A list of required attributes. This is what the other arguments will be tested against. Cannot be null. + * - var/list/attributes_list - The attributes to be validated, passed in a list form. Can be null. + * - var/attributes_text - The attributes to be validated, passed in a text form. (Formatted according to list2params() convention.) + * This overrides attributes_list if both are present. Can be null. + * + * Returns: + * 1 - if all required attributes are present, and no erronious ones exist. + * 0 - if certain required attributes are missing, or there are extras. + */ + +/proc/webint_validate_attributes(var/list/required_attributes, var/list/attributes_list, var/attributes_text) + if (!required_attributes || !istype(required_attributes) || !required_attributes.len) + return 0 + + if (attributes_text) + attributes_list = params2list(attributes_text) + + if (!attributes_list || !attributes_list.len) + return 0 + + for (var/attribute in attributes_list) + if (!(attribute in required_attributes)) + return 0 + + return 1