From d7114651636e94d1e7dbb53215772db64d247e59 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 4 Apr 2018 22:01:54 +1000 Subject: [PATCH] Begin menu controlled chat --- qcsrc/client/main.qc | 9 +++++- qcsrc/common/notifications/all.qc | 7 ++++- qcsrc/common/sounds/all.inc | 1 + qcsrc/lib/cvar.qh | 21 +++++++++++++ qcsrc/menu/command/_mod.inc | 1 + qcsrc/menu/command/_mod.qh | 1 + qcsrc/menu/command/notice.qc | 49 +++++++++++++++++++++++++++++++ qcsrc/menu/command/notice.qh | 1 + 8 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 qcsrc/menu/command/notice.qc create mode 100644 qcsrc/menu/command/notice.qh diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 9c146c09b..25c1073c5 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -907,11 +907,18 @@ void CSQC_Parse_StuffCmd(string strMessage) if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_StuffCmd(\"%s\")", strMessage); localcmd(strMessage); } + +string autocvar__cl_hook_print; + // CSQC_Parse_Print : Provides the print string in the first parameter that the server provided. To execute standard behavior, simply execute print with the string. void CSQC_Parse_Print(string strMessage) { if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_Print(\"%s\")", strMessage); - print(ColorTranslateRGB(strMessage)); + if (autocvar__cl_hook_print != "") { + localcmd("\n", autocvar__cl_hook_print, " ", console_encode(strMessage), "\n"); + } else { + print(ColorTranslateRGB(strMessage)); + } } // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided. diff --git a/qcsrc/common/notifications/all.qc b/qcsrc/common/notifications/all.qc index b9350758a..19ee014fb 100644 --- a/qcsrc/common/notifications/all.qc +++ b/qcsrc/common/notifications/all.qc @@ -1259,7 +1259,12 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) case MSG_INFO: { - print( + #ifdef CSQC + void(string) echo = CSQC_Parse_Print; + #else + void(string, ...) echo = print; + #endif + echo( Local_Notification_sprintf( notif.nent_string, notif.nent_args, diff --git a/qcsrc/common/sounds/all.inc b/qcsrc/common/sounds/all.inc index 31b5ed487..ceeef1b05 100644 --- a/qcsrc/common/sounds/all.inc +++ b/qcsrc/common/sounds/all.inc @@ -273,6 +273,7 @@ SOUND(KILL, "misc/kill"); SOUND(SPAWN, "misc/spawn"); SOUND(TALK, "misc/talk"); +SOUND(TALK2, "misc/talk2"); SOUND(TELEPORT, "misc/teleport"); diff --git a/qcsrc/lib/cvar.qh b/qcsrc/lib/cvar.qh index a17f2bad7..3822805b9 100644 --- a/qcsrc/lib/cvar.qh +++ b/qcsrc/lib/cvar.qh @@ -30,6 +30,27 @@ string MakeConsoleSafe(string input) return input; } +ERASEABLE +string console_encode(string input) +{ + input = strreplace("$", "$$", input); + input = strreplace("\r", "\\r", input); + input = strreplace("\n", "\\n", input); + input = strreplace("\"", "\\\"", input); + input = sprintf("\"%s\"", input); + return input; +} + +ERASEABLE +string console_decode(string input) +{ + input = substring(input, 1, -2); + input = strreplace("\\r", "\r", input); + input = strreplace("\\n", "\n", input); + input = strreplace("\\\"", "\"", input); + return input; +} + ERASEABLE void cvar_describe(string name, string desc) { diff --git a/qcsrc/menu/command/_mod.inc b/qcsrc/menu/command/_mod.inc index 0bcef50de..9b9dc0bf1 100644 --- a/qcsrc/menu/command/_mod.inc +++ b/qcsrc/menu/command/_mod.inc @@ -1,2 +1,3 @@ // generated file; do not modify #include +#include diff --git a/qcsrc/menu/command/_mod.qh b/qcsrc/menu/command/_mod.qh index 91c0a8f35..3633b94d9 100644 --- a/qcsrc/menu/command/_mod.qh +++ b/qcsrc/menu/command/_mod.qh @@ -1,2 +1,3 @@ // generated file; do not modify #include +#include diff --git a/qcsrc/menu/command/notice.qc b/qcsrc/menu/command/notice.qc new file mode 100644 index 000000000..a558f7251 --- /dev/null +++ b/qcsrc/menu/command/notice.qc @@ -0,0 +1,49 @@ +#include "notice.qh" + +#include + +noref string autocvar__cl_hook_print = "menu_cmd notice"; + +GENERIC_COMMAND(notice, "Append a notice to chat") +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + string s = console_decode(substring(command, argv_start_index(1), argv_end_index(-1))); + for (int i = 0, n = tokenizebyseparator(s, "\n"); i < n; ++i) + { + string s = ColorTranslateRGB(argv(i)); + int c = str2chr(s, 0); + if (c == 1 || c == 3) { + // visible in chat + s = substring(s, 1, -1); + if (c == 1) { + entity snd; + if (str2chr(s, 0) == '\r') { + s = substring(s, 1, -1); + snd = SND_TALK2; + } else { + snd = SND_TALK; + } + localsound(Sound_fixpath(snd)); + } + s = strcat("^3", s); + } else { + // not visible in chat + s = strcat("^7", s); + } + print(s, "\n"); + } + return; + } + + default: + case CMD_REQUEST_USAGE: + { + LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " notice message"); + LOG_INFO(" Where 'message' is the message to append."); + return; + } + } +} diff --git a/qcsrc/menu/command/notice.qh b/qcsrc/menu/command/notice.qh new file mode 100644 index 000000000..6f70f09be --- /dev/null +++ b/qcsrc/menu/command/notice.qh @@ -0,0 +1 @@ +#pragma once -- 2.39.2