Skip to content

Commit

Permalink
Merge pull request #216 from MarinaGryphon/update/devmerge-01-14-2021
Browse files Browse the repository at this point in the history
January 14, 2021 Devmerge
  • Loading branch information
noelle-lavenza authored Jan 15, 2022
2 parents 54c269b + 2ad2015 commit 12259ef
Show file tree
Hide file tree
Showing 189 changed files with 629 additions and 532 deletions.
12 changes: 3 additions & 9 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
<!-- !! PLEASE, READ THIS !! -->
<!-- We recommend to check the contributing page before opening pull requests. -->
<!-- https://github.com/NebulaSS13/Nebula/blob/dev/CONTRIBUTING.md -->

<!-- !! PLEASE, READ THIS !! -->
<!-- If you opening a pull request which changes A LOT icon/map files: -->
<!-- Add [IDB IGNORE] (to ignore icon files diff) or [MDB IGNORE] (to ignore map files diff) in PR title. -->
<!-- Add [IDB IGNORE] (to ignore icon files diff) or [MDB IGNORE] (to ignore map files diff) in the PR title. -->
<!-- These tags created to prevent parsing a huge diffs and not overload IconDiffBot and MapDiffBot. -->

## Description of changes

<!-- Describe The Pull Request. Please be sure every change is documented or this can delay review and even discourage maintainers from merging your PR! -->

## Why and what will this PR improve

<!-- Please add a short description of why you think these changes would benefit the game. If you can't justify it in words, it might not be worth adding. -->

## Authorship

<!-- Describe original authors of changes to credit them. -->

## Changelog

<!-- Enter your value after first :cl: tag if you want to specify another name or several people. -->
:cl:
prefix:
/:cl:

<!-- Replace `prefix` with one of tags below. You can add more tags for multiple changelog entries.
- bugfix
- balance
- tweak
Expand All @@ -39,5 +34,4 @@ prefix:
- spellcheck
- experiment
- admin
-->
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ on:

env:
BYOND_MAJOR: "514"
BYOND_MINOR: "1566"
SPACEMAN_DMM_VERSION: suite-1.7
BYOND_MINOR: "1572"
SPACEMAN_DMM_VERSION: suite-1.7.1

jobs:
DreamChecker:
Expand Down
2 changes: 2 additions & 0 deletions code/__defines/directions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define CORNER_EASTWEST CORNER_COUNTERCLOCKWISE
#define CORNER_NORTHSOUTH CORNER_CLOCKWISE

#define FIRST_DIR(X) ((X) & -(X))

/*
turn() is weird:
turn(icon, angle) turns icon by angle degrees clockwise
Expand Down
3 changes: 3 additions & 0 deletions code/__defines/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,6 @@
#define WRITTEN_SKIP 0
#define WRITTEN_PHYSICAL 1
#define WRITTEN_DIGITAL 2

// arbitrary low pressure bound for wind weather effects
#define MIN_WIND_PRESSURE 10
4 changes: 2 additions & 2 deletions code/_global_vars/lists/names.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// All variables here use double quotes to able load information on every startup.

var/global/list/ai_names = file2list("config/names/ai.txt")
var/global/list/wizard_first = file2list("config/names/wizardfirst.txt")
var/global/list/wizard_second = file2list("config/names/wizardsecond.txt")
Expand All @@ -11,5 +13,3 @@ var/global/list/clown_names = file2list("config/names/clown.txt")

var/global/list/verbs = file2list("config/names/verbs.txt")
var/global/list/adjectives = file2list("config/names/adjectives.txt")
//loaded on startup because of "
//would include in rsc if ' was used
133 changes: 93 additions & 40 deletions code/_helpers/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
*/

// Run all strings to be used in an SQL query through this proc first to properly escape out injection attempts.
/proc/sanitizeSQL(var/t as text)
var/sqltext = dbcon.Quote(t);
return copytext(sqltext, 2, length(sqltext));//Quote() adds quotes around input, we already do that
/proc/sanitize_sql(t)
var/sqltext = dbcon.Quote("[t]") // http://www.byond.com/forum/post/2218538
return copytext(sqltext, 2, -1)

