Tgui payload chunking (#90295)

## About The Pull Request

Dream Seeker will not send topic calls greater than 2kb in size. There
are cases where tgui will attempt to send `ui_act` payloads larger than
this, such as writing on paper. This PR takes payloads that would be
larger than 2kb, splits them into payloads that would be roughly 1kb
(after URL encoding), and sends them to the server in sequence. To
prevent abuse and/or topic spam, a config option has been added to put a
limit on the number of chunks for which the server will accept a
payload, defaulting to 10.

## Why It's Good For The Game

Fixes #90056, along with several other things that were affected by the
change to WebView2 in 516.

## Changelog

🆑
code: Any tgui message that would be too big to send to the server is
now split into chunks and sent in sequence. This fixes several issues,
such as...
fix: It is once again possible to save large amounts of text on paper at
once.
/🆑

---------

Co-authored-by: Lucy <lucy@absolucy.moe>
This commit is contained in:
Y0SH1M4S73R
2025-04-01 13:12:03 -07:00
committed by GitHub
co-authored by Lucy
parent 88c2213f1e
commit bfbdefce33
5 changed files with 208 additions and 1 deletions
+42
View File
@@ -26,6 +26,8 @@
var/initial_inline_js
var/initial_inline_css
var/list/oversized_payloads = list()
/**
* public
*
@@ -380,6 +382,46 @@
reinitialize()
if("chat/resend")
SSchat.handle_resend(client, payload)
if("oversizedPayloadRequest")
var/payload_id = payload["id"]
var/chunk_count = payload["chunkCount"]
var/permit_payload = chunk_count <= CONFIG_GET(number/tgui_max_chunk_count)
if(permit_payload)
create_oversized_payload(payload_id, payload["type"], chunk_count)
send_message("oversizePayloadResponse", list("allow" = permit_payload, "id" = payload_id))
if("payloadChunk")
var/payload_id = payload["id"]
append_payload_chunk(payload_id, payload["chunk"])
send_message("acknowlegePayloadChunk", list("id" = payload_id))
/datum/tgui_window/vv_edit_var(var_name, var_value)
return var_name != NAMEOF(src, id) && ..()
/datum/tgui_window/proc/create_oversized_payload(payload_id, message_type, chunk_count)
if(oversized_payloads[payload_id])
stack_trace("Attempted to create oversized tgui payload with duplicate ID.")
return
oversized_payloads[payload_id] = list(
"type" = message_type,
"count" = chunk_count,
"chunks" = list(),
"timeout" = addtimer(CALLBACK(src, PROC_REF(remove_oversized_payload), payload_id), 1 SECONDS, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_STOPPABLE)
)
/datum/tgui_window/proc/append_payload_chunk(payload_id, chunk)
var/list/payload = oversized_payloads[payload_id]
if(!payload)
return
var/list/chunks = payload["chunks"]
chunks += chunk
if(length(chunks) >= payload["count"])
deltimer(payload["timeout"])
var/message_type = payload["type"]
var/final_payload = chunks.Join()
remove_oversized_payload(payload_id)
on_message(message_type, json_decode(final_payload), list("type" = message_type, "payload" = final_payload, "tgui" = TRUE, "window_id" = id))
else
payload["timeout"] = addtimer(CALLBACK(src, PROC_REF(remove_oversized_payload), payload_id), 1 SECONDS, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_STOPPABLE)
/datum/tgui_window/proc/remove_oversized_payload(payload_id)
oversized_payloads -= payload_id