Fixed various issues: added some free()s, lua_optboolean, other things, and also made sure chat can't send empty messages.

This commit is contained in:
Latapostrophe 2018-12-22 12:34:17 +01:00
parent b1ccfa1f46
commit 619dd9d08a
4 changed files with 46 additions and 5 deletions

View File

@ -3661,7 +3661,8 @@ void G_InitNew(UINT8 pultmode, const char *mapname, boolean resetplayer, boolean
unlocktriggers = 0; unlocktriggers = 0;
// clear itemfinder, just in case // 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 // internal game map

View File

@ -465,11 +465,15 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags)
{ {
// check if nodenum[1] is a space // check if nodenum[1] is a space
if (nodenum[1] == ' ') if (nodenum[1] == ' ')
{
spc = 0; spc = 0;
free(nodenum); // don't need this anymore.
// let it slide // let it slide
}
else else
{ {
HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<node> \'.", false); HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<node> \'.", false);
free(nodenum);
return; return;
} }
} }
@ -479,11 +483,13 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags)
if (msg[5] != ' ') if (msg[5] != ' ')
{ {
HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<node> \'.", false); HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<node> \'.", false);
free(nodenum);
return; return;
} }
} }
target = atoi((const char*) nodenum); // turn that into a number target = atoi((const char*) nodenum); // turn that into a number
free(nodenum);
//CONS_Printf("%d\n", target); //CONS_Printf("%d\n", target);
// check for target player, if it doesn't exist then we can't send the message! // 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;*/ static INT32 head = 0, tail = 0;*/
// WHY DO YOU OVERCOMPLICATE EVERYTHING????????? // 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) static void HU_queueChatChar(char c)
@ -919,6 +946,9 @@ static void HU_queueChatChar(char c)
size_t ci = 2; size_t ci = 2;
INT32 target = 0; 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 { do {
c = w_chat[-2+ci++]; c = w_chat[-2+ci++];
if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. 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 // check if nodenum[1] is a space
if (nodenum[1] == ' ') if (nodenum[1] == ' ')
{
spc = 0; spc = 0;
free(nodenum);
// let it slide // let it slide
}
else else
{ {
HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<node> \'.", false); HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<node> \'.", false);
free(nodenum);
return; return;
} }
} }
@ -973,11 +1007,13 @@ static void HU_queueChatChar(char c)
if (msg[5] != ' ') if (msg[5] != ' ')
{ {
HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<node> \'.", false); HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<node> \'.", false);
free(nodenum);
return; return;
} }
} }
target = atoi((const char*) nodenum); // turn that into a number target = atoi((const char*) nodenum); // turn that into a number
free(nodenum);
//CONS_Printf("%d\n", target); //CONS_Printf("%d\n", target);
// check for target player, if it doesn't exist then we can't send the message! // 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. 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_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-48, p_dispy- (6*count), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, "NO RESULT."); V_DrawSmallString(chatx+boxw+4, p_dispy- (6*count), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, "NO RESULT.");
} }
} }

View File

@ -95,7 +95,7 @@ static int lib_print(lua_State *L)
static int lib_chatprint(lua_State *L) static int lib_chatprint(lua_State *L)
{ {
const char *str = luaL_checkstring(L, 1); // retrieve string 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); int len = strlen(str);
if (str == NULL) // error if we don't have a string! 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 */ int n = lua_gettop(L); /* number of arguments */
const char *str = luaL_checkstring(L, 2); // retrieve string 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); int len = strlen(str);
player_t *plr; player_t *plr;

View File

@ -6344,6 +6344,10 @@ static void M_DrawConnectIPMenu(void)
static void M_ConnectIP(INT32 choice) static void M_ConnectIP(INT32 choice)
{ {
(void)choice; (void)choice;
if (*setupm_ip == 0)
return;
COM_BufAddText(va("connect \"%s\"\n", setupm_ip)); COM_BufAddText(va("connect \"%s\"\n", setupm_ip));
// A little "please wait" message. // A little "please wait" message.