mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-09 23:27:56 +01:00
21b4095dfd
Upstream 04/17/2026 fixes https://github.com/Bubberstation/Bubberstation/issues/5549 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com> Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com> Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com> Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com> Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com> Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com> Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com> Co-authored-by: loganuk <fakeemail123@aol.com> Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com> Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com> Co-authored-by: Lucy <lucy@absolucy.moe> Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com> Co-authored-by: Isratosh <Isratosh@hotmail.com> Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com> Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com> Co-authored-by: Alexander V. <volas@ya.ru> Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com> Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> Co-authored-by: Cameron Lennox <killer65311@gmail.com> Co-authored-by: Tim <timothymtorres@gmail.com> Co-authored-by: Iamgoofball <iamgoofball@gmail.com> Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com> Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com> Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com> Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com> Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com> Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com> Co-authored-by: Josh <josh.adam.powell@gmail.com> Co-authored-by: Josh Powell <josh.powell@softwire.com> Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com> Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com> Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com> Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
99 lines
3.3 KiB
Plaintext
99 lines
3.3 KiB
Plaintext
/*!
|
|
* Copyright (c) 2020 Aleksej Komarov
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
SUBSYSTEM_DEF(chat)
|
|
name = "Chat"
|
|
ss_flags = SS_TICKER|SS_NO_INIT
|
|
wait = 1
|
|
priority = FIRE_PRIORITY_CHAT
|
|
init_stage = INITSTAGE_LAST
|
|
|
|
/// Assosciates a ckey with a list of messages to send to them.
|
|
var/list/list/datum/chat_payload/client_to_payloads = list()
|
|
|
|
/// Associates a ckey with an assosciative list of their last CHAT_RELIABILITY_HISTORY_SIZE messages.
|
|
var/list/list/datum/chat_payload/client_to_reliability_history = list()
|
|
|
|
/// Assosciates a ckey with their next sequence number.
|
|
var/list/client_to_sequence_number = list()
|
|
|
|
/datum/controller/subsystem/chat/proc/generate_payload(client/target, message_data)
|
|
var/sequence = client_to_sequence_number[target.ckey]
|
|
client_to_sequence_number[target.ckey] += 1
|
|
|
|
var/datum/chat_payload/payload = new
|
|
payload.sequence = sequence
|
|
payload.content = message_data
|
|
|
|
if(!(target.ckey in client_to_reliability_history))
|
|
client_to_reliability_history[target.ckey] = list()
|
|
var/list/client_history = client_to_reliability_history[target.ckey]
|
|
client_history["[sequence]"] = payload
|
|
|
|
if(length(client_history) > CHAT_RELIABILITY_HISTORY_SIZE)
|
|
var/oldest = text2num(client_history[1])
|
|
for(var/index in 2 to length(client_history))
|
|
var/test = text2num(client_history[index])
|
|
if(test < oldest)
|
|
oldest = test
|
|
client_history -= "[oldest]"
|
|
return payload
|
|
|
|
/datum/controller/subsystem/chat/proc/send_payload_to_client(client/target, datum/chat_payload/payload)
|
|
target.tgui_panel.window.send_message("chat/message", payload.into_message())
|
|
SEND_TEXT(target, payload.get_content_as_html())
|
|
|
|
/datum/controller/subsystem/chat/fire()
|
|
for(var/ckey in client_to_payloads)
|
|
var/client/target = GLOB.directory[ckey]
|
|
if(isnull(target)) // verify client still exists
|
|
LAZYREMOVE(client_to_payloads, ckey)
|
|
continue
|
|
|
|
for(var/datum/chat_payload/payload as anything in client_to_payloads[ckey])
|
|
send_payload_to_client(target, payload)
|
|
LAZYREMOVE(client_to_payloads, ckey)
|
|
|
|
if(MC_TICK_CHECK)
|
|
return
|
|
|
|
/datum/controller/subsystem/chat/proc/queue(queue_target, list/message_data)
|
|
var/list/targets = islist(queue_target) ? queue_target : list(queue_target)
|
|
for(var/target in targets)
|
|
var/client/client = CLIENT_FROM_VAR(target)
|
|
if(isnull(client))
|
|
continue
|
|
LAZYADDASSOCLIST(client_to_payloads, client.ckey, generate_payload(client, message_data))
|
|
|
|
/datum/controller/subsystem/chat/proc/send_immediate(send_target, list/message_data)
|
|
var/list/targets = islist(send_target) ? send_target : list(send_target)
|
|
for(var/target in targets)
|
|
var/client/client = CLIENT_FROM_VAR(target)
|
|
if(isnull(client))
|
|
continue
|
|
send_payload_to_client(client, generate_payload(client, message_data))
|
|
|
|
/datum/controller/subsystem/chat/proc/handle_resend(client/client, sequence)
|
|
var/list/client_history = client_to_reliability_history[client.ckey]
|
|
sequence = "[sequence]"
|
|
if(isnull(client_history) || !(sequence in client_history))
|
|
return
|
|
|
|
var/datum/chat_payload/payload = client_history[sequence]
|
|
if(payload.resends > CHAT_RELIABILITY_MAX_RESENDS)
|
|
return // we tried but byond said no
|
|
|
|
payload.resends += 1
|
|
send_payload_to_client(client, client_history[sequence])
|
|
SSblackbox.record_feedback(
|
|
"nested tally",
|
|
"chat_resend_byond_version",
|
|
1,
|
|
list(
|
|
"[client.byond_version]",
|
|
"[client.byond_build]",
|
|
),
|
|
)
|