From 2ccb2229140e2e15adb3be41f504ce35a53217d0 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 17:08:10 +0100 Subject: [PATCH] Cleanup chat code a little # Conflicts: # src/hu_stuff.c --- src/hu_stuff.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 430c56a1a..8b024fe1c 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1039,11 +1039,8 @@ static boolean HU_chatboxContainsOnlySpaces(void) return true; } -// -// -static void HU_queueChatChar(INT32 c) +static void HU_queueChatChar(char c) { - // send automaticly the message (no more chat char) if (c == KEY_ENTER) { char buf[2+256]; @@ -1093,7 +1090,7 @@ static void HU_queueChatChar(INT32 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] == ' ') @@ -1106,17 +1103,13 @@ static void HU_queueChatChar(INT32 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 \'.", false); - return; - } + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", 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 @@ -1133,11 +1126,7 @@ static void HU_queueChatChar(INT32 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); }