shithub: choc

Download patch

ref: 4a356b565d08ee48dbe8d920876fd73a72dbc016
parent: 69be33fe88d0a55dce27214e7543cded8ff51175
author: Simon Howard <[email protected]>
date: Sat Oct 22 13:09:12 EDT 2011

Fix Heretic and Hexen multiplayer chat.

Subversion-branch: /branches/v2-branch
Subversion-revision: 2455

--- a/src/heretic/ct_chat.c
+++ b/src/heretic/ct_chat.c
@@ -27,9 +27,12 @@
 
 #include <string.h>
 #include <ctype.h>
+
 #include "doomdef.h"
 #include "doomkeys.h"
+
 #include "deh_str.h"
+#include "m_controls.h"
 #include "p_local.h"
 #include "s_sound.h"
 #include "v_video.h"
@@ -44,13 +47,11 @@
 #define CT_PLR_BLUE		4
 #define CT_PLR_ALL		5
 
-#define CT_KEY_GREEN		'g'
-#define CT_KEY_YELLOW	'y'
-#define CT_KEY_RED		'r'
-#define CT_KEY_BLUE		'b'
-#define CT_KEY_ALL		't'
-#define CT_ESCAPE			6
+// Vanilla Heretic seems to use this for KEY_BACKSPACE (tcpdump'ed trace):
+#define CT_BACKSPACE 0x7f
 
+#define CT_ESCAPE 6
+
 // Public data
 
 void CT_Init(void);
@@ -132,6 +133,19 @@
     return;
 }
 
+// These keys are allowed by Vanilla Heretic:
+
+static boolean ValidChatChar(char c)
+{
+    return (c >= 'a' && c <= 'z')
+        || (c >= 'A' && c <= 'Z')
+        || (c >= '0' && c <= '9')
+        || c == '!' || c == '?'
+        || c == ' ' || c == '\''
+        || c == ',' || c == '.'
+        || c == '-' || c == '=';
+}
+
 //===========================================================================
 //
 // CT_Responder
@@ -165,23 +179,23 @@
     if (!chatmodeon)
     {
         sendto = 0;
-        if (ev->data1 == CT_KEY_ALL)
+        if (ev->data1 == key_multi_msg)
         {
             sendto = CT_PLR_ALL;
         }
-        else if (ev->data1 == CT_KEY_GREEN)
+        else if (ev->data1 == key_multi_msgplayer[0])
         {
             sendto = CT_PLR_GREEN;
         }
-        else if (ev->data1 == CT_KEY_YELLOW)
+        else if (ev->data1 == key_multi_msgplayer[1])
         {
             sendto = CT_PLR_YELLOW;
         }
-        else if (ev->data1 == CT_KEY_RED)
+        else if (ev->data1 == key_multi_msgplayer[2])
         {
             sendto = CT_PLR_RED;
         }
-        else if (ev->data1 == CT_KEY_BLUE)
+        else if (ev->data1 == key_multi_msgplayer[3])
         {
             sendto = CT_PLR_BLUE;
         }
@@ -228,35 +242,16 @@
             CT_Stop();
             return true;
         }
-        else if (ev->data1 >= 'a' && ev->data1 <= 'z')
+        else if (ev->data1 == KEY_BACKSPACE)
         {
-            CT_queueChatChar(ev->data1 - 32);
+            CT_queueChatChar(CT_BACKSPACE);
             return true;
         }
-        else if (shiftdown)
+        else if (ValidChatChar(ev->data2))
         {
-            if (ev->data1 == '1')
-            {
-                CT_queueChatChar('!');
-                return true;
-            }
-            else if (ev->data1 == '/')
-            {
-                CT_queueChatChar('?');
-                return true;
-            }
+            CT_queueChatChar(toupper(ev->data2));
+            return true;
         }
-        else
-        {
-            if (ev->data1 == ' ' || ev->data1 == ',' || ev->data1 == '.'
-                || (ev->data1 >= '0' && ev->data1 <= '9') || ev->data1 == '\''
-                || ev->data1 == KEY_BACKSPACE || ev->data1 == '-'
-                || ev->data1 == '=')
-            {
-                CT_queueChatChar(ev->data1);
-                return true;
-            }
-        }
     }
     return false;
 }