/*
* Text sanitization
*/

//Used for preprocessing entered text
//Added in an additional check to alert players if input is too long
/proc/sanitize(var/input, var/max_length = MAX_MESSAGE_LEN, var/encode = 1, var/trim = 1, var/extra = 1)
/proc/sanitize(input, max_length = MAX_MESSAGE_LEN, encode = TRUE, trim = TRUE, extra = TRUE, ascii_only = FALSE)
if(!input)
return

Expand All @@ -33,47 +33,68 @@
if(input_length > max_length)
to_chat(usr, SPAN_WARNING("Your message is too long by [input_length - max_length] character\s."))
return
input = copytext_char(input, 1, max_length + 1)
input = copytext_char(input, 1, max_length)

if(extra)
input = replace_characters(input, list("\n"=" ","\t"=" "))

if(ascii_only)
// Some procs work differently depending on unicode/ascii string
// You should always consider this with any text processing work
// More: http://www.byond.com/docs/ref/info.html#/{notes}/Unicode
// http://www.byond.com/forum/post/2520672
input = strip_non_ascii(input)
else
// Strip Unicode control/space-like chars here exept for line endings (\n,\r) and normal space (0x20)
// codes from https://www.compart.com/en/unicode/category/
// https://en.wikipedia.org/wiki/Whitespace_character#Unicode
var/static/regex/unicode_control_chars = regex(@"[\u0001-\u0009\u000B\u000C\u000E-\u001F\u007F\u0080-\u009F\u00A0\u1680\u180E\u2000-\u200D\u2028\u2029\u202F\u205F\u2060\u3000\uFEFF]", "g")
input = unicode_control_chars.Replace(input, "")

if(encode)
// The below \ escapes have a space inserted to attempt to enable unit testing of span class usage. Please do not remove the space.
//In addition to processing html, html_encode removes byond formatting codes like "\ red", "\ i" and other.
//It is important to avoid double-encode text, it can "break" quotes and some other characters.
//Also, keep in mind that escaped characters don't work in the interface (window titles, lower left corner of the main window, etc.)
// In addition to processing html, html_encode removes byond formatting codes like "\red", "\i" and other.
// It is important to avoid double-encode text, it can "break" quotes and some other characters.
// Also, keep in mind that escaped characters don't work in the interface (window titles, lower left corner of the main window, etc.)
input = html_encode(input)
else
//If not need encode text, simply remove < and >
//note: we can also remove here byond formatting codes: 0xFF + next byte
// If not need encode text, simply remove < and >
// note: we can also remove here byond formatting codes: 0xFF + next byte
input = replace_characters(input, list("<"=" ", ">"=" "))

if(trim)
//Maybe, we need trim text twice? Here and before copytext?
input = trim(input)

return input

//Run sanitize(), but remove <, >, " first to prevent displaying them as &gt; &lt; &34; in some places, after html_encode().
//Run sanitize(), but remove <, >, " first to prevent displaying them as &gt; &lt; &34; in some places after html_encode().
//Best used for sanitize object names, window titles.
//If you have a problem with sanitize() in chat, when quotes and >, < are displayed as html entites -
//this is a problem of double-encode(when & becomes &amp;), use sanitize() with encode=0, but not the sanitizeSafe()!
/proc/sanitizeSafe(var/input, var/max_length = MAX_MESSAGE_LEN, var/encode = 1, var/trim = 1, var/extra = 1)
return sanitize(replace_characters(input, list(">"=" ","<"=" ", "\""="'")), max_length, encode, trim, extra)
//this is a problem of double-encode(when & becomes &amp;), use sanitize() with encode=0, but not the sanitize_safe()!
/proc/sanitize_safe(input, max_length = MAX_MESSAGE_LEN, encode = TRUE, trim = TRUE, extra = TRUE, ascii_only = FALSE)
return sanitize(replace_characters(input, list(">"=" ","<"=" ", "\""="'")), max_length, encode, trim, extra, ascii_only)

