]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Begin menu controlled chat
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 4 Apr 2018 12:01:54 +0000 (22:01 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 4 Apr 2018 12:02:57 +0000 (22:02 +1000)
qcsrc/client/main.qc
qcsrc/common/notifications/all.qc
qcsrc/common/sounds/all.inc
qcsrc/lib/cvar.qh
qcsrc/menu/command/_mod.inc
qcsrc/menu/command/_mod.qh
qcsrc/menu/command/notice.qc [new file with mode: 0644]
qcsrc/menu/command/notice.qh [new file with mode: 0644]

index 9c146c09bd9115091c24585fc02c323558b75d19..25c1073c5c8f3ef484cd6be8d99e087cf2914086 100644 (file)
@@ -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.
index b9350758a115fb6ab3558c86e867a5e62d549c73..19ee014fb058c1239950e86c0610f1fb5fddd14c 100644 (file)
@@ -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,
index 31b5ed4873642ceb21b2fb3fae77b66c5770fd23..ceeef1b05c70c6c8f66ad48b0a5c0c66522de4c8 100644 (file)
@@ -273,6 +273,7 @@ SOUND(KILL, "misc/kill");
 SOUND(SPAWN, "misc/spawn");
 
 SOUND(TALK, "misc/talk");
+SOUND(TALK2, "misc/talk2");
 
 SOUND(TELEPORT, "misc/teleport");
 
index a17f2bad72397d55a470fc32bb64851cfcbe5152..3822805b930b4576905de2370712587fae2fa425 100644 (file)
@@ -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)
 {
index 0bcef50de71c6d6f4b59d1a8574916f6c2866652..9b9dc0bf168597185e8067bbeebf931322fe3043 100644 (file)
@@ -1,2 +1,3 @@
 // generated file; do not modify
 #include <menu/command/menu_cmd.qc>
+#include <menu/command/notice.qc>
index 91c0a8f35e80a23ccdc487acb7a1ba1853d107e6..3633b94d9646542b258fc1a0c8e01f0b6b05d6a0 100644 (file)
@@ -1,2 +1,3 @@
 // generated file; do not modify
 #include <menu/command/menu_cmd.qh>
+#include <menu/command/notice.qh>
diff --git a/qcsrc/menu/command/notice.qc b/qcsrc/menu/command/notice.qc
new file mode 100644 (file)
index 0000000..a558f72
--- /dev/null
@@ -0,0 +1,49 @@
+#include "notice.qh"
+
+#include <common/sounds/all.qh>
+
+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 (file)
index 0000000..6f70f09
--- /dev/null
@@ -0,0 +1 @@
+#pragma once