From 619dd9d08aa285dd59ae87bb04208070e6e2cde3 Mon Sep 17 00:00:00 2001 From: Latapostrophe Date: Sat, 22 Dec 2018 12:34:17 +0100 Subject: [PATCH] Fixed various issues: added some free()s, lua_optboolean, other things, and also made sure chat can't send empty messages. --- src/g_game.c | 3 ++- src/hu_stuff.c | 40 ++++++++++++++++++++++++++++++++++++++-- src/lua_baselib.c | 4 ++-- src/m_menu.c | 4 ++++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 1c37b3b7..2f2ac043 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3661,7 +3661,8 @@ void G_InitNew(UINT8 pultmode, const char *mapname, boolean resetplayer, boolean unlocktriggers = 0; // clear itemfinder, just in case - CV_StealthSetValue(&cv_itemfinder, 0); + if (!dedicated) // except in dedicated servers, where it is not registered and can actually I_Error debug builds + CV_StealthSetValue(&cv_itemfinder, 0); } // internal game map diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 771628ef..8d51bf3f 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -465,11 +465,15 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) { // check if nodenum[1] is a space if (nodenum[1] == ' ') + { spc = 0; + free(nodenum); // don't need this anymore. // let it slide + } else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + free(nodenum); return; } } @@ -479,11 +483,13 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) if (msg[5] != ' ') { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + free(nodenum); return; } } target = atoi((const char*) nodenum); // turn that into a number + free(nodenum); //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -906,6 +912,27 @@ static boolean teamtalk = false; static INT32 head = 0, tail = 0;*/ // WHY DO YOU OVERCOMPLICATE EVERYTHING????????? +// Clear spaces so we don't end up with messages only made out of emptiness +static boolean HU_clearChatSpaces() +{ + size_t i = 0; // Used to just check our message + char c; // current character we're iterating. + boolean nothingbutspaces = true; + + for (; i < strlen(w_chat); i++) // iterate through message and eradicate all spaces that don't belong. + { + c = w_chat[i]; + if (!c) + break; // if there's nothing, it's safe to assume our message has ended, so let's not waste any more time here. + + if (c != ' ') // Isn't a space + { + nothingbutspaces = false; + } + } + return nothingbutspaces; +} + // // static void HU_queueChatChar(char c) @@ -919,6 +946,9 @@ static void HU_queueChatChar(char c) size_t ci = 2; INT32 target = 0; + if (HU_clearChatSpaces()) // Avoids being able to send empty messages, or something. + return; // If this returns true, that means our message was NOTHING but spaces, so don't send it period. + do { c = w_chat[-2+ci++]; if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. @@ -959,11 +989,15 @@ static void HU_queueChatChar(char c) { // check if nodenum[1] is a space if (nodenum[1] == ' ') + { spc = 0; + free(nodenum); // let it slide + } else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + free(nodenum); return; } } @@ -973,11 +1007,13 @@ static void HU_queueChatChar(char c) if (msg[5] != ' ') { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + free(nodenum); return; } } target = atoi((const char*) nodenum); // turn that into a number + free(nodenum); //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -1735,8 +1771,8 @@ static void HU_DrawChat(void) } if (count == 0) // no results. { - V_DrawFillConsoleMap(chatx-50, p_dispy- (6*count), 48, 6, 239 | V_SNAPTOBOTTOM | V_SNAPTOLEFT); // fill it like the chat so the text doesn't become hard to read because of the hud. - V_DrawSmallString(chatx-48, p_dispy- (6*count), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, "NO RESULT."); + V_DrawFillConsoleMap(chatx+boxw+2, p_dispy- (6*count), 48, 6, 239 | V_SNAPTOBOTTOM | V_SNAPTOLEFT); // fill it like the chat so the text doesn't become hard to read because of the hud. + V_DrawSmallString(chatx+boxw+4, p_dispy- (6*count), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, "NO RESULT."); } } diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 6b1456e9..6ae4ad8c 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -95,7 +95,7 @@ static int lib_print(lua_State *L) static int lib_chatprint(lua_State *L) { const char *str = luaL_checkstring(L, 1); // retrieve string - boolean sound = luaL_checkboolean(L, 2); // retrieve sound boolean + boolean sound = lua_optboolean(L, 2); // retrieve sound boolean int len = strlen(str); if (str == NULL) // error if we don't have a string! @@ -113,7 +113,7 @@ static int lib_chatprintf(lua_State *L) { int n = lua_gettop(L); /* number of arguments */ const char *str = luaL_checkstring(L, 2); // retrieve string - boolean sound = luaL_checkboolean(L, 3); // sound? + boolean sound = lua_optboolean(L, 3); // sound? int len = strlen(str); player_t *plr; diff --git a/src/m_menu.c b/src/m_menu.c index 380ba266..8f71c97a 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6344,6 +6344,10 @@ static void M_DrawConnectIPMenu(void) static void M_ConnectIP(INT32 choice) { (void)choice; + + if (*setupm_ip == 0) + return; + COM_BufAddText(va("connect \"%s\"\n", setupm_ip)); // A little "please wait" message.