diff --git a/aurorastation.dme b/aurorastation.dme index 05bf8313d14..f726fa459c5 100644 --- a/aurorastation.dme +++ b/aurorastation.dme @@ -3894,6 +3894,7 @@ #include "code\modules\tgui_input\say_modal\typing.dm" #include "code\modules\tgui_panel\audio.dm" #include "code\modules\tgui_panel\external.dm" +#include "code\modules\tgui_panel\telemetry.dm" #include "code\modules\tgui_panel\tgui_panel.dm" #include "code\modules\tooltip\tooltip.dm" #include "code\modules\turbolift\_turbolift.dm" diff --git a/code/modules/tgui_panel/telemetry.dm b/code/modules/tgui_panel/telemetry.dm new file mode 100644 index 00000000000..d3e8e281eb6 --- /dev/null +++ b/code/modules/tgui_panel/telemetry.dm @@ -0,0 +1,69 @@ +/*! + * 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. + * + * Does nothing except kick people who try to send a billion requests. + */ +/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 + +#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 index 3404e3c2ccf..05ebeb692dd 100644 --- a/code/modules/tgui_panel/tgui_panel.dm +++ b/code/modules/tgui_panel/tgui_panel.dm @@ -51,7 +51,9 @@ window.send_asset(get_asset_datum(/datum/asset/simple/namespaced/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) + window.send_message("testTelemetryCommand") /** * private diff --git a/html/changelogs/johnwildkins-brother.yml b/html/changelogs/johnwildkins-brother.yml new file mode 100644 index 00000000000..9b07f542494 --- /dev/null +++ b/html/changelogs/johnwildkins-brother.yml @@ -0,0 +1,13 @@ +# Your name. +author: JohnWildkins + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - refactor: "Fix TGUI chat / stat panel failing to load properly when connecting." diff --git a/tgui/packages/tgui-panel/telemetry.js b/tgui/packages/tgui-panel/telemetry.js index d1f7346af60..581d32f3069 100644 --- a/tgui/packages/tgui-panel/telemetry.js +++ b/tgui/packages/tgui-panel/telemetry.js @@ -11,12 +11,10 @@ const logger = createLogger('telemetry'); const MAX_CONNECTIONS_STORED = 10; -// prettier-ignore -const connectionsMatch = (a, b) => ( - a.ckey === b.ckey - && a.address === b.address - && a.computer_id === b.computer_id -); +const connectionsMatch = (a, b) => + a.ckey === b.ckey && + a.address === b.address && + a.computer_id === b.computer_id; export const telemetryMiddleware = (store) => { let telemetry; @@ -38,6 +36,14 @@ export const telemetryMiddleware = (store) => { Byond.sendMessage('telemetry', { connections }); return; } + // For whatever reason we didn't get the telemetry, re-request + if (type === 'testTelemetryCommand') { + setTimeout(() => { + if (!telemetry) { + Byond.sendMessage('ready'); + } + }, 500); + } // Keep telemetry up to date if (type === 'backend/update') { next(action); @@ -58,9 +64,10 @@ export const telemetryMiddleware = (store) => { } // Append a connection record let telemetryMutated = false; - // prettier-ignore - const duplicateConnection = telemetry.connections - .find(conn => connectionsMatch(conn, client)); + + const duplicateConnection = telemetry.connections.find((conn) => + connectionsMatch(conn, client), + ); if (!duplicateConnection) { telemetryMutated = true; telemetry.connections.unshift(client); diff --git a/tgui/public/tgui.html b/tgui/public/tgui.html index fadae54e191..cadc2f2db0a 100644 --- a/tgui/public/tgui.html +++ b/tgui/public/tgui.html @@ -766,7 +766,6 @@ NNNNNNNN NNNNNNN TTTTTTTTTTT OOOOOOOOO SSSSSSSSSSSSS