mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-18 13:43:27 +00:00
* tgchat (#52426) Replaces goonchat with a tgui based chat panel Fixes #52898 Fixes #52663 It is as fast as goonchat was (if not faster in certain circumstances), and is very extensible. It has all the necessary code for sorting messages into categories, which means that one of the next features will be multiple tab support. Additional features that you will get with tgchat right now: Massively faster server-side performance compared to goonchat, especially if batching multiple messages to one client. Message persistence across rounds and reconnects. (All messages are stored client-side in IndexedDB) More robust scroll tracking. If you scroll up, it will not change the scroll position on new messages like goonchat did. Multiple message combining. (Currently set to combine up to 5 messages over last 5 seconds). If using the highlighting feature, it highlights the whole message as well as the matching word. "Now playing" widget, with preview of the song title, a knob for adjusting the volume and a stop button. Architecture is as following: ``` to_chat() -+ | SSchat (queue, batching) | window.send_message() | v +-------------+ | tgui-panel | |+-----------+| || tgchat || |+-----------+| +-------------+ ``` Subsystem is basically goonchat, but without all the garbage that slows the servers down (string concatenation, double urlencoding, sanitizing, etc). Now, instead of all that, it's being slowed down by json_encode in /datum/tgui_window/proc/send_message, which IMO is completely worth it, and allows sending various templates and widgets to tgchat. /datum/tgui_window abstracts the whole window away from you, establishes a nice message-passing interface between DM and JS, with two message queues on each side, automatically loads js/css assets for you, basically does everything. You as a developer only have to worry about sending/receiving messages and write javascript. tgui-panel is a slimmed down version of tgui, and functions as a container for various widgets, and tgchat is one of them. It of course can be expanded with more stuff. It's also a separate entry point and a JS bundle, so it's not bloating the main tgui bundle, and is currently sitting at about 230kB. * tgchat Co-authored-by: Aleksej Komarov <stylemistake@gmail.com>
81 lines
2.3 KiB
Plaintext
81 lines
2.3 KiB
Plaintext
/**
|
|
* 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/list/found
|
|
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 (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)
|
|
log_admin_private(msg)
|