From cb62f08364d4d53e51d4770198e2b65b3547e62b Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 22:23:50 -0400 Subject: [PATCH 01/11] "PlayerQuit" hook --- src/lua_hook.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lua_hook.h b/src/lua_hook.h index 804d99e12..240fdaece 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -43,6 +43,7 @@ enum hook { hook_PlayerMsg, hook_HurtMsg, hook_PlayerSpawn, + hook_PlayerQuit, hook_MAX // last hook }; @@ -77,5 +78,6 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook 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 +boolean LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting #endif From cfb2feff8ef4344130bed3456937ecb9609c593a Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 22:25:11 -0400 Subject: [PATCH 02/11] "PlayerQuit" hook --- src/lua_hooklib.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 1b9652571..be3f8b0e1 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -54,6 +54,7 @@ const char *const hookNames[hook_MAX+1] = { "PlayerMsg", "HurtMsg", "PlayerSpawn", + "PlayerQuit", NULL }; @@ -798,4 +799,41 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) // stack: tables } +boolean LUAh_PlayerQuit(player_t *plr, int reason) +{ + hook_p hookp; + boolean hooked = false; + if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8)))) + return false; + + lua_settop(gL, 0); + + for (hookp = roothook; hookp; hookp = hookp->next) + if (hookp->type == hook_PlayerQuit) + { + if (lua_gettop(gL) == 0) + { + LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit + lua_pushinteger(gL, reason); // Reason for quitting + } + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_pushvalue(gL, -3); + lua_pushvalue(gL, -3); + if (lua_pcall(gL, 2, 1, 0)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + continue; + } + if (lua_toboolean(gL, -1)) + hooked = true; + lua_pop(gL, 1); + } + + lua_settop(gL, 0); + return hooked; +} + #endif From 89e8766b77f0176e9680522cd4a9b325a2e1b33c Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 22:30:11 -0400 Subject: [PATCH 03/11] "PlayerQuit" hook --- src/d_clisrv.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index c0f81ba32..973564a9b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2208,7 +2208,7 @@ void CL_ClearPlayer(INT32 playernum) // // Removes a player from the current game // -static void CL_RemovePlayer(INT32 playernum) +static void CL_RemovePlayer(INT32 playernum, INT32 reason) { // Sanity check: exceptional cases (i.e. c-fails) can cause multiple // kick commands to be issued for the same player. @@ -2262,6 +2262,10 @@ static void CL_RemovePlayer(INT32 playernum) } } } + +#ifdef HAVE_BLUA + LUAh_PlayerQuit(&players[playernum], reason); // Lua hook for player quitting +#endif // Reset player data CL_ClearPlayer(playernum); @@ -2513,6 +2517,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) INT32 pnum, msg; XBOXSTATIC char buf[3 + MAX_REASONLENGTH]; char *reason = buf; + INT32 kickreason = 1; pnum = READUINT8(*p); msg = READUINT8(*p); @@ -2593,14 +2598,17 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) { case KICK_MSG_GO_AWAY: CONS_Printf(M_GetText("has been kicked (Go away)\n")); + kickreason = 1; break; #ifdef NEWPING case KICK_MSG_PING_HIGH: CONS_Printf(M_GetText("left the game (Broke ping limit)\n")); + kickreason = 2; break; #endif case KICK_MSG_CON_FAIL: CONS_Printf(M_GetText("left the game (Synch failure)\n")); + kickreason = 3; if (M_CheckParm("-consisdump")) // Helps debugging some problems { @@ -2637,21 +2645,26 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) break; case KICK_MSG_TIMEOUT: CONS_Printf(M_GetText("left the game (Connection timeout)\n")); + kickreason = 4; break; case KICK_MSG_PLAYER_QUIT: if (netgame) // not splitscreen/bots CONS_Printf(M_GetText("left the game\n")); + kickreason = 6; break; case KICK_MSG_BANNED: CONS_Printf(M_GetText("has been banned (Don't come back)\n")); + kickreason = 5; break; case KICK_MSG_CUSTOM_KICK: READSTRINGN(*p, reason, MAX_REASONLENGTH+1); CONS_Printf(M_GetText("has been kicked (%s)\n"), reason); + kickreason = 1; break; case KICK_MSG_CUSTOM_BAN: READSTRINGN(*p, reason, MAX_REASONLENGTH+1); CONS_Printf(M_GetText("has been banned (%s)\n"), reason); + kickreason = 5; break; } @@ -2679,7 +2692,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) M_StartMessage(M_GetText("You have been kicked by the server\n\nPress ESC\n"), NULL, MM_NOTHING); } else - CL_RemovePlayer(pnum); + CL_RemovePlayer(pnum, kickreason); } consvar_t cv_allownewplayer = {"allowjoin", "On", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; From fcf2fe79e00dae735cf383ce04422a6548fe4288 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 23:25:47 -0400 Subject: [PATCH 04/11] Oops; PlayerQuit isn't a boolean! --- src/lua_hook.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 240fdaece..94b934f32 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -78,6 +78,6 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook 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 -boolean LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting +void LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting #endif From defc7c164545eeae8db8f81de5c8ca46eff9af14 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 23:26:41 -0400 Subject: [PATCH 05/11] Oops; PlayerQuit isn't a boolean! --- src/lua_hooklib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index be3f8b0e1..5ac77da97 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -799,12 +799,12 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) // stack: tables } -boolean LUAh_PlayerQuit(player_t *plr, int reason) +void LUAh_PlayerQuit(player_t *plr, int reason) { hook_p hookp; boolean hooked = false; if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8)))) - return false; + return; lua_settop(gL, 0); From 673315265107da0740372f2ba1917cb89396c208 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Fri, 21 Oct 2016 16:16:54 -0400 Subject: [PATCH 06/11] No more magic numbers --- src/d_clisrv.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 973564a9b..cfe0c1cdd 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2517,7 +2517,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) INT32 pnum, msg; XBOXSTATIC char buf[3 + MAX_REASONLENGTH]; char *reason = buf; - INT32 kickreason = 1; + kickreason_t kickreason = KR_KICK; pnum = READUINT8(*p); msg = READUINT8(*p); @@ -2598,17 +2598,17 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) { case KICK_MSG_GO_AWAY: CONS_Printf(M_GetText("has been kicked (Go away)\n")); - kickreason = 1; + kickreason = KR_KICK; break; #ifdef NEWPING case KICK_MSG_PING_HIGH: CONS_Printf(M_GetText("left the game (Broke ping limit)\n")); - kickreason = 2; + kickreason = KR_PINGLIMIT; break; #endif case KICK_MSG_CON_FAIL: CONS_Printf(M_GetText("left the game (Synch failure)\n")); - kickreason = 3; + kickreason = KR_SYNCH; if (M_CheckParm("-consisdump")) // Helps debugging some problems { @@ -2645,26 +2645,26 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) break; case KICK_MSG_TIMEOUT: CONS_Printf(M_GetText("left the game (Connection timeout)\n")); - kickreason = 4; + kickreason = KR_TIMEOUT; break; case KICK_MSG_PLAYER_QUIT: if (netgame) // not splitscreen/bots CONS_Printf(M_GetText("left the game\n")); - kickreason = 6; + kickreason = KR_LEAVE; break; case KICK_MSG_BANNED: CONS_Printf(M_GetText("has been banned (Don't come back)\n")); - kickreason = 5; + kickreason = KR_BAN; break; case KICK_MSG_CUSTOM_KICK: READSTRINGN(*p, reason, MAX_REASONLENGTH+1); CONS_Printf(M_GetText("has been kicked (%s)\n"), reason); - kickreason = 1; + kickreason = KR_KICK; break; case KICK_MSG_CUSTOM_BAN: READSTRINGN(*p, reason, MAX_REASONLENGTH+1); CONS_Printf(M_GetText("has been banned (%s)\n"), reason); - kickreason = 5; + kickreason = KR_BAN; break; } From c38457f23c70509cef3fd131e380332c2e43ab4f Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Fri, 21 Oct 2016 16:25:07 -0400 Subject: [PATCH 07/11] No more magic numbers --- src/d_clisrv.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 14b590926..cd726d9b3 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -436,6 +436,17 @@ extern consvar_t cv_playbackspeed; #define KICK_MSG_CUSTOM_KICK 7 #define KICK_MSG_CUSTOM_BAN 8 +typedef enum +{ + KR_KICK = 1, //Kicked by server + KR_PINGLIMIT = 2, //Broke Ping Limit + KR_SYNCH = 3, //Synch Failure + KR_TIMEOUT = 4, //Connection Timeout + KR_BAN = 5, //Banned by server + KR_LEAVE = 6, //Quit the game + +} kickreason_t; + extern boolean server; extern boolean dedicated; // for dedicated server extern UINT16 software_MAXPACKETLENGTH; From b5988e082cd012555e532d7c0a25b73818ec6566 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Fri, 21 Oct 2016 16:27:15 -0400 Subject: [PATCH 08/11] No more magic numbers --- src/dehacked.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dehacked.c b/src/dehacked.c index f03dd73b4..62a7ad811 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -31,6 +31,7 @@ #include "fastcmp.h" #include "lua_script.h" #include "lua_hook.h" +#include "d_clisrv.h" #include "m_cond.h" @@ -7392,6 +7393,14 @@ struct { {"V_CHARCOLORSHIFT",V_CHARCOLORSHIFT}, {"V_ALPHASHIFT",V_ALPHASHIFT}, + + //Kick Reasons + {"KR_KICK",KR_KICK}, + {"KR_PINGLIMIT",KR_PINGLIMIT}, + {"KR_SYNCH",KR_SYNCH}, + {"KR_TIMEOUT",KR_TIMEOUT}, + {"KR_BAN",KR_BAN}, + {"KR_LEAVE",KR_LEAVE}, #endif {NULL,0} From b1ce5896aa97509268589cbcba26431c08f8adf9 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Tue, 8 Nov 2016 10:30:01 -0500 Subject: [PATCH 09/11] Remove boolean remnants --- src/lua_hooklib.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 5ac77da97..16f8c55d3 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -802,7 +802,6 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) void LUAh_PlayerQuit(player_t *plr, int reason) { hook_p hookp; - boolean hooked = false; if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8)))) return; @@ -811,29 +810,16 @@ void LUAh_PlayerQuit(player_t *plr, int reason) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerQuit) { - if (lua_gettop(gL) == 0) - { - LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit - lua_pushinteger(gL, reason); // Reason for quitting - } + LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit + lua_pushinteger(gL, reason); // Reason for quitting lua_pushfstring(gL, FMT_HOOKID, hookp->id); lua_gettable(gL, LUA_REGISTRYINDEX); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); - if (lua_pcall(gL, 2, 1, 0)) { - if (!hookp->error || cv_debug & DBG_LUA) - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); - hookp->error = true; - continue; - } - if (lua_toboolean(gL, -1)) - hooked = true; - lua_pop(gL, 1); + LUA_Call(gL, 2); } lua_settop(gL, 0); - return hooked; } #endif From d788cb7676e8832147d9e6ae911b10005987a85c Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Fri, 25 Nov 2016 15:20:41 -0500 Subject: [PATCH 10/11] Keeping the lua_gettop(gL) thing, otherwise the player/reason values will be pushed once to the stack each for every hook. Thanks MonsterIestyn! --- src/lua_hooklib.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 16f8c55d3..7c10b7e38 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -810,7 +810,11 @@ void LUAh_PlayerQuit(player_t *plr, int reason) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerQuit) { - LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit + if (lua_gettop(gL) == 0) + { + LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit + lua_pushinteger(gL, reason); // Reason for quitting + } lua_pushinteger(gL, reason); // Reason for quitting lua_pushfstring(gL, FMT_HOOKID, hookp->id); lua_gettable(gL, LUA_REGISTRYINDEX); From dd13df230831debbfb08a447800ea8cc18bd4abf Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Sat, 3 Dec 2016 18:18:16 -0500 Subject: [PATCH 11/11] Whoops, didn't see the duplicate line. --- src/lua_hooklib.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 7c10b7e38..273264d7d 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -815,7 +815,6 @@ void LUAh_PlayerQuit(player_t *plr, int reason) LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit lua_pushinteger(gL, reason); // Reason for quitting } - lua_pushinteger(gL, reason); // Reason for quitting lua_pushfstring(gL, FMT_HOOKID, hookp->id); lua_gettable(gL, LUA_REGISTRYINDEX); lua_pushvalue(gL, -3);