mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
[MIRROR] adds a timeout to tgui payloads (#11535)
Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8bd4e1a84a
commit
b3e84aecb7
61
code/modules/tgui/helpers.dm
Normal file
61
code/modules/tgui/helpers.dm
Normal file
@@ -0,0 +1,61 @@
|
||||
/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
|
||||
return json_decode(assembled_payload)
|
||||
|
||||
/datum/tgui_say/proc/clear_oversized_payload()
|
||||
partial_packets = null
|
||||
|
||||
/datum/tgui/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
|
||||
return json_decode(assembled_payload)
|
||||
|
||||
/datum/tgui/proc/clear_oversized_payload()
|
||||
partial_packets = null
|
||||
@@ -379,26 +379,9 @@
|
||||
var/act_type = copytext(type, 5)
|
||||
var/id = href_list["packetId"]
|
||||
if(!isnull(id))
|
||||
id = text2num(id)
|
||||
|
||||
var/total = text2num(href_list["totalPackets"])
|
||||
if(id == 1)
|
||||
if(total > MAX_MESSAGE_CHUNKS)
|
||||
return
|
||||
|
||||
partial_packets = new /list(total)
|
||||
|
||||
partial_packets[id] = href_list["packet"]
|
||||
|
||||
if(id != total)
|
||||
return
|
||||
|
||||
var/assembled_payload = ""
|
||||
for(var/packet in partial_packets)
|
||||
assembled_payload += packet
|
||||
|
||||
payload = json_decode(assembled_payload)
|
||||
partial_packets = null
|
||||
payload = handle_packets(id, href_list["totalPackets"], href_list["packet"])
|
||||
if(!payload)
|
||||
return FALSE
|
||||
#ifdef TGUI_DEBUGGING
|
||||
log_tgui(user, "Action: [act_type] [href_list["payload"]], Window: [window.id], Source: [src_object]")
|
||||
#endif
|
||||
|
||||
@@ -134,26 +134,9 @@
|
||||
if(type == "entry" || type == "force")
|
||||
var/id = href_list["packetId"]
|
||||
if(!isnull(id))
|
||||
id = text2num(id)
|
||||
|
||||
var/total = text2num(href_list["totalPackets"])
|
||||
if(id == 1)
|
||||
if(total > MAX_MESSAGE_CHUNKS)
|
||||
return
|
||||
|
||||
partial_packets = new /list(total)
|
||||
|
||||
partial_packets[id] = href_list["packet"]
|
||||
|
||||
if(id != total)
|
||||
return
|
||||
|
||||
var/assembled_payload = ""
|
||||
for(var/packet in partial_packets)
|
||||
assembled_payload += packet
|
||||
|
||||
payload = json_decode(assembled_payload)
|
||||
partial_packets = null
|
||||
payload = handle_packets(id, href_list["totalPackets"], href_list["packet"])
|
||||
if(!payload)
|
||||
return FALSE
|
||||
handle_entry(type, payload)
|
||||
return TRUE
|
||||
if(type == "lenwarn")
|
||||
|
||||
@@ -4654,6 +4654,7 @@
|
||||
#include "code\modules\tgs\includes.dm"
|
||||
#include "code\modules\tgs_commands\vorestation.dm"
|
||||
#include "code\modules\tgui\external.dm"
|
||||
#include "code\modules\tgui\helpers.dm"
|
||||
#include "code\modules\tgui\modal.dm"
|
||||
#include "code\modules\tgui\states.dm"
|
||||
#include "code\modules\tgui\tgui.dm"
|
||||
|
||||
Reference in New Issue
Block a user