From 3638d5d55692090da133b66ad93d9ddbf5570555 Mon Sep 17 00:00:00 2001
From: LJ Sonic <lamr@free.fr>
Date: Sun, 2 Jan 2022 17:08:10 +0100
Subject: [PATCH] Cleanup chat code a little

---
 src/hu_stuff.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/src/hu_stuff.c b/src/hu_stuff.c
index fdbef29808..29686cd26a 100644
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -957,11 +957,8 @@ static boolean HU_chatboxContainsOnlySpaces(void)
 	return true;
 }
 
-//
-//
 static void HU_queueChatChar(char c)
 {
-	// send automaticly the message (no more chat char)
 	if (c == KEY_ENTER)
 	{
 		char buf[2+256];
@@ -1010,7 +1007,7 @@ static void HU_queueChatChar(char c)
 
 			strncpy(playernum, msg+3, 3);
 			// check for undesirable characters in our "number"
-			if (((playernum[0] < '0') || (playernum[0] > '9')) || ((playernum[1] < '0') || (playernum[1] > '9')))
+			if (!(isdigit(playernum[0]) && isdigit(playernum[1])))
 			{
 				// check if playernum[1] is a space
 				if (playernum[1] == ' ')
@@ -1023,17 +1020,13 @@ static void HU_queueChatChar(char c)
 				}
 			}
 			// I'm very bad at C, I swear I am, additional checks eww!
-			if (spc != 0)
+			if (spc != 0 && msg[5] != ' ')
 			{
-				if (msg[5] != ' ')
-				{
-					HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<player num> \'.", false);
-					return;
-				}
+				HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<player num> \'.", false);
+				return;
 			}
 
 			target = atoi(playernum); // turn that into a number
-			//CONS_Printf("%d\n", target);
 
 			// check for target player, if it doesn't exist then we can't send the message!
 			if (target < MAXPLAYERS && playeringame[target]) // player exists
@@ -1050,11 +1043,7 @@ static void HU_queueChatChar(char c)
 		}
 		if (ci > 3) // don't send target+flags+empty message.
 		{
-			if (teamtalk)
-				buf[0] = -1; // target
-			else
-				buf[0] = target;
-
+			buf[0] = teamtalk ? -1 : target; // target
 			buf[1] = 0; // flags
 			SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1);
 		}
-- 
GitLab