]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Chat: parse svc_print in client code
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 5 Apr 2018 11:05:36 +0000 (21:05 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 5 Apr 2018 11:05:36 +0000 (21:05 +1000)
qcsrc/client/main.qc
qcsrc/menu/command/notice.qc
qcsrc/menu/command/notice.qh

index 25c1073c5c8f3ef484cd6be8d99e087cf2914086..4fa24bd3dcb8071f2a10d7bcac6655185c94bf23 100644 (file)
@@ -29,6 +29,7 @@
 #include <lib/csqcmodel/cl_model.qh>
 #include <lib/csqcmodel/interpolate.qh>
 #include <lib/warpzone/client.qh>
+#include <menu/command/notice.qh>
 
 // --------------------------------------------------------------------------
 // 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));
        }
index a558f725101c18478b3aebbcc3bded74b780f694..51ed0d3c628962d11dba6d4cbc4fb835b8fa2d22 100644 (file)
@@ -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;
         }
 
index 6f70f09beec2219624baeca92e2cd7deaa104fb4..dd585830ab07c144f63833df930b0c87f08038f0 100644 (file)
@@ -1 +1,7 @@
 #pragma once
+
+enum {
+    NOTICE_CHAT = BIT(0),
+    NOTICE_SILENT = BIT(1),
+    NOTICE_PRIVATE = BIT(2),
+};