From c7060aa5ad99eeaade268918fa22d6d659c92ea1 Mon Sep 17 00:00:00 2001
From: Latapostrophe <hyperclassic3@gmail.com>
Date: Sat, 22 Dec 2018 16:44:58 +0100
Subject: [PATCH] Remove mute boolean from playermsg hook, fix username stuff
 still being there, potential memory leaks, and added back the ip message.

---
 src/d_netcmd.c    |  3 ---
 src/hu_stuff.c    |  8 +-------
 src/lua_hook.h    |  2 +-
 src/lua_hooklib.c | 21 +++++++--------------
 src/m_menu.c      |  3 +++
 5 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/src/d_netcmd.c b/src/d_netcmd.c
index 3ed50e0b05..6d605ad4ca 100644
--- a/src/d_netcmd.c
+++ b/src/d_netcmd.c
@@ -582,7 +582,6 @@ void D_RegisterServerCommands(void)
   */
 void D_RegisterClientCommands(void)
 {
-	const char *username;
 	INT32 i;
 
 	for (i = 0; i < MAXSKINCOLORS; i++)
@@ -639,8 +638,6 @@ void D_RegisterClientCommands(void)
 #endif
 
 	// register these so it is saved to config
-	if ((username = I_GetUserName()))
-		cv_playername.defaultvalue = username;
 	CV_RegisterVar(&cv_playername);
 	CV_RegisterVar(&cv_playercolor);
 	CV_RegisterVar(&cv_skin); // r_things.c (skin NAME)
diff --git a/src/hu_stuff.c b/src/hu_stuff.c
index 8d51bf3fa8..fc5ae657cc 100644
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -465,11 +465,8 @@ 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<node> \'.", false);
@@ -664,7 +661,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum)
 	// run the lua hook even if we were supposed to eat the msg, netgame consistency goes first.
 
 #ifdef HAVE_BLUA
-	if (LUAh_PlayerMsg(playernum, target, flags, msg, spam_eatmsg))
+	if (LUAh_PlayerMsg(playernum, target, flags, msg))
 		return;
 #endif
 
@@ -989,11 +986,8 @@ 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<node> \'.", false);
diff --git a/src/lua_hook.h b/src/lua_hook.h
index 324babdb5f..252960edf5 100644
--- a/src/lua_hook.h
+++ b/src/lua_hook.h
@@ -75,7 +75,7 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source); // Ho
 boolean LUAh_BotTiccmd(player_t *bot, ticcmd_t *cmd); // Hook for B_BuildTiccmd
 boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd); // Hook for B_BuildTailsTiccmd by skin name
 boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook for linedef executors
-boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg, int mute); // Hook for chat messages
+boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg); // Hook for chat messages
 boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source); // Hook for hurt messages
 #define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for G_SpawnPlayer
 void LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting
diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c
index 697552ec39..948eca84c7 100644
--- a/src/lua_hooklib.c
+++ b/src/lua_hooklib.c
@@ -952,10 +952,8 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
 	return hooked;
 }
 
-// Hook for player chat
-// Added the "mute" field. It's set to true if the message was supposed to be eaten by spam protection.
-// But for netgame consistency purposes, this hook is ran first reguardless, so this boolean allows for modders to adapt if they so desire.
-boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg, int mute)
+
+boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg)
 {
 	hook_p hookp;
 	boolean hooked = false;
@@ -984,19 +982,14 @@ boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg, int mute)
 					LUA_PushUserdata(gL, &players[target-1], META_PLAYER); // target
 				}
 				lua_pushstring(gL, msg); // msg
-				if (mute)
-					lua_pushboolean(gL, true); // the message was supposed to be eaten by spamprotecc.
-				else
-					lua_pushboolean(gL, false);
 			}
 			lua_pushfstring(gL, FMT_HOOKID, hookp->id);
 			lua_gettable(gL, LUA_REGISTRYINDEX);
-			lua_pushvalue(gL, -6);
-			lua_pushvalue(gL, -6);
-			lua_pushvalue(gL, -6);
-			lua_pushvalue(gL, -6);
-			lua_pushvalue(gL, -6);
-			if (lua_pcall(gL, 5, 1, 0)) {
+			lua_pushvalue(gL, -5);
+			lua_pushvalue(gL, -5);
+			lua_pushvalue(gL, -5);
+			lua_pushvalue(gL, -5);
+			if (lua_pcall(gL, 4, 1, 0)) {
 				if (!hookp->error || cv_debug & DBG_LUA)
 					CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
 				lua_pop(gL, 1);
diff --git a/src/m_menu.c b/src/m_menu.c
index 8f71c97a2b..ba9e08f39a 100644
--- a/src/m_menu.c
+++ b/src/m_menu.c
@@ -6346,7 +6346,10 @@ static void M_ConnectIP(INT32 choice)
 	(void)choice;
 
 	if (*setupm_ip == 0)
+	{
+		M_StartMessage("You must specify an IP address.\n", NULL, MM_NOTHING);
 		return;
+	}
 
 	COM_BufAddText(va("connect \"%s\"\n", setupm_ip));
 
-- 
GitLab