Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
TGchat (#76)
Browse files Browse the repository at this point in the history
## Почему это хорошо для игры
Порт порта - ParadiseSS13/Paradise#23643
Все ПРы там, использовано правда гораздо больше, но мне ТАААК впадлу всё
перечислять, потому что я тупо копировал код с пары и адаптировал его
под сыр, ищите в репе пары если хочется.

Нормальный чат, Fuckin' Finally

## Изображения изменений
<details>
<summary>Скриншоты</summary>


![image](https://github.com/ss220club/WyccerraBay220/assets/69762909/4489a085-0aaa-4d99-b8c8-d83be0f5dc00)

</details>

<!-- Если вы не меняли карту или спрайты, можете опустить эту секцию.
Если хотите, можете вставить видео. -->

## Тестирование
Буде буде

<!-- Как вы тестировали свой PR, если делали это вовсе? -->

## Changelog

:cl:
add: GoonChan был беспощадно ёбнут ради TGchat'а, слава  ТГчату!
/:cl:

<!-- Оба :cl:'а должны быть на месте, что-бы чейнджлог работал! Вы
можете написать свой ник справа от первого :cl:, если хотите. Иначе
будет использован ваш ник на ГитХабе. -->
<!-- Вы можете использовать несколько записей с одинаковым префиксом
(Они используются только для иконки в игре) и удалить ненужные. Помните,
что чейнджлог должен быть понятен обычным игроком. -->
<!-- Если чейнджлог не влияет на игроков(например, это рефактор), вы
можете исключить всю секцию. -->
  • Loading branch information
AyIong authored Feb 16, 2024
1 parent 796c2cb commit a80452d
Show file tree
Hide file tree
Showing 65 changed files with 1,459 additions and 4,571 deletions.
15 changes: 10 additions & 5 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "code\__defines\atmospherics.dm"
#include "code\__defines\byond_tracy.dm"
#include "code\__defines\callback.dm"
#include "code\__defines\chat.dm"
#include "code\__defines\chat_boxes.dm"
#include "code\__defines\chemistry.dm"
#include "code\__defines\client.dm"
#include "code\__defines\colors.dm"
Expand Down Expand Up @@ -114,6 +116,7 @@
#include "code\_helpers\assets.dm"
#include "code\_helpers\atmospherics.dm"
#include "code\_helpers\atom_movables.dm"
#include "code\_helpers\bicon_procs.dm"
#include "code\_helpers\bubble_effect.dm"
#include "code\_helpers\builtin_proc_callers.dm"
#include "code\_helpers\client.dm"
Expand Down Expand Up @@ -279,6 +282,7 @@
#include "code\datums\callbacks.dm"
#include "code\datums\category.dm"
#include "code\datums\chat_message.dm"
#include "code\datums\chat_payload.dm"
#include "code\datums\cinematic.dm"
#include "code\datums\datum.dm"
#include "code\datums\footsteps.dm"
Expand Down Expand Up @@ -1484,8 +1488,6 @@
#include "code\modules\asset_cache\assets\asset_changelog.dm"
#include "code\modules\asset_cache\assets\asset_credits.dm"
#include "code\modules\asset_cache\assets\asset_fontawesome.dm"
#include "code\modules\asset_cache\assets\asset_goonchat.dm"
#include "code\modules\asset_cache\assets\asset_jquery.dm"
#include "code\modules\asset_cache\assets\asset_lobby_screen.dm"
#include "code\modules\asset_cache\assets\asset_nanoui_common.dm"
#include "code\modules\asset_cache\assets\asset_nanoui_group.dm"
Expand Down Expand Up @@ -1561,7 +1563,6 @@
#include "code\modules\client\client_defines.dm"
#include "code\modules\client\client_helpers.dm"
#include "code\modules\client\client_procs.dm"
#include "code\modules\client\darkmode.dm"
#include "code\modules\client\movement.dm"
#include "code\modules\client\preferences.dm"
#include "code\modules\client\preferences_persist.dm"
Expand Down Expand Up @@ -1951,8 +1952,6 @@
#include "code\modules\goals\definitions\personal_achievement.dm"
#include "code\modules\goals\definitions\personal_achievement_movement.dm"
#include "code\modules\goals\definitions\personal_achievement_specific_object.dm"
#include "code\modules\goonchat\_helpers.dm"
#include "code\modules\goonchat\browserOutput.dm"
#include "code\modules\holodeck\HolodeckControl.dm"
#include "code\modules\holodeck\HolodeckObjects.dm"
#include "code\modules\holodeck\HolodeckPrograms.dm"
Expand Down Expand Up @@ -3238,6 +3237,12 @@
#include "code\modules\tgui\tgui_input\list_input.dm"
#include "code\modules\tgui\tgui_input\number_input.dm"
#include "code\modules\tgui\tgui_input\text_input.dm"
#include "code\modules\tgui\tgui_panel\audio.dm"
#include "code\modules\tgui\tgui_panel\telemetry.dm"
#include "code\modules\tgui\tgui_panel\tgui_panel.dm"
#include "code\modules\tgui\tgui_panel\tgui_panel_external.dm"
#include "code\modules\tgui\tgui_panel\tgui_panel_message.dm"
#include "code\modules\tgui\tgui_panel\to_chat.dm"
#include "code\modules\tooltip\tooltip.dm"
#include "code\modules\turbolift\_turbolift.dm"
#include "code\modules\turbolift\turbolift.dm"
Expand Down
25 changes: 25 additions & 0 deletions code/__defines/chat.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2020 Aleksej Komarov
* SPDX-License-Identifier: MIT
*/

/// How many chat payloads to keep in history
#define CHAT_RELIABILITY_HISTORY_SIZE 5
/// How many resends to allow before giving up
#define CHAT_RELIABILITY_MAX_RESENDS 3

#define MESSAGE_TYPE_SYSTEM "system"
#define MESSAGE_TYPE_LOCALCHAT "localchat"
#define MESSAGE_TYPE_RADIO "radio"
#define MESSAGE_TYPE_INFO "info"
#define MESSAGE_TYPE_WARNING "warning"
#define MESSAGE_TYPE_DEADCHAT "deadchat"
#define MESSAGE_TYPE_OOC "ooc"
#define MESSAGE_TYPE_ADMINPM "adminpm"
#define MESSAGE_TYPE_COMBAT "combat"
#define MESSAGE_TYPE_ADMINCHAT "adminchat"
#define MESSAGE_TYPE_MENTORCHAT "mentorchat"
#define MESSAGE_TYPE_EVENTCHAT "eventchat"
#define MESSAGE_TYPE_ADMINLOG "adminlog"
#define MESSAGE_TYPE_ATTACKLOG "attacklog"
#define MESSAGE_TYPE_DEBUG "debug"
8 changes: 8 additions & 0 deletions code/__defines/chat_boxes.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#define chat_box_regular(str) ("<div class='boxed_message'>" + str + "</div>")
#define chat_box_examine(str) ("<div class='boxed_message left_align_text'>" + str + "</div>")
#define chat_box_red(str) ("<div class='boxed_message red_border'>" + str + "</div>")
#define chat_box_green(str) ("<div class='boxed_message green_border'>" + str + "</div>")
#define chat_box_purple(str) ("<div class='boxed_message purple_border'>" + str + "</div>")
#define chat_box_notice(str) ("<div class='boxed_message notice_border'>" + str + "</div>")
#define chat_box_healthscan(str) ("<div class='boxed_message notice_border left_align_text'>" + str + "</div>")
#define chat_box_notice_thick(str) ("<div class='boxed_message notice_border thick_border'>" + str + "</div>")
4 changes: 0 additions & 4 deletions code/__defines/colors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,6 @@

#define COLOR_WEBHOOK_DEFAULT 0x8bbbd5

#define COLOR_DARKMODE_BACKGROUND "#202020"
#define COLOR_DARKMODE_DARKBACKGROUND "#171717"
#define COLOR_DARKMODE_TEXT "#a4bad6"

// Medical readout colors
#define COLOR_MEDICAL_BRUTE "#ff0000"
#define COLOR_MEDICAL_BURN "#ff7700"
Expand Down
3 changes: 3 additions & 0 deletions code/__defines/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,6 @@

/// Integer (~ticks * SSMobs/wait fire rate). The default maximum value a mob's confused var can be set to.
#define CONFUSED_MAX 15

/// Get the client from the var
#define CLIENT_FROM_VAR(I) (ismob(I) ? I:client : (istype(I, /client) ? I : (istype(I, /datum/mind) ? I:current?:client : null)))
3 changes: 2 additions & 1 deletion code/__defines/subsystem-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// [/SIERRA-ADD]
#define SS_PRIORITY_MOB 95 // Mob Life().
#define SS_PRIORITY_MACHINERY 95 // Machinery + powernet ticks.
#define SS_PRIORITY_TGUI 95 // SIERRA TGUI.
#define SS_PRIORITY_TGUI 95
#define SS_PRIORITY_AIR 80 // ZAS processing.
#define SS_PRIORITY_THROWING 75 // Throwing calculation and constant checks
#define SS_PRIORITY_CHEMISTRY 60 // Multi-tick chemical reactions.
Expand All @@ -39,6 +39,7 @@
#define SS_PRIORITY_SUPPLY 10 // Supply point accumulation.
#define SS_PRIORITY_TRADE 10 // Adds/removes traders.
#define SS_PRIORITY_GHOST_IMAGES 10 // Updates ghost client images.
#define SS_PRIORITY_PING 10
#define SS_PRIORITY_ZCOPY 10 // Builds appearances for Z-Mimic.

// SS_BACKGROUND
Expand Down
31 changes: 15 additions & 16 deletions code/__defines/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@
// Subsystems shutdown in the reverse of the order they initialize in
// The numbers just define the ordering, they are meaningless otherwise.

#define SS_INIT_EARLY 19
#define SS_INIT_GARBAGE 18
#define SS_INIT_CHEMISTRY 17
#define SS_INIT_MATERIALS 16
#define SS_INIT_PLANTS 15
#define SS_INIT_ANTAGS 14
#define SS_INIT_CULTURE 13
#define SS_INIT_MISC 12
#define SS_INIT_SKYBOX 11
#define SS_INIT_MAPPING 10
#define SS_INIT_JOBS 9
#define SS_INIT_ASSETS 8
#define SS_INIT_CHAR_SETUP 7
// [SIERRA-ADD] - SSINPUT - Input must be after char setup
#define SS_INIT_INPUT 6
// [/SIERRA-ADD]
#define SS_INIT_EARLY 20
#define SS_INIT_GARBAGE 19
#define SS_INIT_CHEMISTRY 18
#define SS_INIT_MATERIALS 17
#define SS_INIT_PLANTS 16
#define SS_INIT_ANTAGS 15
#define SS_INIT_CULTURE 14
#define SS_INIT_MISC 13
#define SS_INIT_SKYBOX 12
#define SS_INIT_MAPPING 11
#define SS_INIT_JOBS 10
#define SS_INIT_ASSETS 9
#define SS_INIT_CHAR_SETUP 8
#define SS_INIT_INPUT 7
#define SS_INIT_CIRCUIT 6
#define SS_INIT_GRAPH 5
#define SS_INIT_OPEN_SPACE 4
Expand All @@ -55,5 +53,6 @@
#define SS_INIT_TICKER -20
#define SS_INIT_AI -21
#define SS_INIT_AIFAST -22
#define SS_INIT_PING -85
#define SS_INIT_CHAT -90 // Should be lower to ensure chat remains smooth during init.
#define SS_INIT_UNIT_TESTS -100
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav"))
GLOBAL_DATUM_INIT(is_http_protocol, /regex, regex("^https?://"))


//Converts an icon to base64. Operates by putting the icon in the iconCache savefile,
// Converts an icon to base64. Operates by putting the icon in the iconCache savefile,
// exporting it as text, and then parsing the base64 from that.
// (This relies on byond automatically storing icons in savefiles as base64)
/proc/icon2base64(icon/icon, iconKey = "misc")
Expand Down Expand Up @@ -108,7 +109,7 @@ GLOBAL_DATUM_INIT(is_http_protocol, /regex, regex("^https?://"))

return "<img class='icon icon-[A.icon_state]' src='data:image/png;base64,[bicon_cache[key]]'>"

//Costlier version of icon2html() that uses getFlatIcon() to account for overlays, underlays, etc. Use with extreme moderation, ESPECIALLY on mobs.
// Costlier version of icon2html() that uses getFlatIcon() to account for overlays, underlays, etc. Use with extreme moderation, ESPECIALLY on mobs.
/proc/costly_icon2html(thing, target)
if (!thing)
return
Expand Down
11 changes: 7 additions & 4 deletions code/_helpers/logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ var/global/log_end= world.system_type == UNIX ? ascii2text(13) : ""
/proc/log_ss_init(text)
game_log("SS", "[text]")

//wrapper macros for easier grepping
#define DIRECT_OUTPUT(A, B) A << B
#define SEND_TEXT(target, text) DIRECT_OUTPUT(target, text)
#define WRITE_FILE(file, text) DIRECT_OUTPUT(file, text)

#define WARNING(MSG) warning("[MSG] in [__FILE__] at line [__LINE__] src: [src] usr: [usr].")

//print a warning message to world.log
/proc/warning(msg)
to_world_log("## WARNING: [msg][log_end]")
Expand All @@ -30,10 +36,7 @@ var/global/log_end= world.system_type == UNIX ? ascii2text(13) : ""
to_world_log("## TESTING: [msg][log_end]")

/proc/game_log(category, text)
// [SIERRA-EDIT] - RUST_G
// to_file(global.diary, "\[[time_stamp()]] [game_id] [category]: [text][log_end]") // SIERRA-EDIT - ORIGINAL
rustg_log_write_formatted("[GLOB.log_directory]/game.log", "[category]: [text]")
// [/SIERRA-EDIT]

/proc/log_admin(text)
GLOB.admin_log.Add(text)
Expand Down Expand Up @@ -61,7 +64,7 @@ var/global/log_end= world.system_type == UNIX ? ascii2text(13) : ""
/proc/to_debug_listeners(text, prefix = "DEBUG")
for(var/client/C as anything in GLOB.admins)
if(C.get_preference_value(/datum/client_preference/staff/show_debug_logs) == GLOB.PREF_SHOW)
to_chat(C, SPAN_DEBUG("<b>[prefix]</b>: [text]"))
to_chat(C, MESSAGE_TYPE_DEBUG, SPAN_DEBUG("<b>[prefix]</b>: [text]"), TRUE)

/proc/log_game(text)
if (config.log_game)
Expand Down
120 changes: 77 additions & 43 deletions code/controllers/subsystems/chat.dm
Original file line number Diff line number Diff line change
@@ -1,57 +1,91 @@
/**
* Copyright (c) 2020 Aleksej Komarov
* SPDX-License-Identifier: MIT
*/

SUBSYSTEM_DEF(chat)
name = "Chat"
flags = SS_TICKER|SS_NO_INIT
wait = 1
runlevels = RUNLEVELS_PREGAME | RUNLEVELS_GAME
priority = SS_PRIORITY_CHAT
init_order = SS_INIT_CHAT
var/static/list/payload = list()


/datum/controller/subsystem/chat/UpdateStat(time)
return
/// Associates 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 associative list of their last CHAT_RELIABILITY_HISTORY_SIZE messages.
var/list/list/datum/chat_payload/client_to_reliability_history = list()

/// Associates 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.ckey_directory[ckey]
if(isnull(target)) // verify client still exists
LAZYREMOVE(client_to_payloads, ckey)
continue

/datum/controller/subsystem/chat/fire(resumed)
for (var/client/C as anything in payload)
send_output(C, payload[C], "browseroutput:output")
payload -= C
if (MC_TICK_CHECK)
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
LAZYADDASSOC(client_to_payloads, client.ckey, generate_payload(client, message_data))

/datum/controller/subsystem/chat/proc/queue(target, message, handle_whitespace = TRUE, trailing_newline = TRUE)
if (!target || !message)
return
if (!istext(message))
CRASH("to_chat called with invalid input type")
if (target == world)
target = GLOB.clients
var/original_message = message //Some macros resist parsing elsewhere; strip them here
message = replacetext(message, "\improper", "")
message = replacetext(message, "\proper", "")
if (handle_whitespace)
message = replacetext(message, "\n", "<br>")
message = replacetext(message, "\t", "[FOURSPACES][FOURSPACES]")
if (trailing_newline)
message += "<br>"
var/twiceEncoded = url_encode(url_encode(message)) // Double encode so that JS can consume utf-8
if (islist(target))
for(var/I in target)
queuePartTwo(I, message, original_message, twiceEncoded)
else
queuePartTwo(target, message, original_message, twiceEncoded)


/datum/controller/subsystem/chat/proc/queuePartTwo(client/C, message, original, encoded)
C = resolve_client(C)
if (!C)
return
legacy_chat(C, original)
if (C?.get_preference_value(/datum/client_preference/goonchat) != GLOB.PREF_YES)
return
if (!C.chatOutput || C.chatOutput.broken)
return
if (!C.chatOutput.loaded)
C.chatOutput.messageQueue += message
/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
payload[C] += encoded

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])
Loading

0 comments on commit a80452d

Please sign in to comment.