From 167f5f40edb3774798b97934320a2e134ae29cc0 Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Sat, 29 Apr 2023 20:16:20 -0700 Subject: [PATCH] PT_SAY and gamestochat: the rest of the owl --- src/d_clisrv.c | 33 +++++++++++++++++++++++++++++++-- src/d_clisrv.h | 3 +++ src/d_netcmd.c | 1 + src/hu_stuff.c | 13 +++++++++++++ src/hu_stuff.h | 1 + 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 79d57fccd..cd76ebfc1 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -222,6 +222,8 @@ consvar_t cv_httpsource = CVAR_INIT ("http_source", "", CV_SAVE, NULL, NULL); consvar_t cv_kicktime = CVAR_INIT ("kicktime", "10", CV_SAVE, CV_Unsigned, NULL); +consvar_t cv_gamestochat = CVAR_INIT ("gamestochat", "0", 0, CV_Unsigned, NULL); + static tic_t stop_spamming[MAXPLAYERS]; // Generate a message for an authenticating client to sign, with some guarantees about who we are. @@ -5258,6 +5260,13 @@ static void HandlePacketFromPlayer(SINT8 node) break; } + if ((say.flags & HU_PRIVNOTICE) && !(IsPlayerAdmin(say.source))) + { + CONS_Debug(DBG_NETPLAY,"Received SAY cmd from Player %d (%s) with an illegal HU_PRIVNOTICE flag.\n", say.source+1, player_names[say.source]); + SendKick(say.source, KICK_MSG_CON_FAIL); + return; + } + { size_t i; const size_t j = strlen(say.message); @@ -5266,8 +5275,7 @@ static void HandlePacketFromPlayer(SINT8 node) if (say.message[i] & 0x80) { CONS_Alert(CONS_WARNING, M_GetText("Illegal say command received from %s containing invalid characters\n"), player_names[say.source]); - if (server) - SendKick(say.source, KICK_MSG_CON_FAIL); + SendKick(say.source, KICK_MSG_CON_FAIL); return; } } @@ -5282,6 +5290,20 @@ static void HandlePacketFromPlayer(SINT8 node) stop_spamming[say.source] = 4; + serverplayer_t *stats = SV_GetStatsByPlayerIndex(say.source); + int remainingGames = cv_gamestochat.value - stats->finishedrounds; + + if (remainingGames > 0 && !(IsPlayerAdmin(say.source))) + { + CONS_Debug(DBG_NETPLAY,"Received SAY cmd from Player %d (%s), but they aren't permitted to chat yet.\n", say.source+1, player_names[say.source]); + + char rejectmsg[256]; + strlcpy(rejectmsg, va("Please play %d more games to use chat.", remainingGames), 256); + SendServerNotice(say.source, rejectmsg); + + break; + } + DoSayCommand(say.message, say.target, say.flags, say.source); break; case PT_LOGIN: @@ -7032,4 +7054,11 @@ void DoSayPacketFromCommand(SINT8 target, size_t usedargs, UINT8 flags) } DoSayPacket(target, flags, consoleplayer, msg); +} + +void SendServerNotice(SINT8 target, char *message) +{ + if (client) + return; + DoSayCommand(message, target + 1, HU_PRIVNOTICE, servernode); } \ No newline at end of file diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 5f194498f..ae3811c4e 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -542,6 +542,8 @@ extern consvar_t cv_discordinvites; extern consvar_t cv_allowguests; +extern consvar_t cv_gamestochat; + #ifdef DEVELOP extern consvar_t cv_badjoin; extern consvar_t cv_badtraffic; @@ -645,6 +647,7 @@ void HandleSigfail(const char *string); void DoSayPacket(SINT8 target, UINT8 flags, UINT8 source, char *message); void DoSayPacketFromCommand(SINT8 target, size_t usedargs, UINT8 flags); +void SendServerNotice(SINT8 target, char *message); #ifdef __cplusplus } // extern "C" diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 0f351c201..987262a06 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -953,6 +953,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_mindelay); CV_RegisterVar(&cv_allowguests); + CV_RegisterVar(&cv_gamestochat); #ifdef DEVELOP CV_RegisterVar(&cv_badjoin); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 6c0311f51..ce448f651 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -790,6 +790,13 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) cstart = "\x82"; textcolor = "\x82"; fmt2 = "%s<%s%s>%s\x80 %s%s"; + + if (flags & HU_PRIVNOTICE) + { + dispname = "SERVER"; + prefix = "\x82"; + fmt2 = "%s[%s%s]%s %s%s"; + } } else if (target > 0) // By you, to another player { @@ -799,6 +806,12 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) cstart = "\x82"; fmt2 = "%s<%s%s>%s\x80 %s%s"; + if (flags & HU_PRIVNOTICE) + { + if (tempchar) + Z_Free(tempchar); + return; // I pretend I do not see it + } } else // To everyone or sayteam, it doesn't change anything. fmt2 = "%s<%s%s%s>\x80 %s%s"; diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 546061462..ca1b72c37 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -109,6 +109,7 @@ typedef enum { HU_SHOUT = 1, // Shout message HU_CSAY = 1<<1, // Middle-of-screen server message + HU_PRIVNOTICE = 1<<2, // Special server sayto, we don't want to see it as the sender. } sayflags_t; // some functions