Merge pull request #2331 from yogstation13/upstream-merge-39899

[MIRROR] Small refactor to to_chat to get rid of needless list-wrapping
This commit is contained in:
1fbff5f83b23d39d38b1dfcb4cac8d9b
2018-08-29 16:10:54 +02:00
committed by GitHub
3 changed files with 42 additions and 38 deletions

View File

@@ -457,3 +457,5 @@ GLOBAL_LIST_INIT(pda_styles, list(MONO, VT, ORBITRON, SHARE))
#define CAMERA_NO_GHOSTS 0
#define CAMERA_SEE_GHOSTS_BASIC 1
#define CAMERA_SEE_GHOSTS_ORBIT 2
#define CLIENT_FROM_VAR(I) (ismob(I) ? I:client : (istype(I, /client) ? I : (istype(I, /datum/mind) ? I:current?:client : null)))

View File

@@ -21,18 +21,17 @@
var/mob/living/silicon/robot/borg
var/user
/datum/borgpanel/New(user, mob/living/silicon/robot/borg)
if(!istype(borg))
/datum/borgpanel/New(to_user, mob/living/silicon/robot/to_borg)
if(!istype(to_borg))
CRASH("Borg panel is only available for borgs")
qdel(src)
if (istype(user, /mob))
var/mob/M = user
if (!M.client)
user = CLIENT_FROM_VAR(to_user)
if (!user)
CRASH("Borg panel attempted to open to a mob without a client")
src.user = M.client
else
src.user = user
src.borg = borg
borg = to_borg
/datum/borgpanel/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.admin_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)

View File

@@ -191,29 +191,23 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic
log_world("\[[time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")]\] Client: [(src.owner.key ? src.owner.key : src.owner)] triggered JS error: [error]")
//Global chat procs
/proc/to_chat(target, message, handle_whitespace=TRUE)
if(!target)
return
//Ok so I did my best but I accept that some calls to this will be for shit like sound and images
//It stands that we PROBABLY don't want to output those to the browser output so just handle them here
if (istype(message, /image) || istype(message, /sound) || istype(target, /savefile))
if (istype(target, /savefile))
CRASH("Invalid message! [message]")
if(!istext(message))
if (istype(message, /image) || istype(message, /sound))
CRASH("Invalid message! [message]")
return
if(target == world)
target = GLOB.clients
var/list/targets
if(!islist(target))
targets = list(target)
else
targets = target
if(!targets.len)
return
var/original_message = message
//Some macros remain in the string even after parsing and fuck up the eventual output
message = replacetext(message, "\improper", "")
@@ -221,23 +215,13 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic
if(handle_whitespace)
message = replacetext(message, "\n", "<br>")
message = replacetext(message, "\t", "[GLOB.TAB][GLOB.TAB]")
message = to_utf8(message, target) // yogs - LibVG
for(var/I in targets)
//Grab us a client if possible
var/client/C
if (ismob(I))
var/mob/M = I
if(M.client)
C = M.client
else if(istype(I, /client))
C = I
else if(istype(I, /datum/mind))
var/datum/mind/M = I
if(M.current && M.current.client)
C = M.current.client
if(islist(target))
// Do the double-encoding outside the loop to save nanoseconds
var/twiceEncoded = url_encode(url_encode(message))
for(var/I in target)
message = to_utf8(message, I) // yogs - LibVG
var/client/C = CLIENT_FROM_VAR(I) //Grab us a client if possible
if (!C)
continue
@@ -252,5 +236,24 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic
C.chatOutput.messageQueue += message
continue
C << output(twiceEncoded, "browseroutput:output")
else
var/client/C = CLIENT_FROM_VAR(target) //Grab us a client if possible
if (!C)
return
message = to_utf8(message, target) // yogs - LibVG
//Send it to the old style output window.
SEND_TEXT(C, original_message)
if(!C.chatOutput || C.chatOutput.broken) // A player who hasn't updated his skin file.
return
if(!C.chatOutput.loaded)
//Client still loading, put their messages in a queue
C.chatOutput.messageQueue += message
return
// url_encode it TWICE, this way any UTF-8 characters are able to be decoded by the Javascript.
C << output(url_encode(url_encode(message)), "browseroutput:output")