mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-09 16:05:07 +00:00
* Unicode support Part 2 -- copytext() This is the transition of all copytext() calls to be unicode aware and also some nearby calls in the same functions. Most things are just replacing copytext() with copytext_char() as a terrible character limiter but a few others were slightly more involved. I replaced a ton of ```` var/something = sanitize(input()) something = copytext(something, 1, MAX_MESSAGE_LEN) ```` with a single stripped_input() call. stripped_input() already calls html_encode(), trim(), and some other sanitization so there shouldn't be any major issues there. This is still VERY rough btw; DNA is a mess, the status displays are complete ass, there's a copytext() in code\datums\shuttles.dm that I'm not sure what to do with, and I didn't touch anything in the tools folder. I haven't tested this much at all yet, I only got it to compile earlier this morning. There's also likely to be weird bugs until I get around to fixing length(), findtext(), and the rest of the string procs. * Makes the code functional * Assume color hex strings are always # followed by ascii. Properly encodes and decodes the stuff in mob_helpers.dm which fixes some issues there. * Removes ninjaspeak since it's unused
61 lines
2.0 KiB
Plaintext
61 lines
2.0 KiB
Plaintext
//Runs the command in the system's shell, returns a list of (error code, stdout, stderr)
|
|
|
|
#define SHELLEO_NAME "data/shelleo."
|
|
#define SHELLEO_ERR ".err"
|
|
#define SHELLEO_OUT ".out"
|
|
/world/proc/shelleo(command)
|
|
var/static/list/shelleo_ids = list()
|
|
var/stdout = ""
|
|
var/stderr = ""
|
|
var/errorcode = 1
|
|
var/shelleo_id
|
|
var/out_file = ""
|
|
var/err_file = ""
|
|
var/static/list/interpreters = list("[MS_WINDOWS]" = "cmd /c", "[UNIX]" = "sh -c")
|
|
var/interpreter = interpreters["[world.system_type]"]
|
|
if(interpreter)
|
|
for(var/seo_id in shelleo_ids)
|
|
if(!shelleo_ids[seo_id])
|
|
shelleo_ids[seo_id] = TRUE
|
|
shelleo_id = "[seo_id]"
|
|
break
|
|
if(!shelleo_id)
|
|
shelleo_id = "[shelleo_ids.len + 1]"
|
|
shelleo_ids += shelleo_id
|
|
shelleo_ids[shelleo_id] = TRUE
|
|
out_file = "[SHELLEO_NAME][shelleo_id][SHELLEO_OUT]"
|
|
err_file = "[SHELLEO_NAME][shelleo_id][SHELLEO_ERR]"
|
|
if(world.system_type == UNIX)
|
|
errorcode = shell("[interpreter] \"[replacetext(command, "\"", "\\\"")]\" > [out_file] 2> [err_file]")
|
|
else
|
|
errorcode = shell("[interpreter] \"[command]\" > [out_file] 2> [err_file]")
|
|
if(fexists(out_file))
|
|
stdout = file2text(out_file)
|
|
fdel(out_file)
|
|
if(fexists(err_file))
|
|
stderr = file2text(err_file)
|
|
fdel(err_file)
|
|
shelleo_ids[shelleo_id] = FALSE
|
|
else
|
|
CRASH("Operating System: [world.system_type] not supported") // If you encounter this error, you are encouraged to update this proc with support for the new operating system
|
|
. = list(errorcode, stdout, stderr)
|
|
#undef SHELLEO_NAME
|
|
#undef SHELLEO_ERR
|
|
#undef SHELLEO_OUT
|
|
|
|
/proc/shell_url_scrub(url)
|
|
var/static/regex/bad_chars_regex = regex("\[^#%&./:=?\\w]*", "g")
|
|
var/scrubbed_url = ""
|
|
var/bad_match = ""
|
|
var/last_good = 1
|
|
var/bad_chars = 1
|
|
do
|
|
bad_chars = bad_chars_regex.Find(url)
|
|
scrubbed_url += copytext(url, last_good, bad_chars)
|
|
if(bad_chars)
|
|
bad_match = url_encode(bad_chars_regex.match)
|
|
scrubbed_url += bad_match
|
|
last_good = bad_chars + length(bad_chars_regex.match)
|
|
while(bad_chars)
|
|
. = scrubbed_url
|