/proc/paranoid_sanitize(t)
var/regex/alphanum_only = regex("\[^a-zA-Z0-9# ,.?!:;()]", "g")
return alphanum_only.Replace(t, "#")

//Filters out undesirable characters from names
/proc/sanitizeName(var/input, var/max_length = MAX_NAME_LEN, var/allow_numbers = 0, var/force_first_letter_uppercase = TRUE)
if(!input || length(input) > max_length)
/proc/sanitize_name(input, max_length = MAX_NAME_LEN, allow_numbers = 0, force_first_letter_uppercase = TRUE)
if(!input || length_char(input) > max_length)
return //Rejects the input if it is null or if it is longer then the max length allowed

var/number_of_alphanumeric = 0
var/last_char_group = 0
var/output = ""

for(var/i=1, i<=length(input), i++)
var/ascii_char = text2ascii(input,i)
switch(ascii_char)
var/char = ""
var/bytes_length = length(input)
var/ascii_char
for(var/i = 1, i <= bytes_length, i += length(char))
char = input[i]

ascii_char = text2ascii(char)

switch(ascii_char) //todo: unicode names?
// A .. Z
if(65 to 90) //Uppercase Letters
output += ascii2text(ascii_char)
Expand Down Expand Up @@ -121,10 +142,7 @@
if(number_of_alphanumeric < 2) return //protects against tiny names like "A" and also names like "' ' ' ' ' ' ' '"

if(last_char_group == 1)
output = copytext(output,1,length(output)) //removes the last character (in this case a space)

for(var/bad_name in list("space","floor","wall","r-wall","monkey","unknown","inactive ai","plating")) //prevents these common metagamey names
if(cmptext(output,bad_name)) return //(not case sensitive)
output = copytext(output, 1, -1) //removes the last character (in this case a space)

return output

Expand Down Expand Up @@ -213,11 +231,16 @@
* Text modification
*/

/proc/replace_characters(var/t,var/list/repl_chars)
/proc/replace_characters(t, list/repl_chars)
for(var/char in repl_chars)
t = replacetext(t, char, repl_chars[char])
return t

/proc/random_string(length, list/characters)
. = ""
for (var/i in 1 to length)
. += pick(characters)

//Adds 'u' number of zeros ahead of the text 't'
/proc/add_zero(t, u)
return pad_left(t, u, "0")
Expand All @@ -233,13 +256,13 @@
// Adds the required amount of 'character' in front of 'text' to extend the lengh to 'desired_length', if it is shorter
// No consideration are made for a multi-character 'character' input
/proc/pad_left(text, desired_length, character)
var/padding = generate_padding(length(text), desired_length, character)
var/padding = generate_padding(length_char(text), desired_length, character)
return length(padding) ? "[padding][text]" : text

// Adds the required amount of 'character' after 'text' to extend the lengh to 'desired_length', if it is shorter
// No consideration are made for a multi-character 'character' input
/proc/pad_right(text, desired_length, character)
var/padding = generate_padding(length(text), desired_length, character)
var/padding = generate_padding(length_char(text), desired_length, character)
return length(padding) ? "[text][padding]" : text

/proc/generate_padding(current_length, desired_length, character)
Expand All @@ -250,32 +273,59 @@
characters += character
return JOINTEXT(characters)


//Returns a string with reserved characters and spaces before the first letter removed
// Returns a string with reserved characters and spaces before the first letter removed
// not work for unicode spaces - you should cleanup them first with sanitize()
/proc/trim_left(text)
for (var/i = 1 to length(text))
if (text2ascii(text, i) > 32)
return copytext(text, i)
return ""

//Returns a string with reserved characters and spaces after the last letter removed
// Returns a string with reserved characters and spaces after the last letter removed
// not work for unicode spaces - you should cleanup them first with sanitize()
/proc/trim_right(text)
for (var/i = length(text), i > 0, i--)
if (text2ascii(text, i) > 32)
return copytext(text, 1, i + 1)

return ""

//Returns a string with reserved characters and spaces before the first word and after the last word removed.
// Returns a string with reserved characters and spaces before the first word and after the last word removed.
// not work for unicode spaces - you should cleanup them first with sanitize()
/proc/trim(text)
return trim_left(trim_right(text))