@@ -336,7 +331,7 @@
                 }
                 CT_ClearChatMessage(i);
             }
-            else if (c == KEY_BACKSPACE)
+            else if (c == CT_BACKSPACE)
             {
                 CT_BackSpace(i);
             }
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -53,6 +53,11 @@
 #include "w_main.h"
 #include "v_video.h"
 
+#define CT_KEY_GREEN    'g'
+#define CT_KEY_YELLOW   'y'
+#define CT_KEY_RED      'r'
+#define CT_KEY_BLUE     'b'
+
 #define STARTUP_WINDOW_X 17
 #define STARTUP_WINDOW_Y 7
 
@@ -736,6 +741,11 @@
     M_BindHereticControls();
     M_BindWeaponControls();
     M_BindChatControls(MAXPLAYERS);
+
+    key_multi_msgplayer[0] = CT_KEY_GREEN;
+    key_multi_msgplayer[1] = CT_KEY_YELLOW;
+    key_multi_msgplayer[2] = CT_KEY_RED;
+    key_multi_msgplayer[3] = CT_KEY_BLUE;
 
     M_BindMenuControls();
     M_BindMapControls();
--- a/src/hexen/ct_chat.c
+++ b/src/hexen/ct_chat.c
@@ -28,6 +28,7 @@
 #include "h2def.h"
 #include "s_sound.h"
 #include "doomkeys.h"
+#include "m_controls.h"
 #include "p_local.h"
 #include "v_video.h"
 
@@ -51,17 +52,14 @@
     CT_PLR_ALL
 };
 
-#define CT_KEY_BLUE		'b'
-#define CT_KEY_RED		'r'
-#define CT_KEY_YELLOW	'y'
-#define CT_KEY_GREEN	'g'
-#define CT_KEY_PLAYER5	'j'     // Jade
-#define CT_KEY_PLAYER6	'w'     // White
-#define CT_KEY_PLAYER7	'h'     // Hazel
-#define CT_KEY_PLAYER8	'p'     // Purple
-#define CT_KEY_ALL		't'
-#define CT_ESCAPE		6
+// KEY_BACKSPACE (ASCII code 0x08) can't be used, because it conflicts with
+// CT_PLR_PLAYER8. Investigation reveals that Vanilla Hexen appears to use
+// this value for backspace.
 
+#define CT_BACKSPACE 0x7f
+
+#define CT_ESCAPE 6
+
 // Public data
 
 void CT_Init(void);
@@ -159,6 +157,19 @@
     return;
 }
 
+// These keys are allowed by Vanilla Heretic:
+
+static boolean ValidChatChar(char c)
+{
+    return (c >= 'a' && c <= 'z')
+        || (c >= 'A' && c <= 'Z')
+        || (c >= '0' && c <= '9')
+        || c == '!' || c == '?'
+        || c == ' ' || c == '\''
+        || c == ',' || c == '.'
+        || c == '-' || c == '=';
+}
+
 //===========================================================================
 //
 // CT_Responder
