From: TimePath Date: Thu, 5 Apr 2018 11:05:36 +0000 (+1000) Subject: Chat: parse svc_print in client code X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=aa278f41cc05777d3663575c34d815eb9e94377e;p=xonotic%2Fxonotic-data.pk3dir.git Chat: parse svc_print in client code --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 25c1073c5..4fa24bd3d 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -29,6 +29,7 @@ #include #include #include +#include // -------------------------------------------------------------------------- // BEGIN REQUIRED CSQC FUNCTIONS @@ -915,7 +916,23 @@ void CSQC_Parse_Print(string strMessage) { if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_Print(\"%s\")", strMessage); if (autocvar__cl_hook_print != "") { - localcmd("\n", autocvar__cl_hook_print, " ", console_encode(strMessage), "\n"); + int flags = 0; + string s = substring(strMessage, 0, -2); // remove trailing \n + int c = str2chr(s, 0); + if (c == 1 || c == 2 || c == 3) { + s = substring(s, 1, -1); + if (c != 1) { + flags |= NOTICE_SILENT; + } else if (str2chr(s, 0) == '\r') { + s = substring(s, 1, -1); + flags |= NOTICE_PRIVATE; + } + if (c != 2) { + flags |= NOTICE_CHAT; + } + s = strcat("^3", s); + } + localcmd("\n", autocvar__cl_hook_print, " ", itos(flags), " ", console_encode(s), "\n"); } else { print(ColorTranslateRGB(strMessage)); } diff --git a/qcsrc/menu/command/notice.qc b/qcsrc/menu/command/notice.qc index a558f7251..51ed0d3c6 100644 --- a/qcsrc/menu/command/notice.qc +++ b/qcsrc/menu/command/notice.qc @@ -10,31 +10,15 @@ GENERIC_COMMAND(notice, "Append a notice to chat") { 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"); + int flags = stoi(argv(1)); + string s = console_decode(substring(command, argv_start_index(2), argv_end_index(-1))); + s = ColorTranslateRGB(s); + string prefix = (flags & NOTICE_CHAT) ? "\{3}" : ""; + if (!(flags & NOTICE_SILENT)) { + entity snd = (flags & NOTICE_PRIVATE) ? SND_TALK2 : SND_TALK; + localsound(Sound_fixpath(snd)); } + print(prefix, "^7", s, "\n"); return; } diff --git a/qcsrc/menu/command/notice.qh b/qcsrc/menu/command/notice.qh index 6f70f09be..dd585830a 100644 --- a/qcsrc/menu/command/notice.qh +++ b/qcsrc/menu/command/notice.qh @@ -1 +1,7 @@ #pragma once + +enum { + NOTICE_CHAT = BIT(0), + NOTICE_SILENT = BIT(1), + NOTICE_PRIVATE = BIT(2), +};