diff --git a/code/__defines/chat.dm b/code/__defines/chat.dm
index 37624e1f4d..e1acf03d64 100644
--- a/code/__defines/chat.dm
+++ b/code/__defines/chat.dm
@@ -3,6 +3,11 @@
* SPDX-License-Identifier: MIT
*/
+/// How many chat payloads to keep in history
+#define CHAT_RELIABILITY_HISTORY_SIZE 5
+/// How many resends to allow before giving up
+#define CHAT_RELIABILITY_MAX_RESENDS 3
+
#define MESSAGE_TYPE_SYSTEM "system"
#define MESSAGE_TYPE_LOCALCHAT "localchat"
#define MESSAGE_TYPE_PLOCALCHAT "plocalchat"
diff --git a/code/_helpers/icons.dm b/code/_helpers/icons.dm
index dce51f35bf..532222b7f6 100644
--- a/code/_helpers/icons.dm
+++ b/code/_helpers/icons.dm
@@ -517,6 +517,37 @@ GLOBAL_LIST_EMPTY(cached_examine_icons)
return list(rsc_ref, hash, "asset.[hash]")
+/// Gets a dummy savefile for usage in icon generation.
+/// Savefiles generated from this proc will be empty.
+/proc/get_dummy_savefile(from_failure = FALSE)
+ var/static/next_id = 0
+ if(next_id++ > 9)
+ next_id = 0
+ var/savefile_path = "tmp/dummy-save-[next_id].sav"
+ try
+ if(fexists(savefile_path))
+ fdel(savefile_path)
+ return new /savefile(savefile_path)
+ catch(var/exception/error)
+ // if we failed to create a dummy once, try again; maybe someone slept somewhere they shouldnt have
+ if(from_failure) // this *is* the retry, something fucked up
+ CRASH("get_dummy_savefile failed to create a dummy savefile: '[error]'")
+ return get_dummy_savefile(from_failure = TRUE)
+
+/**
+ * Converts an icon to base64. Operates by putting the icon in the iconCache savefile,
+ * exporting it as text, and then parsing the base64 from that.
+ * (This relies on byond automatically storing icons in savefiles as base64)
+ */
+/proc/icon2base64(icon/icon)
+ if (!isicon(icon))
+ return FALSE
+ var/savefile/dummySave = get_dummy_savefile()
+ WRITE_FILE(dummySave["dummy"], icon)
+ var/iconData = dummySave.ExportText("dummy")
+ var/list/partial = splittext(iconData, "{")
+ return replacetext(copytext_char(partial[2], 3, -5), "\n", "") //if cleanup fails we want to still return the correct base64
+
///given a text string, returns whether it is a valid dmi icons folder path
/proc/is_valid_dmi_file(icon_path)
if(!istext(icon_path) || !length(icon_path))
@@ -671,6 +702,39 @@ GLOBAL_LIST_EMPTY(cached_examine_icons)
return get_asset_url(key)
return ""
+/proc/icon2base64html(target, var/custom_classes = "")
+ if (!target)
+ return
+ var/static/list/bicon_cache = list()
+ if (isicon(target))
+ var/icon/target_icon = target
+ var/icon_base64 = icon2base64(target_icon)
+
+ if (target_icon.Height() > world.icon_size || target_icon.Width() > world.icon_size)
+ var/icon_md5 = md5(icon_base64)
+ icon_base64 = bicon_cache[icon_md5]
+ if (!icon_base64) // Doesn't exist yet, make it.
+ bicon_cache[icon_md5] = icon_base64 = icon2base64(target_icon)
+
+
+ return "
"
+
+ // Either an atom or somebody fucked up and is gonna get a runtime, which I'm fine with.
+ var/atom/target_atom = target
+ var/key = "[istype(target_atom.icon, /icon) ? "[REF(target_atom.icon)]" : target_atom.icon]:[target_atom.icon_state]"
+
+
+ if (!bicon_cache[key]) // Doesn't exist, make it.
+ var/icon/target_icon = icon(target_atom.icon, target_atom.icon_state, SOUTH, 1)
+ if (ishuman(target)) // Shitty workaround for a BYOND issue.
+ var/icon/temp = target_icon
+ target_icon = icon()
+ target_icon.Insert(temp, dir = SOUTH)
+
+ bicon_cache[key] = icon2base64(target_icon)
+
+ return "
"
+
//Costlier version of icon2html() that uses getFlatIcon() to account for overlays, underlays, etc. Use with extreme moderation, ESPECIALLY on mobs.
/proc/costly_icon2html(thing, target, sourceonly = FALSE)
if (!thing)
diff --git a/code/_helpers/text.dm b/code/_helpers/text.dm
index 5e77b4b09c..1ce469c407 100644
--- a/code/_helpers/text.dm
+++ b/code/_helpers/text.dm
@@ -347,7 +347,7 @@
if(!text_tag_cache[tagname])
var/icon/tag = icon(text_tag_icons, tagname)
text_tag_cache[tagname] = bicon(tag, TRUE, "text_tag")
- if(C.chatOutput.broken)
+ if(!C.tgui_panel.is_ready() || C.tgui_panel.oldchat)
return "
"
return text_tag_cache[tagname]
diff --git a/code/_macros.dm b/code/_macros.dm
index 737b317abe..169a897881 100644
--- a/code/_macros.dm
+++ b/code/_macros.dm
@@ -12,7 +12,7 @@
// #define to_chat(target, message) target << message Not anymore!
//#define to_chat to_chat_filename=__FILE__;to_chat_line=__LINE__;to_chat_src=src;__to_chat
-#define to_chat __to_chat
+//#define to_chat __to_chat
#define to_world(message) to_chat(world, message)
#define to_world_log(message) world.log << message
// TODO - Baystation has this log to crazy places. For now lets just world.log, but maybe look into it later.
diff --git a/code/controllers/subsystems/chat.dm b/code/controllers/subsystems/chat.dm
index 92a1be2757..b8b2917c8d 100644
--- a/code/controllers/subsystems/chat.dm
+++ b/code/controllers/subsystems/chat.dm
@@ -1,77 +1,100 @@
+/*!
+ * Copyright (c) 2020 Aleksej Komarov
+ * SPDX-License-Identifier: MIT
+ */
+
SUBSYSTEM_DEF(chat)
name = "Chat"
- flags = SS_TICKER
- wait = 1 // SS_TICKER means this runs every tick
+ flags = SS_TICKER|SS_NO_INIT
+ wait = 1
priority = FIRE_PRIORITY_CHAT
init_order = INIT_ORDER_CHAT
- var/list/list/msg_queue = list() //List of lists
+ /// Assosciates a ckey with a list of messages to send to them.
+ var/list/list/datum/chat_payload/client_to_payloads = list()
-/datum/controller/subsystem/chat/Initialize(timeofday)
- init_vchat()
- ..()
+ /// Associates a ckey with an assosciative list of their last CHAT_RELIABILITY_HISTORY_SIZE messages.
+ var/list/list/datum/chat_payload/client_to_reliability_history = list()
+
+ /// Assosciates a ckey with their next sequence number.
+ var/list/client_to_sequence_number = list()
+
+/datum/controller/subsystem/chat/proc/generate_payload(client/target, message_data)
+ var/sequence = client_to_sequence_number[target.ckey]
+ client_to_sequence_number[target.ckey] += 1
+
+ var/datum/chat_payload/payload = new
+ payload.sequence = sequence
+ payload.content = message_data
+
+ if(!(target.ckey in client_to_reliability_history))
+ client_to_reliability_history[target.ckey] = list()
+ var/list/client_history = client_to_reliability_history[target.ckey]
+ client_history["[sequence]"] = payload
+
+ if(length(client_history) > CHAT_RELIABILITY_HISTORY_SIZE)
+ var/oldest = text2num(client_history[1])
+ for(var/index in 2 to length(client_history))
+ var/test = text2num(client_history[index])
+ if(test < oldest)
+ oldest = test
+ client_history -= "[oldest]"
+ return payload
+
+/datum/controller/subsystem/chat/proc/send_payload_to_client(client/target, datum/chat_payload/payload)
+ target.tgui_panel.window.send_message("chat/message", payload.into_message())
+ SEND_TEXT(target, payload.get_content_as_html())
/datum/controller/subsystem/chat/fire()
- var/list/msg_queue = src.msg_queue // Local variable for sanic speed.
- for(var/client/C as anything in msg_queue)
- var/list/messages = msg_queue[C]
- msg_queue -= C
- if (C)
- C << output(jsEncode(messages), "htmloutput:putmessage")
+ for(var/ckey in client_to_payloads)
+ var/client/target = GLOB.directory[ckey]
+ if(isnull(target)) // verify client still exists
+ LAZYREMOVE(client_to_payloads, ckey)
+ continue
+
+ for(var/datum/chat_payload/payload as anything in client_to_payloads[ckey])
+ send_payload_to_client(target, payload)
+ LAZYREMOVE(client_to_payloads, ckey)
if(MC_TICK_CHECK)
return
-/datum/controller/subsystem/chat/stat_entry()
- ..("C:[msg_queue.len]")
+/datum/controller/subsystem/chat/proc/queue(queue_target, list/message_data)
+ var/list/targets = islist(queue_target) ? queue_target : list(queue_target)
+ for(var/target in targets)
+ var/client/client = CLIENT_FROM_VAR(target)
+ if(isnull(client))
+ continue
+ LAZYADDASSOCLIST(client_to_payloads, client.ckey, generate_payload(client, message_data))
-/datum/controller/subsystem/chat/proc/queue(target, time, message, handle_whitespace = TRUE)
- if(!target || !message)
+/datum/controller/subsystem/chat/proc/send_immediate(send_target, list/message_data)
+ var/list/targets = islist(send_target) ? send_target : list(send_target)
+ for(var/target in targets)
+ var/client/client = CLIENT_FROM_VAR(target)
+ if(isnull(client))
+ continue
+ send_payload_to_client(client, generate_payload(client, message_data))
+
+/datum/controller/subsystem/chat/proc/handle_resend(client/client, sequence)
+ var/list/client_history = client_to_reliability_history[client.ckey]
+ sequence = "[sequence]"
+ if(isnull(client_history) || !(sequence in client_history))
return
- if(!istext(message))
- stack_trace("to_chat called with invalid input type")
- return
+ var/datum/chat_payload/payload = client_history[sequence]
+ if(payload.resends > CHAT_RELIABILITY_MAX_RESENDS)
+ return // we tried but byond said no
- // Currently to_chat(world, ...) gets sent individually to each client. Consider.
- if(target == world)
- target = GLOB.clients
-
- //Some macros remain in the string even after parsing and fuck up the eventual output
- var/original_message = message
- message = replacetext(message, "\n", "
")
- message = replacetext(message, "\improper", "")
- message = replacetext(message, "\proper", "")
-
- if(isnull(time))
- time = world.time
-
- var/list/messageStruct = list("time" = time, "message" = message);
-
- if(islist(target))
- for(var/I in target)
- var/client/C = CLIENT_FROM_VAR(I) //Grab us a client if possible
-
- if(!C || !C.chatOutput)
- continue // No client? No care.
- else if(C.chatOutput.broken)
- DIRECT_OUTPUT(C, original_message)
- continue
- else if(!C.chatOutput.loaded)
- continue // If not loaded yet, do nothing and history-sending on load will get it.
-
- LAZYINITLIST(msg_queue[C])
- msg_queue[C][++msg_queue[C].len] = messageStruct
- else
- var/client/C = CLIENT_FROM_VAR(target) //Grab us a client if possible
-
- if(!C || !C.chatOutput)
- return // No client? No care.
- else if(C.chatOutput.broken)
- DIRECT_OUTPUT(C, original_message)
- return
- else if(!C.chatOutput.loaded)
- return // If not loaded yet, do nothing and history-sending on load will get it.
-
- LAZYINITLIST(msg_queue[C])
- msg_queue[C][++msg_queue[C].len] = messageStruct
+ payload.resends += 1
+ send_payload_to_client(client, client_history[sequence])
+ /*
+ SSblackbox.record_feedback(
+ "nested tally",
+ "chat_resend_byond_version",
+ 1,
+ list(
+ "[client.byond_version]",
+ "[client.byond_build]",
+ ),
+ )
+ */
diff --git a/code/controllers/subsystems/ping.dm b/code/controllers/subsystems/ping.dm
new file mode 100644
index 0000000000..00e3effe02
--- /dev/null
+++ b/code/controllers/subsystems/ping.dm
@@ -0,0 +1,44 @@
+/*!
+ * Copyright (c) 2022 Aleksej Komarov
+ * SPDX-License-Identifier: MIT
+ */
+
+SUBSYSTEM_DEF(ping)
+ name = "Ping"
+ priority = FIRE_PRIORITY_PING
+ // init_stage = INITSTAGE_EARLY
+ wait = 4 SECONDS
+ flags = SS_NO_INIT
+ runlevels = RUNLEVEL_LOBBY | RUNLEVELS_DEFAULT
+ var/list/currentrun = list()
+
+/datum/controller/subsystem/ping/stat_entry()
+ ..("P:[GLOB.clients.len]")
+
+/datum/controller/subsystem/ping/fire(resumed = FALSE)
+ // Prepare the new batch of clients
+ if (!resumed)
+ src.currentrun = GLOB.clients.Copy()
+
+ // De-reference the list for sanic speeds
+ var/list/currentrun = src.currentrun
+
+ while (currentrun.len)
+ var/client/client = currentrun[currentrun.len]
+ currentrun.len--
+
+ if(!client.is_preference_enabled(/datum/client_preference/vchat_enable))
+ winset(client, "output", "on-show=&is-disabled=0&is-visible=1")
+ winset(client, "browseroutput", "is-disabled=1;is-visible=0")
+ client.tgui_panel.oldchat = TRUE
+
+ if (client?.tgui_panel?.is_ready())
+ // Send a soft ping
+ client.tgui_panel.window.send_message("ping/soft", list(
+ // Slightly less than the subsystem timer (somewhat arbitrary)
+ // to prevent incoming pings from resetting the afk state
+ "afk" = client.is_afk(3.5 SECONDS),
+ ))
+
+ if (MC_TICK_CHECK)
+ return
diff --git a/code/controllers/subsystems/tgui.dm b/code/controllers/subsystems/tgui.dm
index 73494cbf46..6810a23a7f 100644
--- a/code/controllers/subsystems/tgui.dm
+++ b/code/controllers/subsystems/tgui.dm
@@ -2,6 +2,7 @@
* Copyright (c) 2020 Aleksej Komarov
* SPDX-License-Identifier: MIT
*/
+
/**
* tgui subsystem
*
@@ -37,7 +38,7 @@ SUBSYSTEM_DEF(tgui)
/datum/controller/subsystem/tgui/stat_entry()
..("P:[all_uis.len]")
-/datum/controller/subsystem/tgui/fire(resumed = 0)
+/datum/controller/subsystem/tgui/fire(resumed = FALSE)
if(!resumed)
src.current_run = all_uis.Copy()
// Cache for sanic speed (lists are references anyways)
@@ -46,8 +47,8 @@ SUBSYSTEM_DEF(tgui)
var/datum/tgui/ui = current_run[current_run.len]
current_run.len--
// TODO: Move user/src_object check to process()
- if(ui && ui.user && ui.src_object)
- ui.process()
+ if(ui?.user && ui.src_object)
+ ui.process(wait * 0.1)
else
ui.close(0)
if(MC_TICK_CHECK)
@@ -86,6 +87,8 @@ SUBSYSTEM_DEF(tgui)
window_found = TRUE
break
if(!window_found)
+ log_tgui(user, "Error: Pool exhausted",
+ context = "SStgui/request_pooled_window")
return null
return window
@@ -97,6 +100,7 @@ SUBSYSTEM_DEF(tgui)
* required user mob
*/
/datum/controller/subsystem/tgui/proc/force_close_all_windows(mob/user)
+ log_tgui(user, context = "SStgui/force_close_all_windows")
if(user.client)
user.client.tgui_windows = list()
for(var/i in 1 to TGUI_WINDOW_HARD_LIMIT)
@@ -112,6 +116,7 @@ SUBSYSTEM_DEF(tgui)
* required window_id string
*/
/datum/controller/subsystem/tgui/proc/force_close_window(mob/user, window_id)
+ log_tgui(user, context = "SStgui/force_close_window")
// Close all tgui datums based on window_id.
for(var/datum/tgui/ui in user.tgui_open_uis)
if(ui.window && ui.window.id == window_id)
@@ -121,22 +126,23 @@ SUBSYSTEM_DEF(tgui)
// Close window directly just to be sure.
user << browse(null, "window=[window_id]")
- /**
- * public
- *
- * Get a open UI given a user, src_object, and ui_key and try to update it with data.
- *
- * required user mob The mob who opened/is using the UI.
- * required src_object datum The object/datum which owns the UI.
- * required ui_key string The ui_key of the UI.
- *
- * return datum/tgui The found UI.
- **/
+/**
+ * public
+ *
+ * Try to find an instance of a UI, and push an update to it.
+ *
+ * required user mob The mob who opened/is using the UI.
+ * required src_object datum The object/datum which owns the UI.
+ * optional ui datum/tgui The UI to be updated, if it exists.
+ * optional force_open bool If the UI should be re-opened instead of updated.
+ *
+ * return datum/tgui The found UI.
+ */
/datum/controller/subsystem/tgui/proc/try_update_ui(
mob/user,
datum/src_object,
datum/tgui/ui)
- // Look up a UI if it wasn't passed.
+ // Look up a UI if it wasn't passed
if(isnull(ui))
ui = get_open_ui(user, src_object)
// Couldn't find a UI.
@@ -152,17 +158,16 @@ SUBSYSTEM_DEF(tgui)
ui.send_update()
return ui
- /**
- * private
- *
- * Get a open UI given a user, src_object, and ui_key.
- *
- * required user mob The mob who opened/is using the UI.
- * required src_object datum The object/datum which owns the UI.
- * required ui_key string The ui_key of the UI.
- *
- * return datum/tgui The found UI.
- **/
+/**
+ * public
+ *
+ * Get a open UI given a user and src_object.
+ *
+ * required user mob The mob who opened/is using the UI.
+ * required src_object datum The object/datum which owns the UI.
+ *
+ * return datum/tgui The found UI.
+ */
/datum/controller/subsystem/tgui/proc/get_open_ui(mob/user, datum/src_object)
// No UIs opened for this src_object
if(!LAZYLEN(src_object?.open_tguis))
@@ -171,56 +176,57 @@ SUBSYSTEM_DEF(tgui)
// Make sure we have the right user
if(ui.user == user)
return ui
- return null // Couldn't find a UI!
+ return null
- /**
- * private
- *
- * Update all UIs attached to src_object.
- *
- * required src_object datum The object/datum which owns the UIs.
- *
- * return int The number of UIs updated.
- **/
+/**
+ * public
+ *
+ * Update all UIs attached to src_object.
+ *
+ * required src_object datum The object/datum which owns the UIs.
+ *
+ * return int The number of UIs updated.
+ */
/datum/controller/subsystem/tgui/proc/update_uis(datum/src_object)
// No UIs opened for this src_object
if(!LAZYLEN(src_object?.open_tguis))
return 0
var/count = 0
for(var/datum/tgui/ui in src_object.open_tguis)
- // Check the UI is valid.
- if(ui && ui.src_object && ui.user && ui.src_object.tgui_host(ui.user))
+ // Check if UI is valid.
+ if(ui?.src_object && ui.user && ui.src_object.tgui_host(ui.user))
INVOKE_ASYNC(ui, TYPE_PROC_REF(/datum/tgui, process), wait * 0.1, TRUE)
- count++ // Count each UI we update.
+ count++
return count
- /**
- * private
- *
- * Close all UIs attached to src_object.
- *
- * required src_object datum The object/datum which owns the UIs.
- *
- * return int The number of UIs closed.
- **/
+/**
+ * public
+ *
+ * Close all UIs attached to src_object.
+ *
+ * required src_object datum The object/datum which owns the UIs.
+ *
+ * return int The number of UIs closed.
+ */
/datum/controller/subsystem/tgui/proc/close_uis(datum/src_object)
// No UIs opened for this src_object
if(!LAZYLEN(src_object?.open_tguis))
return 0
var/count = 0
for(var/datum/tgui/ui in src_object.open_tguis)
- if(ui && ui.src_object && ui.user && ui.src_object.tgui_host(ui.user)) // Check the UI is valid.
- ui.close() // Close the UI.
- count++ // Count each UI we close.
+ // Check if UI is valid.
+ if(ui?.src_object && ui.user && ui.src_object.tgui_host(ui.user))
+ ui.close()
+ count++
return count
- /**
- * private
- *
- * Close all UIs regardless of their attachment to src_object.
- *
- * return int The number of UIs closed.
- **/
+/**
+ * public
+ *
+ * Close all UIs regardless of their attachment to src_object.
+ *
+ * return int The number of UIs closed.
+ */
/datum/controller/subsystem/tgui/proc/close_all_uis()
var/count = 0
for(var/datum/tgui/ui in all_uis)
@@ -230,67 +236,67 @@ SUBSYSTEM_DEF(tgui)
count++
return count
- /**
- * private
- *
- * Update all UIs belonging to a user.
- *
- * required user mob The mob who opened/is using the UI.
- * optional src_object datum If provided, only update UIs belonging this src_object.
- *
- * return int The number of UIs updated.
- **/
+/**
+ * public
+ *
+ * Update all UIs belonging to a user.
+ *
+ * required user mob The mob who opened/is using the UI.
+ * optional src_object datum If provided, only update UIs belonging this src_object.
+ *
+ * return int The number of UIs updated.
+ */
/datum/controller/subsystem/tgui/proc/update_user_uis(mob/user, datum/src_object)
var/count = 0
if(length(user?.tgui_open_uis) == 0)
return count
for(var/datum/tgui/ui in user.tgui_open_uis)
if(isnull(src_object) || ui.src_object == src_object)
- ui.process(force = 1)
+ ui.process(wait * 0.1, force = 1)
count++
return count
- /**
- * private
- *
- * Close all UIs belonging to a user.
- *
- * required user mob The mob who opened/is using the UI.
- * optional src_object datum If provided, only close UIs belonging this src_object.
- *
- * return int The number of UIs closed.
- **/
-/datum/controller/subsystem/tgui/proc/close_user_uis(mob/user, datum/src_object, logout = FALSE)
+/**
+ * public
+ *
+ * Close all UIs belonging to a user.
+ *
+ * required user mob The mob who opened/is using the UI.
+ * optional src_object datum If provided, only close UIs belonging this src_object.
+ *
+ * return int The number of UIs closed.
+ */
+/datum/controller/subsystem/tgui/proc/close_user_uis(mob/user, datum/src_object)
var/count = 0
if(length(user?.tgui_open_uis) == 0)
return count
for(var/datum/tgui/ui in user.tgui_open_uis)
if(isnull(src_object) || ui.src_object == src_object)
- ui.close(logout = logout)
+ ui.close()
count++
return count
- /**
- * private
- *
- * Add a UI to the list of open UIs.
- *
- * required ui datum/tgui The UI to be added.
- **/
+/**
+ * private
+ *
+ * Add a UI to the list of open UIs.
+ *
+ * required ui datum/tgui The UI to be added.
+ */
/datum/controller/subsystem/tgui/proc/on_open(datum/tgui/ui)
ui.user?.tgui_open_uis |= ui
LAZYOR(ui.src_object.open_tguis, ui)
all_uis |= ui
- /**
- * private
- *
- * Remove a UI from the list of open UIs.
- *
- * required ui datum/tgui The UI to be removed.
- *
- * return bool If the UI was removed or not.
- **/
+/**
+ * private
+ *
+ * Remove a UI from the list of open UIs.
+ *
+ * required ui datum/tgui The UI to be removed.
+ *
+ * return bool If the UI was removed or not.
+ */
/datum/controller/subsystem/tgui/proc/on_close(datum/tgui/ui)
// Remove it from the list of processing UIs.
all_uis -= ui
@@ -302,28 +308,28 @@ SUBSYSTEM_DEF(tgui)
LAZYREMOVE(ui.src_object.open_tguis, ui)
return TRUE
- /**
- * private
- *
- * Handle client logout, by closing all their UIs.
- *
- * required user mob The mob which logged out.
- *
- * return int The number of UIs closed.
- **/
+/**
+ * private
+ *
+ * Handle client logout, by closing all their UIs.
+ *
+ * required user mob The mob which logged out.
+ *
+ * return int The number of UIs closed.
+ */
/datum/controller/subsystem/tgui/proc/on_logout(mob/user)
- return close_user_uis(user, logout = TRUE)
+ close_user_uis(user)
- /**
- * private
- *
- * Handle clients switching mobs, by transferring their UIs.
- *
- * required user source The client's original mob.
- * required user target The client's new mob.
- *
- * return bool If the UIs were transferred.
- **/
+/**
+ * private
+ *
+ * Handle clients switching mobs, by transferring their UIs.
+ *
+ * required user source The client's original mob.
+ * required user target The client's new mob.
+ *
+ * return bool If the UIs were transferred.
+ */
/datum/controller/subsystem/tgui/proc/on_transfer(mob/source, mob/target)
// The old mob had no open UIs.
if(length(source?.tgui_open_uis) == 0)
diff --git a/code/datums/chat_payload.dm b/code/datums/chat_payload.dm
new file mode 100644
index 0000000000..fd35bbc4ee
--- /dev/null
+++ b/code/datums/chat_payload.dm
@@ -0,0 +1,16 @@
+/// Stores information about a chat payload
+/datum/chat_payload
+ /// Sequence number of this payload
+ var/sequence = 0
+ /// Message we are sending
+ var/list/content
+ /// Resend count
+ var/resends = 0
+
+/// Converts the chat payload into a JSON string
+/datum/chat_payload/proc/into_message()
+ return "{\"sequence\":[sequence],\"content\":[json_encode(content)]}"
+
+/// Returns an HTML-encoded message from our contents.
+/datum/chat_payload/proc/get_content_as_html()
+ return message_to_html(content)
diff --git a/code/game/world.dm b/code/game/world.dm
index 88d6b2412c..70df3ea593 100644
--- a/code/game/world.dm
+++ b/code/game/world.dm
@@ -60,7 +60,6 @@
GLOB.timezoneOffset = get_timezone_offset()
callHook("startup")
- init_vchat()
//Emergency Fix
load_mods()
//end-emergency fix
diff --git a/code/modules/admin/verbs/pray.dm b/code/modules/admin/verbs/pray.dm
index b2be689721..ffac68a6f9 100644
--- a/code/modules/admin/verbs/pray.dm
+++ b/code/modules/admin/verbs/pray.dm
@@ -22,9 +22,9 @@
for(var/client/C in GLOB.admins)
if(R_ADMIN|R_EVENT & C.holder.rights)
if(C.is_preference_enabled(/datum/client_preference/admin/show_chat_prayers))
- to_chat(C,msg)
+ to_chat(C, msg, type = MESSAGE_TYPE_PRAYER, confidential = TRUE)
C << 'sound/effects/ding.ogg'
- to_chat(usr, "Your prayers have been received by the gods.")
+ to_chat(usr, "Your prayers have been received by the gods.", confidential = TRUE)
feedback_add_details("admin_verb","PR") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
log_pray(raw_msg, src)
diff --git a/code/modules/asset_cache/assets/chat.dm b/code/modules/asset_cache/assets/chat.dm
new file mode 100644
index 0000000000..eba0e5418e
--- /dev/null
+++ b/code/modules/asset_cache/assets/chat.dm
@@ -0,0 +1,2 @@
+/datum/asset/spritesheet/chat
+ name = "chat"
diff --git a/code/modules/asset_cache/assets/tgui.dm b/code/modules/asset_cache/assets/tgui.dm
index 6874c24eea..6446471a30 100644
--- a/code/modules/asset_cache/assets/tgui.dm
+++ b/code/modules/asset_cache/assets/tgui.dm
@@ -5,11 +5,9 @@
"tgui.bundle.css" = file("tgui/public/tgui.bundle.css"),
)
-/* Comment will be removed in later part
/datum/asset/simple/tgui_panel
// keep_local_name = TRUE
assets = list(
"tgui-panel.bundle.js" = file("tgui/public/tgui-panel.bundle.js"),
"tgui-panel.bundle.css" = file("tgui/public/tgui-panel.bundle.css"),
)
-*/
diff --git a/code/modules/client/client defines.dm b/code/modules/client/client defines.dm
index 13b80f1529..fa78e8d29a 100644
--- a/code/modules/client/client defines.dm
+++ b/code/modules/client/client defines.dm
@@ -41,8 +41,10 @@
var/datum/admins/deadmin_holder = null
var/buildmode = 0
- var/last_message = "" //Contains the last message sent by this client - used to protect against copy-paste spamming.
- var/last_message_count = 0 //contins a number of how many times a message identical to last_message was sent.
+ ///Contains the last message sent by this client - used to protect against copy-paste spamming.
+ var/last_message = ""
+ ///contins a number of how many times a message identical to last_message was sent.
+ var/last_message_count = 0
var/ircreplyamount = 0
var/entity_narrate_holder //Holds /datum/entity_narrate when using the relevant admin verbs.
@@ -56,9 +58,7 @@
var/area = null
var/time_died_as_mouse = null //when the client last died as a mouse
var/datum/tooltip/tooltips = null
- var/datum/chatOutput/chatOutput
var/datum/volume_panel/volume_panel = null // Initialized by /client/verb/volume_panel()
- var/chatOutputLoadedAt
var/seen_news = 0
var/adminhelped = 0
diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm
index 1a91fb94a0..cdc7577afc 100644
--- a/code/modules/client/client procs.dm
+++ b/code/modules/client/client procs.dm
@@ -135,7 +135,6 @@
if("usr") hsrc = mob
if("prefs") return prefs.process_link(usr,href_list)
if("vars") return view_var_Topic(href,href_list,hsrc)
- if("chat") return chatOutput.Topic(href, href_list)
switch(href_list["action"])
if("openLink")
@@ -174,11 +173,6 @@
del(src)
return
- chatOutput = new /datum/chatOutput(src) //veechat
- chatOutput.send_resources()
- spawn()
- chatOutput.start()
-
//Only show this if they are put into a new_player mob. Otherwise, "what title screen?"
if(isnewplayer(src.mob))
to_chat(src, "If the title screen is black, resources are still downloading. Please be patient until the title screen appears.")
@@ -186,6 +180,9 @@
GLOB.clients += src
GLOB.directory[ckey] = src
+ // Instantiate tgui panel
+ tgui_panel = new(src, "browseroutput")
+
GLOB.tickets.ClientLogin(src) // CHOMPedit - Tickets System
//Admin Authorisation
@@ -214,6 +211,9 @@
if(prefs)
prefs.selecting_slots = FALSE
+ // Initialize tgui panel
+ tgui_panel.initialize()
+
connection_time = world.time
connection_realtime = world.realtime
connection_timeofday = world.timeofday
@@ -492,29 +492,6 @@
return FALSE
return ..()
-/client/verb/reload_vchat()
- set name = "Reload VChat"
- set category = "OOC"
-
- //Timing
- if(src.chatOutputLoadedAt > (world.time - 10 SECONDS))
- tgui_alert_async(src, "You can only try to reload VChat every 10 seconds at most.")
- return
-
- // YW EDIT: disabled until we can fix the lag: verbs -= /client/proc/vchat_export_log
-
- //Log, disable
- log_debug("[key_name(src)] reloaded VChat.")
- winset(src, null, "outputwindow.htmloutput.is-visible=false;outputwindow.oldoutput.is-visible=false;outputwindow.chatloadlabel.is-visible=true")
-
- //The hard way
- qdel_null(src.chatOutput)
- chatOutput = new /datum/chatOutput(src) //veechat
- chatOutput.send_resources()
- spawn()
- chatOutput.start()
-
-
//This is for getipintel.net.
//You're welcome to replace this proc with your own that does your own cool stuff.
//Just set the client's ip_reputation var and make sure it makes sense with your config settings (higher numbers are worse results)
diff --git a/code/modules/client/preference_setup/global/setting_datums.dm b/code/modules/client/preference_setup/global/setting_datums.dm
index d229bf8afe..b500712b90 100644
--- a/code/modules/client/preference_setup/global/setting_datums.dm
+++ b/code/modules/client/preference_setup/global/setting_datums.dm
@@ -296,7 +296,7 @@ var/list/_client_preferences_by_type
key = "SOUND_INSTRUMENT"
/datum/client_preference/vchat_enable
- description = "Enable/Disable VChat"
+ description = "Enable/Disable TGChat"
key = "VCHAT_ENABLE"
enabled_description = "Enabled"
disabled_description = "Disabled"
diff --git a/code/modules/client/preferences_toggle_procs.dm b/code/modules/client/preferences_toggle_procs.dm
index 050ffa0b5d..027a6fc87a 100644
--- a/code/modules/client/preferences_toggle_procs.dm
+++ b/code/modules/client/preferences_toggle_procs.dm
@@ -367,17 +367,17 @@
feedback_add_details("admin_verb","THInstm") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
/client/verb/toggle_vchat()
- set name = "Toggle VChat"
+ set name = "Toggle TGChat"
set category = "Preferences"
- set desc = "Toggles VChat. Reloading VChat and/or reconnecting required to affect changes."
+ set desc = "Toggles TGChat. Reloading TGChat and/or reconnecting required to affect changes."
var/pref_path = /datum/client_preference/vchat_enable
toggle_preference(pref_path)
SScharacter_setup.queue_preferences_save(prefs)
- to_chat(src, "You have toggled VChat [is_preference_enabled(pref_path) ? "on" : "off"]. \
- You will have to reload VChat and/or reconnect to the server for these changes to take place. \
- VChat message persistence is not guaranteed if you change this again before the start of the next round.")
+ to_chat(src, "You have toggled TGChat [is_preference_enabled(pref_path) ? "on" : "off"]. \
+ You will have to reload TGChat and/or reconnect to the server for these changes to take place. \
+ TGChat message persistence is not guaranteed if you change this again before the start of the next round.")
/client/verb/toggle_chat_timestamps()
set name = "Toggle Chat Timestamps"
diff --git a/code/modules/tgchat/README.md b/code/modules/tgchat/README.md
new file mode 100644
index 0000000000..71acb47c45
--- /dev/null
+++ b/code/modules/tgchat/README.md
@@ -0,0 +1,30 @@
+## /TG/ Chat
+
+/TG/ Chat, which will be referred to as TgChat from this point onwards, is a system in which we can send messages to clients in a controlled and semi-reliable manner. The standard way of sending messages to BYOND clients simply dumps whatever you output to them directly into their chat window, however BYOND allows us to load our own code on the client to change this behaviour in a way that allows us to do some pretty neat things.
+
+### Message Format
+
+TgChat handles sending messages from the server to the client through the use of JSON payloads, of which the format will change depending on the type of message and the intended client endpoint. An example of the payload for chat messages is as follows:
+```json
+{
+ "sequence": 0,
+ "content": {
+ "type": ". . .", // ?optional
+ "text": ". . .", // ?optional !atleast-one
+ "html": ". . .", // ?optional !atleast-one
+ "avoidHighlighting": 0 // ?optional
+ },
+}
+```
+
+### Reliability
+
+In the past there have been issues where BYOND will silently and without reason lose a message we sent to the client, to detect this and recover from it seamlessly TgChat also has a baked in reliability layer. This reliability layer is very primitive, and simply keeps track of received sequence numbers. Should the client receive an unexpected sequence number TgChat asks the server to resend any missing packets.
+
+### Ping System
+
+TgChat supports a round trip time ping measurement, which is displayed to the client so they can know how long it takes for their commands and inputs to reach the server. This is done by sending the client a ping request, `ping/soft`, which tells the client to send a ping to the server. When the server receives said ping it sends a reply, `ping/reply`, to the client with a payload containing the current DateTime which the client can reference against the initial ping request.
+
+### Chat Tabs, Local Storage, and Highlighting
+
+To make organizing and managing chat easier and more functional for both players and admins, TgChat has the ability to filter out messages based on their primary tag, such as individual departmental radios, to a dedicated chat tab for easier reading and comprehension. These tabs can also be configured to highlist messages based on a simple keyword search. You can set a multitude of different keywords to search for and they will be highlighting for instant alerting of the client. Said tabs, highlighting rules, and your chat history will persist thanks to use of local storage on the client. Using local storage TgChat can ensure that your preferences are saved and maintained between client restarts and switching between other /TG/ servers. Local Storage is also used to keep your chat history aswell, should you need to scroll through your chat logs.
diff --git a/code/modules/tgchat/_legacy.dm b/code/modules/tgchat/_legacy.dm
new file mode 100644
index 0000000000..fe01936540
--- /dev/null
+++ b/code/modules/tgchat/_legacy.dm
@@ -0,0 +1,48 @@
+/// Old VChat Code Stuff
+
+/* Old bicon code
+/proc/expire_bicon_cache(key)
+ if(GLOB.bicon_cache[key])
+ GLOB.bicon_cache -= key
+ return TRUE
+ return FALSE
+
+GLOBAL_LIST_EMPTY(bicon_cache) // Cache of the tag results, not the icons
+*/
+
+/proc/bicon(var/obj, var/use_class = 1, var/custom_classes = "")
+ return icon2base64html(obj, custom_classes)
+
+ /* Old bicon code
+ var/class = use_class ? "class='icon misc [custom_classes]'" : null
+ if(!obj)
+ return
+
+ // Try to avoid passing bicon an /icon directly. It is better to pass it an atom so it can cache.
+ if(isicon(obj)) // Passed an icon directly, nothing to cache-key on, as icon refs get reused *often*
+ return "
"
+
+ // Either an atom or somebody fucked up and is gonna get a runtime, which I'm fine with.
+ var/atom/A = obj
+ var/key
+ var/changes_often = ishuman(A) || isobserver(A) // If this ends up with more, move it into a proc or var on atom.
+
+ if(changes_often)
+ key = "\ref[A]"
+ else
+ key = "[istype(A.icon, /icon) ? "\ref[A.icon]" : A.icon]:[A.icon_state]"
+
+ var/base64 = GLOB.bicon_cache[key]
+ // Non-human atom, no cache
+ if(!base64) // Doesn't exist, make it.
+ base64 = icon2base64(A.examine_icon(), key)
+ GLOB.bicon_cache[key] = base64
+ if(changes_often)
+ addtimer(CALLBACK(GLOBAL_PROC, .proc/expire_bicon_cache, key), 50 SECONDS, TIMER_UNIQUE)
+
+ // May add a class to the img tag created by bicon
+ if(use_class)
+ class = "class='icon [A.icon_state] [custom_classes]'"
+
+ return "
"
+ */
diff --git a/code/modules/tgchat/message.dm b/code/modules/tgchat/message.dm
new file mode 100644
index 0000000000..69d3a6faf5
--- /dev/null
+++ b/code/modules/tgchat/message.dm
@@ -0,0 +1,17 @@
+/**
+ * Message-related procs
+ *
+ * Message format (/list):
+ * - type - Message type, must be one of defines in `code/__DEFINES/chat.dm`
+ * - text - Plain message text
+ * - html - HTML message text
+ * - Optional metadata, can be any key/value pair.
+ *
+ * Copyright (c) 2020 Aleksej Komarov
+ * SPDX-License-Identifier: MIT
+ */
+
+/proc/message_to_html(message)
+ // Here it is possible to add a switch statement
+ // to custom-handle various message types.
+ return message["html"] || message["text"]
diff --git a/code/modules/tgchat/to_chat.dm b/code/modules/tgchat/to_chat.dm
new file mode 100644
index 0000000000..ae434b36f1
--- /dev/null
+++ b/code/modules/tgchat/to_chat.dm
@@ -0,0 +1,85 @@
+/*!
+ * Copyright (c) 2020 Aleksej Komarov
+ * SPDX-License-Identifier: MIT
+ */
+
+/**
+ * Circumvents the message queue and sends the message
+ * to the recipient (target) as soon as possible.
+ */
+/proc/to_chat_immediate(
+ target,
+ html,
+ type = null,
+ text = null,
+ avoid_highlighting = FALSE,
+ // FIXME: These flags are now pointless and have no effect
+ handle_whitespace = TRUE,
+ trailing_newline = TRUE,
+ confidential = FALSE
+)
+ // Useful where the integer 0 is the entire message. Use case is enabling to_chat(target, some_boolean) while preventing to_chat(target, "")
+ html = "[html]"
+ text = "[text]"
+
+ if(!target)
+ return
+ if(!html && !text)
+ CRASH("Empty or null string in to_chat proc call.")
+ if(target == world)
+ target = GLOB.clients
+
+ // Build a message
+ var/message = list()
+ if(type) message["type"] = type
+ if(text) message["text"] = text
+ if(html) message["html"] = html
+ if(avoid_highlighting) message["avoidHighlighting"] = avoid_highlighting
+
+ // send it immediately
+ SSchat.send_immediate(target, message)
+
+/**
+ * Sends the message to the recipient (target).
+ *
+ * Recommended way to write to_chat calls:
+ * ```
+ * to_chat(client,
+ * type = MESSAGE_TYPE_INFO,
+ * html = "You have found [object]")
+ * ```
+ */
+/proc/to_chat(
+ target,
+ html,
+ type = null,
+ text = null,
+ avoid_highlighting = FALSE,
+ // FIXME: These flags are now pointless and have no effect
+ handle_whitespace = TRUE,
+ trailing_newline = TRUE,
+ confidential = FALSE
+)
+ //if(isnull(Master) || !SSchat?.initialized || !MC_RUNNING(SSchat.init_stage))
+ if(isnull(Master) || !SSchat?.subsystem_initialized)
+ to_chat_immediate(target, html, type, text, avoid_highlighting)
+ return
+
+ // Useful where the integer 0 is the entire message. Use case is enabling to_chat(target, some_boolean) while preventing to_chat(target, "")
+ html = "[html]"
+ text = "[text]"
+
+ if(!target)
+ return
+ if(!html && !text)
+ CRASH("Empty or null string in to_chat proc call.")
+ if(target == world)
+ target = GLOB.clients
+
+ // Build a message
+ var/message = list()
+ if(type) message["type"] = type
+ if(text) message["text"] = text
+ if(html) message["html"] = html
+ if(avoid_highlighting) message["avoidHighlighting"] = avoid_highlighting
+ SSchat.queue(target, message)
diff --git a/code/modules/tgui/tgui_window.dm b/code/modules/tgui/tgui_window.dm
index 180e18a518..73dfdf2803 100644
--- a/code/modules/tgui/tgui_window.dm
+++ b/code/modules/tgui/tgui_window.dm
@@ -380,6 +380,8 @@
// Resend the assets
for(var/asset in sent_assets)
send_asset(asset)
+ if("chat/resend")
+ SSchat.handle_resend(client, payload)
/datum/tgui_window/vv_edit_var(var_name, var_value)
return var_name != NAMEOF(src, id) && ..()
diff --git a/code/modules/tgui_panel/audio.dm b/code/modules/tgui_panel/audio.dm
new file mode 100644
index 0000000000..32ecd93ab8
--- /dev/null
+++ b/code/modules/tgui_panel/audio.dm
@@ -0,0 +1,42 @@
+/*!
+ * Copyright (c) 2020 Aleksej Komarov
+ * SPDX-License-Identifier: MIT
+ */
+
+/// Admin music volume, from 0 to 1.
+/client/var/admin_music_volume = 1
+
+/**
+ * public
+ *
+ * Sends music data to the browser.
+ *
+ * Optional settings:
+ * - pitch: the playback rate
+ * - start: the start time of the sound
+ * - end: when the musics stops playing
+ *
+ * required url string Must be an https URL.
+ * optional extra_data list Optional settings.
+ */
+/datum/tgui_panel/proc/play_music(url, extra_data)
+ if(!is_ready())
+ return
+ if(!findtext(url, GLOB.is_http_protocol))
+ return
+ var/list/payload = list()
+ if(length(extra_data) > 0)
+ for(var/key in extra_data)
+ payload[key] = extra_data[key]
+ payload["url"] = url
+ window.send_message("audio/playMusic", payload)
+
+/**
+ * public
+ *
+ * Stops playing music through the browser.
+ */
+/datum/tgui_panel/proc/stop_music()
+ if(!is_ready())
+ return
+ window.send_message("audio/stopMusic")
diff --git a/code/modules/tgui_panel/external.dm b/code/modules/tgui_panel/external.dm
new file mode 100644
index 0000000000..a4ce4444ca
--- /dev/null
+++ b/code/modules/tgui_panel/external.dm
@@ -0,0 +1,45 @@
+/*!
+ * Copyright (c) 2020 Aleksej Komarov
+ * SPDX-License-Identifier: MIT
+ */
+
+/client/var/datum/tgui_panel/tgui_panel
+
+/**
+ * tgui panel / chat troubleshooting verb
+ */
+/client/verb/fix_tgui_panel()
+ set name = "Fix chat"
+ set category = "OOC"
+ var/action
+ log_tgui(src, "Started fixing.", context = "verb/fix_tgui_panel")
+
+ nuke_chat()
+
+ // Failed to fix, using tgalert as fallback
+ action = tgalert(src, "Did that work?", "", "Yes", "No, switch to old ui")
+ if (action == "No, switch to old ui")
+ winset(src, "output", "on-show=&is-disabled=0&is-visible=1")
+ winset(src, "browseroutput", "is-disabled=1;is-visible=0")
+ log_tgui(src, "Failed to fix.", context = "verb/fix_tgui_panel")
+
+/client/proc/nuke_chat()
+ // Catch all solution (kick the whole thing in the pants)
+ winset(src, "output", "on-show=&is-disabled=0&is-visible=1")
+ winset(src, "browseroutput", "is-disabled=1;is-visible=0")
+ if(!tgui_panel || !istype(tgui_panel))
+ log_tgui(src, "tgui_panel datum is missing",
+ context = "verb/fix_tgui_panel")
+ tgui_panel = new(src)
+ tgui_panel.initialize(force = TRUE)
+ // Force show the panel to see if there are any errors
+ winset(src, "output", "is-disabled=1&is-visible=0")
+ winset(src, "browseroutput", "is-disabled=0;is-visible=1")
+
+/client/verb/refresh_tgui()
+ set name = "Refresh TGUI"
+ set category = "OOC"
+
+ for(var/window_id in tgui_windows)
+ var/datum/tgui_window/window = tgui_windows[window_id]
+ window.reinitialize()
diff --git a/code/modules/tgui_panel/telemetry.dm b/code/modules/tgui_panel/telemetry.dm
new file mode 100644
index 0000000000..4dabcbb01a
--- /dev/null
+++ b/code/modules/tgui_panel/telemetry.dm
@@ -0,0 +1,146 @@
+/*!
+ * Copyright (c) 2020 Aleksej Komarov
+ * SPDX-License-Identifier: MIT
+ */
+
+/**
+ * Maximum number of connection records allowed to analyze.
+ * Should match the value set in the browser.
+ */
+#define TGUI_TELEMETRY_MAX_CONNECTIONS 5
+
+/**
+ * Maximum time allocated for sending a telemetry packet.
+ */
+#define TGUI_TELEMETRY_RESPONSE_WINDOW (30 SECONDS)
+
+/// Time of telemetry request
+/datum/tgui_panel/var/telemetry_requested_at
+/// Time of telemetry analysis completion
+/datum/tgui_panel/var/telemetry_analyzed_at
+/// List of previous client connections
+/datum/tgui_panel/var/list/telemetry_connections
+
+/**
+ * private
+ *
+ * Requests some telemetry from the client.
+ */
+/datum/tgui_panel/proc/request_telemetry()
+ telemetry_requested_at = world.time
+ telemetry_analyzed_at = null
+ window.send_message("telemetry/request", list(
+ "limits" = list(
+ "connections" = TGUI_TELEMETRY_MAX_CONNECTIONS,
+ ),
+ ))
+
+/**
+ * private
+ *
+ * Analyzes a telemetry packet.
+ *
+ * Is currently only useful for detecting ban evasion attempts.
+ */
+/datum/tgui_panel/proc/analyze_telemetry(payload)
+ if(world.time > telemetry_requested_at + TGUI_TELEMETRY_RESPONSE_WINDOW)
+ message_admins("[key_name(client)] sent telemetry outside of the allocated time window.")
+ return
+ if(telemetry_analyzed_at)
+ message_admins("[key_name(client)] sent telemetry more than once.")
+ return
+ telemetry_analyzed_at = world.time
+ if(!payload)
+ return
+ telemetry_connections = payload["connections"]
+ var/len = length(telemetry_connections)
+ if(len == 0)
+ return
+ if(len > TGUI_TELEMETRY_MAX_CONNECTIONS)
+ message_admins("[key_name(client)] was kicked for sending a huge telemetry payload")
+ qdel(client)
+ return
+
+ var/ckey = client?.ckey
+ if (!ckey)
+ return
+
+ /* FIXME: Stuff we dont have > Can be reimplemented later on
+ var/list/all_known_alts = GLOB.known_alts.load_known_alts()
+ var/list/our_known_alts = list()
+
+ for (var/known_alt in all_known_alts)
+ if (known_alt[1] == ckey)
+ our_known_alts += known_alt[2]
+ else if (known_alt[2] == ckey)
+ our_known_alts += known_alt[1]
+
+ var/list/found
+
+ var/list/query_data = list()
+
+ for(var/i in 1 to len)
+ if(QDELETED(client))
+ // He got cleaned up before we were done
+ return
+ var/list/row = telemetry_connections[i]
+
+ // Check for a malformed history object
+ if (!row || row.len < 3 || (!row["ckey"] || !row["address"] || !row["computer_id"]))
+ return
+
+ if (!isnull(GLOB.round_id))
+ query_data += list(list(
+ "telemetry_ckey" = row["ckey"],
+ "address" = row["address"],
+ "computer_id" = row["computer_id"],
+ ))
+
+ if (row["ckey"] in our_known_alts)
+ continue
+
+ if (world.IsBanned(row["ckey"], row["address"], row["computer_id"], real_bans_only = TRUE))
+ found = row
+ break
+
+ CHECK_TICK
+
+ // This fucker has a history of playing on a banned account.
+ if(found)
+ var/msg = "[key_name(client)] has a banned account in connection history! (Matched: [found["ckey"]], [found["address"]], [found["computer_id"]])"
+ message_admins(msg)
+ send2tgs_adminless_only("Banned-user", msg)
+ log_admin_private(msg)
+ log_suspicious_login(msg, access_log_mirror = FALSE)
+
+ // Only log them all at the end, since it's not as important as reporting an evader
+ for (var/list/one_query as anything in query_data)
+ var/datum/db_query/query = SSdbcore.NewQuery({"
+ INSERT INTO [format_table_name("telemetry_connections")] (
+ ckey,
+ telemetry_ckey,
+ address,
+ computer_id,
+ first_round_id,
+ latest_round_id
+ ) VALUES(
+ :ckey,
+ :telemetry_ckey,
+ INET_ATON(:address),
+ :computer_id,
+ :round_id,
+ :round_id
+ ) ON DUPLICATE KEY UPDATE latest_round_id = :round_id
+ "}, list(
+ "ckey" = ckey,
+ "telemetry_ckey" = one_query["telemetry_ckey"],
+ "address" = one_query["address"],
+ "computer_id" = one_query["computer_id"],
+ "round_id" = GLOB.round_id,
+ ))
+ query.Execute()
+ qdel(query)
+ */
+
+#undef TGUI_TELEMETRY_MAX_CONNECTIONS
+#undef TGUI_TELEMETRY_RESPONSE_WINDOW
diff --git a/code/modules/tgui_panel/tgui_panel.dm b/code/modules/tgui_panel/tgui_panel.dm
new file mode 100644
index 0000000000..ffb31cd788
--- /dev/null
+++ b/code/modules/tgui_panel/tgui_panel.dm
@@ -0,0 +1,102 @@
+/*!
+ * Copyright (c) 2020 Aleksej Komarov
+ * SPDX-License-Identifier: MIT
+ */
+
+/**
+ * tgui_panel datum
+ * Hosts tgchat and other nice features.
+ */
+/datum/tgui_panel
+ var/client/client
+ var/datum/tgui_window/window
+ var/broken = FALSE
+ var/initialized_at
+ var/oldchat = FALSE
+
+/datum/tgui_panel/New(client/client, id)
+ src.client = client
+ window = new(client, id)
+ window.subscribe(src, PROC_REF(on_message))
+
+/datum/tgui_panel/Del()
+ window.unsubscribe(src)
+ window.close()
+ return ..()
+
+/**
+ * public
+ *
+ * TRUE if panel is initialized and ready to receive messages.
+ */
+/datum/tgui_panel/proc/is_ready()
+ return !broken && window.is_ready()
+
+/**
+ * public
+ *
+ * Initializes tgui panel.
+ */
+/datum/tgui_panel/proc/initialize(force = FALSE)
+ set waitfor = FALSE
+ // Minimal sleep to defer initialization to after client constructor
+ sleep(1 TICKS)
+ initialized_at = world.time
+ // Perform a clean initialization
+ window.initialize(
+ strict_mode = TRUE,
+ assets = list(
+ get_asset_datum(/datum/asset/simple/tgui_panel),
+ ))
+ window.send_asset(get_asset_datum(/datum/asset/simple/fontawesome))
+ window.send_asset(get_asset_datum(/datum/asset/simple/tgfont))
+ window.send_asset(get_asset_datum(/datum/asset/spritesheet/chat))
+ // Other setup
+ request_telemetry()
+ addtimer(CALLBACK(src, PROC_REF(on_initialize_timed_out)), 5 SECONDS)
+
+/**
+ * private
+ *
+ * Called when initialization has timed out.
+ */
+/datum/tgui_panel/proc/on_initialize_timed_out()
+ // Currently does nothing but sending a message to old chat.
+ // SEND_TEXT(client, "Failed to load fancy chat, click HERE to attempt to reload it.")
+
+/**
+ * private
+ *
+ * Callback for handling incoming tgui messages.
+ */
+/datum/tgui_panel/proc/on_message(type, payload)
+ if(type == "ready")
+ broken = FALSE
+ window.send_message("update", list(
+ "config" = list(
+ "client" = list(
+ "ckey" = client.ckey,
+ "address" = client.address,
+ "computer_id" = client.computer_id,
+ ),
+ "window" = list(
+ "fancy" = FALSE,
+ "locked" = FALSE,
+ ),
+ ),
+ ))
+ return TRUE
+ if(type == "audio/setAdminMusicVolume")
+ client.admin_music_volume = payload["volume"]
+ return TRUE
+ if(type == "telemetry")
+ analyze_telemetry(payload)
+ return TRUE
+
+/**
+ * public
+ *
+ * Sends a round restart notification.
+ */
+/datum/tgui_panel/proc/send_roundrestart()
+ window.send_message("roundrestart")
diff --git a/code/modules/vchat/js/vchat.min.js b/code/modules/vchat/js/vchat.min.js
index 545fc849f4..915fcac4bb 100644
--- a/code/modules/vchat/js/vchat.min.js
+++ b/code/modules/vchat/js/vchat.min.js
@@ -1 +1,5 @@
-!function(){var e=console.log;console.log=function(t){send_debug(t),e.apply(console,arguments)};var t=console.error;console.error=function(e){send_debug(e),t.apply(console,arguments)},window.onerror=function(e,t,s,a,n){var o="";return n&&n.stack&&(o=n.stack),send_debug(e+" ("+t+"@"+s+":"+a+") "+n+"|UA: "+navigator.userAgent+"|Stack: "+o),!0}}();var vueapp,vchat_opts={msBeforeDropped:3e4,cookiePrefix:"vst-",alwaysShow:["vc_looc","vc_system"],vchatTabsVer:1},DARKMODE_COLORS={buttonBgColor:"#40628a",buttonTextColor:"#FFFFFF",windowBgColor:"#272727",highlightColor:"#009900",tabTextColor:"#FFFFFF",tabBackgroundColor:"#272727"},LIGHTMODE_COLORS={buttonBgColor:"none",buttonTextColor:"#000000",windowBgColor:"none",highlightColor:"#007700",tabTextColor:"#000000",tabBackgroundColor:"none"},set_storage=set_cookie,get_storage=get_cookie,domparser=new DOMParser;storageAvailable("localStorage")&&(set_storage=set_localstorage,get_storage=get_localstorage);var vchat_state={ready:!1,byond_ip:null,byond_cid:null,byond_ckey:null,lastPingReceived:0,latency_sent:0,lastId:0};function start_vchat(){start_vue(),vchat_state.ready=!0,push_Topic("done_loading"),push_Topic_showingnum(this.showingnum),doWinset("htmloutput",{"is-visible":!0}),doWinset("oldoutput",{"is-visible":!1}),doWinset("chatloadlabel",{"is-visible":!1}),setInterval(check_ping,vchat_opts.msBeforeDropped),send_debug("VChat Loaded!")}function start_vue(){vueapp=new Vue({el:"#app",data:{messages:[],shown_messages:[],unshown_messages:0,archived_messages:[],tabs:[{name:"Main",categories:[],immutable:!0,active:!0}],unread_messages:{},editing:!1,paused:!1,latency:0,reconnecting:!1,ext_styles:"",is_admin:!1,inverted:!1,crushing:3,animated:!1,fontsize:.9,lineheight:130,showingnum:200,type_table:[{matches:".filter_say, .say, .emote, .emotesubtle",becomes:"vc_localchat",pretty:"Local Chat",tooltip:"In-character local messages (say, emote, etc)",required:!1,admin:!1},{matches:".filter_radio, .alert, .syndradio, .centradio, .airadio, .entradio, .comradio, .secradio, .engradio, .medradio, .sciradio, .supradio, .srvradio, .expradio, .radio, .deptradio, .newscaster",becomes:"vc_radio",pretty:"Radio Comms",tooltip:"All departments of radio messages",required:!1,admin:!1},{matches:".filter_notice, .notice:not(.pm), .adminnotice, .info, .sinister, .cult",becomes:"vc_info",pretty:"Notices",tooltip:"Non-urgent messages from the game and items",required:!1,admin:!1},{matches:".filter_warning, .warning:not(.pm), .critical, .userdanger, .italics",becomes:"vc_warnings",pretty:"Warnings",tooltip:"Urgent messages from the game and items",required:!1,admin:!1},{matches:".filter_deadsay, .deadsay",becomes:"vc_deadchat",pretty:"Deadchat",tooltip:"All of deadchat",required:!1,admin:!1},{matches:".filter_pray",becomes:"vc_pray",pretty:"Pray",tooltip:"Prayer messages",required:!1,admin:!1},{matches:".ooc, .filter_ooc",becomes:"vc_globalooc",pretty:"Global OOC",tooltip:"The bluewall of global OOC messages",required:!1,admin:!1},{matches:".nif",becomes:"vc_nif",pretty:"NIF Messages",tooltip:"Messages from the NIF itself and people inside",required:!1,admin:!1},{matches:".psay, .pemote",becomes:"vc_pmessage",pretty:"Pred/Prey Messages",tooltip:"Messages from / to absorbed or dominated prey",required:!1,admin:!1},{matches:".mentor_channel, .mentor",becomes:"vc_mentor",pretty:"Mentor messages",tooltip:"Mentorchat and mentor pms",required:!1,admin:!1},{matches:".filter_pm, .pm",becomes:"vc_adminpm",pretty:"Admin PMs",tooltip:"Messages to/from admins ('adminhelps')",required:!1,admin:!1},{matches:".filter_ASAY, .admin_channel",becomes:"vc_adminchat",pretty:"Admin Chat",tooltip:"ASAY messages",required:!1,admin:!0},{matches:".filter_MSAY, .mod_channel",becomes:"vc_modchat",pretty:"Mod Chat",tooltip:"MSAY messages",required:!1,admin:!0},{matches:".filter_ESAY, .event_channel",becomes:"vc_eventchat",pretty:"Event Chat",tooltip:"ESAY messages",required:!1,admin:!0},{matches:".filter_combat, .danger",becomes:"vc_combat",pretty:"Combat Logs",tooltip:"Urist McTraitor has stabbed you with a knife!",required:!1,admin:!1},{matches:".filter_adminlogs, .log_message",becomes:"vc_adminlogs",pretty:"Admin Logs",tooltip:"ADMIN LOG: Urist McAdmin has jumped to coordinates X, Y, Z",required:!1,admin:!0},{matches:".filter_attacklogs",becomes:"vc_attacklogs",pretty:"Attack Logs",tooltip:"Urist McTraitor has shot John Doe",required:!1,admin:!0},{matches:".filter_debuglogs",becomes:"vc_debuglogs",pretty:"Debug Logs",tooltip:"DEBUG: SSPlanets subsystem Recover().",required:!1,admin:!0},{matches:".looc",becomes:"vc_looc",pretty:"Local OOC",tooltip:"Local OOC messages, always enabled",required:!0},{matches:".rlooc",becomes:"vc_rlooc",pretty:"Remote LOOC",tooltip:"Remote LOOC messages",required:!1,admin:!0},{matches:".boldannounce, .filter_system",becomes:"vc_system",pretty:"System Messages",tooltip:"Messages from your client, always enabled",required:!0},{matches:".unsorted",becomes:"vc_unsorted",pretty:"Unsorted",tooltip:"Messages that don't have any filters.",required:!1,admin:!1}]},mounted:function(){this.load_settings();var e=new XMLHttpRequest;e.open("GET","ss13styles.css"),e.onreadystatechange=(function(){this.ext_styles=e.responseText}).bind(this),e.send()},updated:function(){this.editing||this.paused||window.scrollTo(0,document.getElementById("messagebox").scrollHeight)},watch:{reconnecting:function(e,t){!0==e&&!1==t?this.internal_message("Your client has lost connection to the server, or there is severe lag. Your client will reconnect if possible."):!1==e&&!0==t&&this.internal_message("Your client has reconnected to the server.")},inverted:function(e){set_storage("darkmode",e),e?(document.body.classList.add("inverted"),switch_ui_mode(DARKMODE_COLORS)):(document.body.classList.remove("inverted"),switch_ui_mode(LIGHTMODE_COLORS))},crushing:function(e){set_storage("crushing",e)},animated:function(e){set_storage("animated",e)},fontsize:function(e,t){if(isNaN(e)){this.fontsize=t;return}e<.2?this.fontsize=.2:e>5&&(this.fontsize=5),set_storage("fontsize",e)},lineheight:function(e,t){if(!isFinite(e)){this.lineheight=t;return}e<100?this.lineheight=100:e>200&&(this.lineheight=200),set_storage("lineheight",e)},showingnum:function(e,t){if(!isFinite(e)){this.showingnum=t;return}(e=Math.floor(e))<50?this.showingnum=50:e>2e3&&(this.showingnum=2e3),set_storage("showingnum",this.showingnum),push_Topic_showingnum(this.showingnum),this.attempt_archive()},current_categories:function(e,t){e.length&&this.apply_filter(e)}},computed:{active_tab:function(){return this.tabs.find(function(e){return e.active})},ping_classes:function(){return this.latency?"?"==this.latency?"grey":this.latency<0?"red":this.latency<=200?"green":this.latency<=400?"yellow":"grey":this.reconnecting?"red":"green"},current_categories:function(){return this.active_tab==this.tabs[0]?[]:this.active_tab.categories.concat(vchat_opts.alwaysShow)}},methods:{load_settings:function(){this.inverted=get_storage("darkmode",!1),this.crushing=get_storage("crushing",3),this.animated=get_storage("animated",!1),this.fontsize=get_storage("fontsize",.9),this.lineheight=get_storage("lineheight",130),this.showingnum=get_storage("showingnum",200),isNaN(this.crushing)&&(this.crushing=3),isNaN(this.fontsize)&&(this.fontsize=.9),this.load_tabs()},load_tabs:function(){var e=get_storage("tabs");if(e){var t=JSON.parse(e);if(!t.version||!t.tabs){this.internal_message("There was a problem loading your tabs. Any new ones you make will be saved, however.");return}if(!t.version==vchat_opts.vchatTabsVer){this.internal_message("Your saved tabs are for an older version of VChat and must be recreated, sorry.");return}this.tabs.push.apply(this.tabs,t.tabs)}},save_tabs:function(){var e={version:vchat_opts.vchatTabsVer,tabs:[]};this.tabs.forEach(function(t){if(!t.immutable){var s=t.name,a=[];t.categories.forEach(function(e){a.push(e)}),e.tabs.push({name:s,categories:a,immutable:!1,active:!1})}}),set_storage("tabs",JSON.stringify(e))},switchtab:function(e){e!=this.active_tab&&(this.active_tab.active=!1,e.active=!0,e.categories.forEach(function(e){this.unread_messages[e]=0},this),this.apply_filter(this.current_categories))},editmode:function(){this.editing=!this.editing,this.save_tabs()},pause:function(){this.paused=!this.paused},newtab:function(){this.tabs.push({name:"New Tab",categories:[],immutable:!1,active:!1}),this.switchtab(this.tabs[this.tabs.length-1])},renametab:function(){if(!this.active_tab.immutable){var e=this.active_tab,t=window.prompt("Type the desired tab name:",e.name);null!==t&&""!==t&&null!==e&&(e.name=t)}},deltab:function(e){e||(e=this.active_tab),!e.immutable&&(this.switchtab(this.tabs[0]),this.tabs.splice(this.tabs.indexOf(e),1))},movetab:function(e,t){if(e&&!e.immutable){var s=this.tabs.indexOf(e);this.tabs.splice(s+t,0,this.tabs.splice(s,1)[0])}},tab_unread_count:function(e){var t=0,s=this.unread_messages;return e.categories.find(function(e){s[e]&&(t+=s[e])}),t},tab_unread_categories:function(e){var t=!1,s=this.unread_messages;return e.categories.find(function(e){if(s[e])return t=!0,!0}),{red:t,grey:!t}},attempt_archive:function(){if(this.messages.length>this.showingnum){var e=this.messages.splice(0,20);Array.prototype.push.apply(this.archived_messages,e)}},apply_filter:function(e){this.shown_messages.splice(0),this.unshown_messages=0,this.messages.forEach(function(t){e.indexOf(t.category)>-1&&this.shown_messages.push(t)},this),this.archived_messages.forEach(function(t){e.indexOf(t.category)>-1&&this.unshown_messages++},this)},add_message:function(e){let t={time:e.time,category:"error",content:e.message,repeats:1};if(t.category=this.get_category(t.content),"vc_unsorted"==t.category&&(t.content=""+t.content+""),this.crushing){let s=this.messages.slice(-this.crushing);for(let a=s.length-1;a>=0;a--){let n=s[a];n.content==t.content&&(t.repeats+=n.repeats,this.messages.splice(this.messages.indexOf(n),1))}}t.content=t.content.replace(/(\b(https?):\/\/[\-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|])/img,'$1'),this.current_categories.length&&0>this.current_categories.indexOf(t.category)?(isNaN(this.unread_messages[t.category])&&(this.unread_messages[t.category]=0),this.unread_messages[t.category]+=1):this.current_categories.length&&this.shown_messages.push(t),t.id=++vchat_state.lastId,this.attempt_archive(),this.messages.push(t)},internal_message:function(e){let t={time:this.messages.length?this.messages.slice(-1).time+1:0,category:"vc_system",content:"[VChat Internal] "+e+""};t.id=++vchat_state.lastId,this.messages.push(t)},on_mouseup:function(e){let t=e.target;"getSelection"in window&&!1===window.getSelection().isCollapsed||t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName)||(focusMapWindow(),e.preventDefault(),e.target.click())},click_message:function(e){let t=e.target;if("A"===t.tagName){e.stopPropagation(),e.preventDefault?e.preventDefault():e.returnValue=!1;var s=t.getAttribute("href");"?"==s[0]||s.length>=8&&"byond://"==s.substring(0,8)?window.location=s:window.location="byond://?action=openLink&link="+encodeURIComponent(s)}},get_category:function(e){if(!vchat_state.ready){push_Topic("not_ready");return}let t=domparser.parseFromString(e,"text/html").querySelector("span"),s="vc_unsorted";return t&&this.type_table.find(function(e){if(t.msMatchesSelector(e.matches))return s=e.becomes,!0}),s},save_chatlog:function(){var e="