Merge branch 'master' into upstream-merge-13193

This commit is contained in:
Nadyr
2022-07-19 20:17:40 -04:00
committed by GitHub
348 changed files with 9156 additions and 2314 deletions

View File

@@ -217,6 +217,17 @@ This actually tests if they have the same entries and values.
return 0
return 1
/*
Checks if a list has the same entries and values as an element of big.
*/
/proc/in_as_list(var/list/little, var/list/big)
if(!islist(big))
return 0
for(var/element in big)
if(same_entries(little, element))
return 1
return 0
/*
* Returns list containing entries that are in either list but not both.
* If skipref = 1, repeated elements are treated as one.
@@ -870,4 +881,3 @@ var/global/list/json_cache = list()
else
used_key_list[input_key] = 1
return input_key

View File

@@ -6,6 +6,16 @@
return number
return default
// Checks if the given input is a valid list index; returns true/false and doesn't change anything.
/proc/is_valid_index(input, list/given_list)
if(!isnum(input))
return FALSE
if(input != round(input))
return FALSE
if(input < 1 || input > length(given_list))
return FALSE
return TRUE
/proc/sanitize_text(text, default="")
if(istext(text))
return text
@@ -44,3 +54,60 @@
if(65 to 70) . += ascii2text(ascii+32) //letters A to F - translates to lowercase
else return default
return .
//Valid format codes: YY, YEAR, MM, DD, hh, mm, ss, :, -. " " (space). Invalid format will return default.
/proc/sanitize_time(time, default, format = "hh:mm")
if(!istext(time) || !(length(time) == length(format)))
return default
var/fragment = ""
. = list()
for(var/i = 1, i <= length(format), i++)
fragment += copytext(format,i,i+1)
if(fragment in list("YY", "YEAR", "MM", "DD", "hh", "mm", "ss"))
. += sanitize_one_time(copytext(time, i - length(fragment) + 1, i + 1), copytext(default, i - length(fragment) + 1, i + 1), fragment)
fragment = ""
else if(fragment in list(":", "-", " "))
. += fragment
fragment = ""
if(fragment)
return default //This means the format was improper.
return JOINTEXT(.)
//Internal proc, expects valid format and text input of equal length to format.
/proc/sanitize_one_time(input, default, format)
var/list/ainput = list()
for(var/i = 1, i <= length(input), i++)
ainput += text2ascii(input, i)
switch(format)
if("YY")
if(!(ainput[1] in 48 to 57) || !(ainput[2] in 48 to 57))//0 to 9
return (default || "00")
return input
if("YEAR")
for(var/i = 1, i <= 4, i++)
if(!(ainput[i] in 48 to 57))//0 to 9
return (default || "0000")
return input
if("MM")
var/early = (ainput[1] == 48) && (ainput[2] in 49 to 57) //01 to 09
var/late = (ainput[1] == 49) && (ainput[2] in 48 to 50) //10 to 12
if(!(early || late))
return (default || "01")
return input
if("DD")
var/early = (ainput[1] == 48) && (ainput[2] in 49 to 57) //01 to 09
var/mid = (ainput[1] in 49 to 50) && (ainput[2] in 48 to 57) //10 to 29
var/late = (ainput[1] == 51) && (ainput[2] in 48 to 49) //30 to 31
if(!(early || mid || late))
return (default || "01")
return input
if("hh")
var/early = (ainput[1] in 48 to 49) && (ainput[2] in 48 to 57) //00 to 19
var/late = (ainput[1] == 50) && (ainput[2] in 48 to 51) //20 to 23
if(!(early || late))
return (default || "00")
return input
if("mm", "ss")
if(!(ainput[1] in 48 to 53) || !(ainput[2] in 48 to 57)) //0 to 5, 0 to 9
return (default || "00")
return input

View File

@@ -410,6 +410,58 @@
t = replacetext(t, "\[editorbr\]", "")
return t
//pencode translation to html for tags exclusive to digital files (currently email, nanoword, report editor fields,
//modular scanner data and txt file printing) and prints from them
/proc/digitalPencode2html(var/text)
text = replacetext(text, "\[pre\]", "<pre>")
text = replacetext(text, "\[/pre\]", "</pre>")
text = replacetext(text, "\[fontred\]", "<font color=\"red\">") //</font> to pass html tag integrity unit test
text = replacetext(text, "\[fontblue\]", "<font color=\"blue\">")//</font> to pass html tag integrity unit test
text = replacetext(text, "\[fontgreen\]", "<font color=\"green\">")
text = replacetext(text, "\[/font\]", "</font>")
text = replacetext(text, "\[redacted\]", "<span class=\"redacted\">R E D A C T E D</span>")
return pencode2html(text)
//Will kill most formatting; not recommended.
/proc/html2pencode(t)
t = replacetext(t, "<pre>", "\[pre\]")
t = replacetext(t, "</pre>", "\[/pre\]")
t = replacetext(t, "<font color=\"red\">", "\[fontred\]")//</font> to pass html tag integrity unit test
t = replacetext(t, "<font color=\"blue\">", "\[fontblue\]")//</font> to pass html tag integrity unit test
t = replacetext(t, "<font color=\"green\">", "\[fontgreen\]")
t = replacetext(t, "</font>", "\[/font\]")
t = replacetext(t, "<BR>", "\[br\]")
t = replacetext(t, "<br>", "\[br\]")
t = replacetext(t, "<B>", "\[b\]")
t = replacetext(t, "</B>", "\[/b\]")
t = replacetext(t, "<I>", "\[i\]")
t = replacetext(t, "</I>", "\[/i\]")
t = replacetext(t, "<U>", "\[u\]")
t = replacetext(t, "</U>", "\[/u\]")
t = replacetext(t, "<center>", "\[center\]")
t = replacetext(t, "</center>", "\[/center\]")
t = replacetext(t, "<H1>", "\[h1\]")
t = replacetext(t, "</H1>", "\[/h1\]")
t = replacetext(t, "<H2>", "\[h2\]")
t = replacetext(t, "</H2>", "\[/h2\]")
t = replacetext(t, "<H3>", "\[h3\]")
t = replacetext(t, "</H3>", "\[/h3\]")
t = replacetext(t, "<li>", "\[*\]")
t = replacetext(t, "<HR>", "\[hr\]")
t = replacetext(t, "<ul>", "\[list\]")
t = replacetext(t, "</ul>", "\[/list\]")
t = replacetext(t, "<table>", "\[grid\]")
t = replacetext(t, "</table>", "\[/grid\]")
t = replacetext(t, "<tr>", "\[row\]")
t = replacetext(t, "<td>", "\[cell\]")
t = replacetext(t, "<img src = ntlogo.png>", "\[logo\]")
t = replacetext(t, "<img src = redntlogo.png>", "\[redlogo\]")
t = replacetext(t, "<img src = sglogo.png>", "\[sglogo\]")
t = replacetext(t, "<span class=\"paper_field\"></span>", "\[field\]")
t = replacetext(t, "<span class=\"redacted\">R E D A C T E D</span>", "\[redacted\]")
t = strip_html_properly(t)
return t
// Random password generator
/proc/GenerateKey()
//Feel free to move to Helpers.

View File

@@ -18,7 +18,8 @@
continue
if(vent.welded)
continue
if(istype(get_area(vent), /area/crew_quarters/sleep)) //No going to dorms
var/area/A = get_area(vent)
if(A.forbid_events)
continue
vent_list += vent
if(!vent_list.len)