//Returns a string with the first element of the string capitalized.
/proc/capitalize(var/t as text)
return uppertext(copytext_char(t, 1, 2)) + copytext_char(t, 2)
/proc/capitalize(text)
if(text)
text = uppertext(text[1]) + copytext(text, 1 + length(text[1]))
return text

//Returns a string with the first element of the every word of the string capitalized.
/proc/capitalize_words(text)
var/list/S = splittext(text, " ")
var/list/M = list()
for (var/w in S)
M += capitalize(w)
return jointext(M, " ")

/proc/strip_non_ascii(text)
var/static/regex/non_ascii_regex = regex(@"[^\x00-\x7F]+", "g")
return non_ascii_regex.Replace(text, "")

/proc/strip_html_simple(t, limit = MAX_MESSAGE_LEN)
var/list/strip_chars = list("<",">")
t = copytext(t,1,limit)
for(var/char in strip_chars)
var/index = findtext(t, char)
while(index)
t = copytext(t, 1, index) + copytext(t, index+1)
index = findtext(t, char)
return t

//This proc strips html properly, remove < > and all text between
//for complete text sanitizing should be used sanitize()
/proc/strip_html_properly(var/input)
/proc/strip_html_properly(input)
if(!input)
return
var/opentag = 1 //These store the position of < and > respectively.
Expand All @@ -301,7 +351,7 @@
//This proc fills in all spaces with the "replace" var (* by default) with whatever
//is in the other string at the same spot (assuming it is not a replace char).
//This is used for fingerprints
/proc/stringmerge(var/text,var/compare,replace = "*")
/proc/stringmerge_ascii(text, compare,replace = "*")
var/newtext = text
if(length(text) != length(compare))
return 0
Expand All @@ -321,7 +371,7 @@

//This proc returns the number of chars of the string that is the character
//This is used for detective work to determine fingerprint completion.
/proc/stringpercent(var/text,character = "*")
/proc/stringpercent_ascii(text,character = "*")
if(!text || !character)
return 0
var/count = 0
Expand All @@ -331,10 +381,13 @@
count++
return count

/proc/reverse_text(var/text = "")
/proc/reverse_text(text = "")
var/new_text = ""
for(var/i = length(text); i > 0; i--)
new_text += copytext(text, i, i+1)
var/bytes_length = length(text)
var/letter = ""
for(var/i = 1, i <= bytes_length, i += length(letter))
letter = text[i]
new_text = letter + new_text
return new_text

//Used in preferences' SetFlavorText and human's set_flavor verb
Expand Down
2 changes: 1 addition & 1 deletion code/_helpers/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ Turf and target are seperate in case you want to teleport some distance from a t
newname = input(src,"You are \a [role]. Would you like to change your name to something else?", "Name change",oldname) as text
if((world.time-time_passed) > 5 MINUTES)
return //took too long
newname = sanitizeName(newname, ,allow_numbers) //returns null if the name doesn't meet some basic requirements. Tidies up a few other things like bad-characters.
newname = sanitize_name(newname, ,allow_numbers) //returns null if the name doesn't meet some basic requirements. Tidies up a few other things like bad-characters.
for(var/mob/living/M in global.player_list)
if(M == src)
continue
Expand Down
2 changes: 1 addition & 1 deletion code/_onclick/hud/movable_screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
var/list/screen_loc_params = splittext(PM["screen-loc"], ",")
var/list/x_data = splittext(screen_loc_params[1], ":")
var/list/y_data = splittext(screen_loc_params[2], ":")
screen_loc = "LEFT+[x_data[1]]:[text2num(x_data[2])-16],BOTTOM+[y_data[1]]:[text2num(y_data[2])-16]"
screen_loc = "LEFT+[x_data[1]]:[text2num(x_data[2])-(1.5 * world.icon_size)],BOTTOM+[y_data[1]]:[text2num(y_data[2])-(1.5 * world.icon_size)]"
Loading

0 comments on commit 12259ef

Please sign in to comment.