@@ -192,39 +203,39 @@
     if (!chatmodeon)
     {
         sendto = 0;
-        if (ev->data1 == CT_KEY_ALL)
+        if (ev->data1 == key_multi_msg)
         {
             sendto = CT_PLR_ALL;
         }
-        else if (ev->data1 == CT_KEY_GREEN)
+        else if (ev->data1 == key_multi_msgplayer[0])
         {
-            sendto = CT_PLR_GREEN;
+            sendto = CT_PLR_BLUE;
         }
-        else if (ev->data1 == CT_KEY_YELLOW)
+        else if (ev->data1 == key_multi_msgplayer[1])
         {
-            sendto = CT_PLR_YELLOW;
+            sendto = CT_PLR_RED;
         }
-        else if (ev->data1 == CT_KEY_RED)
+        else if (ev->data1 == key_multi_msgplayer[2])
         {
-            sendto = CT_PLR_RED;
+            sendto = CT_PLR_YELLOW;
         }
-        else if (ev->data1 == CT_KEY_BLUE)
+        else if (ev->data1 == key_multi_msgplayer[3])
         {
-            sendto = CT_PLR_BLUE;
+            sendto = CT_PLR_GREEN;
         }
-        else if (ev->data1 == CT_KEY_PLAYER5)
+        else if (ev->data1 == key_multi_msgplayer[4])
         {
             sendto = CT_PLR_PLAYER5;
         }
-        else if (ev->data1 == CT_KEY_PLAYER6)
+        else if (ev->data1 == key_multi_msgplayer[5])
         {
             sendto = CT_PLR_PLAYER6;
         }
-        else if (ev->data1 == CT_KEY_PLAYER7)
+        else if (ev->data1 == key_multi_msgplayer[6])
         {
             sendto = CT_PLR_PLAYER7;
         }
-        else if (ev->data1 == CT_KEY_PLAYER8)
+        else if (ev->data1 == key_multi_msgplayer[7])
         {
             sendto = CT_PLR_PLAYER8;
         }
@@ -272,30 +283,14 @@
             CT_Stop();
             return true;
         }
-        else if (ev->data1 >= 'a' && ev->data1 <= 'z')
+        else if (ev->data1 == KEY_BACKSPACE)
         {
-            CT_queueChatChar(ev->data1 - 32);
+            CT_queueChatChar(CT_BACKSPACE);
             return true;
         }
-        else if (shiftdown)
+        else if (ValidChatChar(ev->data2))
         {
-            if (ev->data1 == '1')
-            {
-                CT_queueChatChar('!');
-                return true;
-            }
-            else if (ev->data1 == '/')
-            {
-                CT_queueChatChar('?');
-                return true;
-            }
-        }
-        if (ev->data1 == ' ' || ev->data1 == ',' || ev->data1 == '.'
-            || (ev->data1 >= '0' && ev->data1 <= '9') || ev->data1 == '\''
-            || ev->data1 == KEY_BACKSPACE || ev->data1 == '-'
-            || ev->data1 == '=')
-        {
-            CT_queueChatChar(ev->data1);
+            CT_queueChatChar(toupper(ev->data2));
             return true;
         }
     }
@@ -369,7 +364,7 @@
                 }
                 CT_ClearChatMessage(i);
             }
-            else if (c == KEY_BACKSPACE)
+            else if (c == CT_BACKSPACE)
             {
                 CT_BackSpace(i);
             }
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -53,6 +53,15 @@
 // MACROS ------------------------------------------------------------------
 
 #define MAXWADFILES 20
+#define CT_KEY_BLUE         'b'
+#define CT_KEY_RED          'r'
+#define CT_KEY_YELLOW       'y'
+#define CT_KEY_GREEN        'g'
+#define CT_KEY_PLAYER5      'j'     // Jade
+#define CT_KEY_PLAYER6      'w'     // White
+#define CT_KEY_PLAYER7      'h'     // Hazel
+#define CT_KEY_PLAYER8      'p'     // Purple
+#define CT_KEY_ALL          't'
 
 // TYPES -------------------------------------------------------------------
 
@@ -162,6 +171,15 @@
     M_BindChatControls(MAXPLAYERS);
     M_BindHereticControls();
     M_BindHexenControls();
+
+    key_multi_msgplayer[0] = CT_KEY_BLUE;
+    key_multi_msgplayer[1] = CT_KEY_RED;
+    key_multi_msgplayer[2] = CT_KEY_YELLOW;
+    key_multi_msgplayer[3] = CT_KEY_GREEN;
+    key_multi_msgplayer[4] = CT_KEY_PLAYER5;
+    key_multi_msgplayer[5] = CT_KEY_PLAYER6;
+    key_multi_msgplayer[6] = CT_KEY_PLAYER7;
+    key_multi_msgplayer[7] = CT_KEY_PLAYER8;
 
     M_BindVariable("graphical_startup",      &graphical_startup);
     M_BindVariable("mouse_sensitivity",      &mouseSensitivity);