Skip to content

Commit

Permalink
TGS Test Merge (#8492)
Browse files Browse the repository at this point in the history
  • Loading branch information
cm13-github committed Mar 5, 2025
2 parents 6816b12 + f003f71 commit fb322f7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions code/__DEFINES/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@
#define MAX_PAPER_MESSAGE_LEN 3072
#define MAX_BOOK_MESSAGE_LEN 9216
#define MAX_NAME_LEN 28

#define MAX_MESSAGE_CHUNKS 20
27 changes: 27 additions & 0 deletions code/modules/tgui/tgui.dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
/// If the window should be closed with other windows when requested
var/closeable = TRUE

/// Any partial packets that we have received from TGUI, waiting to be sent
var/partial_packets

/**
* public
*
Expand Down Expand Up @@ -345,6 +348,30 @@
// Pass act type messages to ui_act
if(type && copytext(type, 1, 5) == "act/")
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

log_tgui(user, "Action: [act_type] [href_list["payload"]]",
window = window,
src_object = src_object)
Expand Down
19 changes: 19 additions & 0 deletions tgui/public/tgui.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,28 @@
? { type: type, payload: payload }
: type;
// JSON-encode the payload

if (message.payload !== null && message.payload !== undefined) {
message.payload = JSON.stringify(message.payload);

if(!Byond.TRIDENT && message.payload.length > 512) {
var chunks = [];

for(var i = 0, charsLength = message.payload.length; i < charsLength; i += 512) {
chunks.push(message.payload.substring(i, i + 512))
}

for(var i = 0; i < chunks.length; i++) {
var to_send = chunks[i]

message = { type: type, packet: to_send, packetId: i + 1, totalPackets: chunks.length, tgui: 1, window_id: Byond.windowId };
Byond.topic(message);
}

return;
}
}

// Append an identifying header
assign(message, {
tgui: 1,
Expand Down
1 change: 1 addition & 0 deletions tools/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const DmTarget = new Juke.Target({
"html/**",
"icons/**",
"interface/**",
"tgui/public/tgui.html",
`${DME_NAME}.dme`,
NamedVersionFile,
],
Expand Down

0 comments on commit fb322f7

Please sign in to comment.