From 53db028bdb9041b9753dcabe9ecc9e97d2f4f5d9 Mon Sep 17 00:00:00 2001 From: Hanicef Date: Fri, 6 Sep 2024 12:21:34 +0200 Subject: [PATCH] Synchronize rate limit variables and limit PlayerMsg hook --- src/hu_stuff.c | 10 ++++------ src/hu_stuff.h | 3 +++ src/p_saveg.c | 13 +++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index caf13a445..a7d0aea74 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -587,8 +587,8 @@ static void Command_CSay_f(void) DoSayCommand(0, 1, HU_CSAY); } -static tic_t spam_tokens[MAXPLAYERS] = { 1 }; // fill the buffer with 1 so the motd can be sent. -static tic_t spam_tics[MAXPLAYERS]; +UINT8 spam_tokens[MAXPLAYERS] = { 1 }; // fill the buffer with 1 so the motd can be sent. +tic_t spam_tics[MAXPLAYERS]; /** Receives a message, processing an ::XD_SAY command. * \sa DoSayCommand @@ -649,14 +649,12 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) else spam_tokens[playernum] -= 1; - // run the lua hook even if we were supposed to eat the msg, netgame consistency goes first. + if (spam_eatmsg) + return; // don't proceed if we were supposed to eat the message. if (LUA_HookPlayerMsg(playernum, target, flags, msg)) return; - if (spam_eatmsg) - return; // don't proceed if we were supposed to eat the message. - // If it's a CSAY, just CECHO and be done with it. if (flags & HU_CSAY) { diff --git a/src/hu_stuff.h b/src/hu_stuff.h index ca77ed930..07881ce1a 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -79,6 +79,9 @@ void HU_AddChatText(const char *text, boolean playsound); // set true when entering a chat message extern boolean chat_on; +extern UINT8 spam_tokens[MAXPLAYERS]; +extern tic_t spam_tics[MAXPLAYERS]; + extern patch_t *emeraldpics[3][8]; extern patch_t *rflagico; extern patch_t *bflagico; diff --git a/src/p_saveg.c b/src/p_saveg.c index da73dd8a0..c5ec57d01 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -35,6 +35,7 @@ #include "p_polyobj.h" #include "lua_script.h" #include "p_slopes.h" +#include "hu_stuff.h" savedata_t savedata; UINT8 *save_p; @@ -4611,6 +4612,12 @@ static void P_NetArchiveMisc(boolean resending) WRITEUINT8(save_p, 0x2f); else WRITEUINT8(save_p, 0x2e); + + for (i = 0; i < MAXPLAYERS; i++) + { + WRITEUINT8(save_p, spam_tokens[i]); + WRITEUINT32(save_p, spam_tics[i]); + } } static inline boolean P_NetUnArchiveMisc(boolean reloading) @@ -4708,6 +4715,12 @@ static inline boolean P_NetUnArchiveMisc(boolean reloading) if (READUINT8(save_p) == 0x2f) paused = true; + for (i = 0; i < MAXPLAYERS; i++) + { + spam_tokens[i] = READUINT8(save_p); + spam_tics[i] = READUINT32(save_p); + } + return true; }