mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-05-17 20:30:46 +01:00
6a771809f2
* fix tgui chunking bug on 2 chunks * ugh * ugh * should be fine * people might have longer pint times
34 lines
1.0 KiB
Plaintext
34 lines
1.0 KiB
Plaintext
/datum/tgui_say/proc/handle_packets(id, total_packets, packet)
|
|
id = text2num(id)
|
|
|
|
var/total = text2num(total_packets)
|
|
if(id == 1)
|
|
if(total > MAX_MESSAGE_CHUNKS)
|
|
return null
|
|
|
|
partial_packets = list("chunks" = new /list(total),
|
|
"timeout" = addtimer(CALLBACK(src, PROC_REF(clear_oversized_payload)), 10 SECONDS, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_STOPPABLE)
|
|
)
|
|
|
|
var/list/chunks = partial_packets["chunks"]
|
|
chunks[id] = packet
|
|
|
|
if(id != total)
|
|
if(id > 1)
|
|
partial_packets["timeout"] = addtimer(CALLBACK(src, PROC_REF(clear_oversized_payload)), 10 SECONDS, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_STOPPABLE)
|
|
return null
|
|
|
|
var/assembled_payload = ""
|
|
for(var/received_packet in partial_packets["chunks"])
|
|
assembled_payload += received_packet
|
|
|
|
deltimer(partial_packets["timeout"])
|
|
partial_packets = null
|
|
if (!rustg_json_is_valid(assembled_payload))
|
|
log_tgui(usr, "Error: Invalid JSON")
|
|
return
|
|
return json_decode(assembled_payload)
|
|
|
|
/datum/tgui_say/proc/clear_oversized_payload()
|
|
partial_packets = null
|