From fce57a102767aa3c71334c46effe613b4d472c66 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Tue, 29 Mar 2022 15:42:31 -0400 Subject: [PATCH] startedInFreePlay --- src/d_clisrv.c | 21 +++++++++++++++++++++ src/d_clisrv.h | 17 +++++++++-------- src/g_game.c | 3 +++ src/k_kart.c | 45 ++++++++++++++++++++++++++++++++++++--------- src/p_saveg.c | 2 ++ src/p_setup.c | 39 +++++++++++++++++++++++++++++++-------- src/p_tick.c | 5 +++++ src/p_user.c | 4 ++-- 8 files changed, 109 insertions(+), 27 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 925bf2e4..eb191757 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2972,6 +2972,23 @@ void CL_RemovePlayer(INT32 playernum, INT32 reason) K_CheckBumpers(); else if (G_RaceGametype()) P_CheckRacers(); + + // Reset startedInFreePlay + { + INT32 i; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && !players[i].spectator) + break; + } + + if (i == MAXPLAYERS) + { + // Server was emptied, consider it FREE PLAY. + startedInFreePlay = true; + } + } } void CL_Reset(void) @@ -3412,6 +3429,10 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) HU_AddChatText(va("\x82*%s left the game", player_names[pnum]), false); kickreason = KR_LEAVE; break; + case KICK_MSG_GRIEF: + HU_AddChatText(va("\x82*%s has been kicked (Automatic grief detection)", player_names[pnum]), false); + kickreason = KR_KICK; + break; case KICK_MSG_BANNED: HU_AddChatText(va("\x82*%s has been banned (Don't come back)", player_names[pnum]), false); kickreason = KR_BAN; diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 7a8272b2..853af371 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -521,17 +521,18 @@ extern consvar_t cv_playbackspeed; #define KICK_MSG_TIMEOUT 4 #define KICK_MSG_BANNED 5 #define KICK_MSG_PING_HIGH 6 -#define KICK_MSG_CUSTOM_KICK 7 -#define KICK_MSG_CUSTOM_BAN 8 +#define KICK_MSG_GRIEF 7 +#define KICK_MSG_CUSTOM_KICK 8 +#define KICK_MSG_CUSTOM_BAN 9 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 + KR_KICK = 1, //Kicked by server + KR_PINGLIMIT, //Broke Ping Limit + KR_SYNCH, //Synch Failure + KR_TIMEOUT, //Connection Timeout + KR_BAN, //Banned by server + KR_LEAVE, //Quit the game } kickreason_t; diff --git a/src/g_game.c b/src/g_game.c index 91bd11fa..c1034d59 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -275,6 +275,7 @@ tic_t mapreset; // Map reset delay when enough players have joined an empty game UINT8 nospectategrief; // How many players need to be in-game to eliminate last; for preventing spectate griefing boolean thwompsactive; // Thwomps activate on lap 2 SINT8 spbplace; // SPB exists, give the person behind better items +boolean startedInFreePlay; // Map was started in free play // Client-sided, unsynched variables (NEVER use in anything that needs to be synced with other players) boolean legitimateexit; // Did this client actually finish the match? @@ -2482,7 +2483,9 @@ void G_Ticker(boolean run) if (G_GametypeHasSpectators() && (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING // definitely good || gamestate == GS_WAITINGPLAYERS)) // definitely a problem if we don't do it at all in this gamestate, but might need more protection? + { K_CheckSpectateStatus(); + } if (pausedelay) pausedelay--; diff --git a/src/k_kart.c b/src/k_kart.c index 02a3c77e..7b95d7a0 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -6316,6 +6316,10 @@ void K_CheckSpectateStatus(void) if (numingame < 2 || leveltime < starttime || mapreset) continue; + // DON'T allow if the match is 20 seconds in + if (leveltime > (starttime + 20*TICRATE)) + return; + // DON'T allow if the race is on the second lap if (G_RaceGametype() && players[i].laps) return; @@ -6331,15 +6335,11 @@ void K_CheckSpectateStatus(void) respawnlist[numjoiners++] = i; } - // 1.4: prevent last lap jerkitude - if (gamestate == GS_LEVEL) + // The map started as a legitimate race, but there's still the one player. + // Don't allow new joiners, as they're probably a ragespeccer. + if (G_RaceGametype() && startedInFreePlay == false && numingame == 1) { - if (!numingame) // but allow empty netgames to recover - nospectategrief = 0; - else if (!nospectategrief && (leveltime > (starttime + 20*TICRATE))) - nospectategrief = numingame; - if (nospectategrief > 1) - return; + return; } // literally zero point in going any further if nobody is joining @@ -6391,13 +6391,40 @@ void K_CheckSpectateStatus(void) } // Reset the match if you're in an empty server - if (!mapreset && gamestate == GS_LEVEL && leveltime >= starttime && (previngame < 2 && numingame >= 2)) + if (!mapreset && gamestate == GS_LEVEL && (previngame < 2 && numingame >= 2)) { S_ChangeMusicInternal("chalng", false); // COME ON mapreset = 3*TICRATE; // Even though only the server uses this for game logic, set for everyone for HUD } } +void K_UpdateSpectateGrief(void) +{ + UINT8 numingame = 0; + + if (nospectategrief) + { + return; + } + + if (leveltime <= (starttime + 20*TICRATE)) + { + return; + } + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + { + continue; + } + + numingame++; + } + + nospectategrief = numingame; +} + //} //{ SRB2kart HUD Code diff --git a/src/p_saveg.c b/src/p_saveg.c index 3a29269b..11ee6630 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3278,6 +3278,7 @@ static void P_NetArchiveMisc(void) WRITEUINT8(save_p, nospectategrief); WRITEUINT8(save_p, thwompsactive); WRITESINT8(save_p, spbplace); + WRITEUINT8(save_p, startedInFreePlay); // Is it paused? if (paused) @@ -3387,6 +3388,7 @@ static inline boolean P_NetUnArchiveMisc(void) nospectategrief = READUINT8(save_p); thwompsactive = (boolean)READUINT8(save_p); spbplace = READSINT8(save_p); + startedInFreePlay = READUINT8(save_p); // Is it paused? if (READUINT8(save_p) == 0x2f) diff --git a/src/p_setup.c b/src/p_setup.c index 24241a7f..1868664d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3229,6 +3229,37 @@ boolean P_SetupLevel(boolean skipprecip) G_RecordDemo(buf); } + wantedcalcdelay = wantedfrequency*2; + indirectitemcooldown = 0; + hyubgone = 0; + mapreset = 0; + nospectategrief = 0; + thwompsactive = false; + spbplace = -1; + + startedInFreePlay = false; + { + UINT8 nump = 0; + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + { + continue; + } + + nump++; + if (nump == 2) + { + break; + } + } + + if (nump <= 1) + { + startedInFreePlay = true; + } + } + // =========== // landing point for netgames. netgameskip: @@ -3301,14 +3332,6 @@ boolean P_SetupLevel(boolean skipprecip) CV_SetValue(&cv_analog, false); }*/ - wantedcalcdelay = wantedfrequency*2; - indirectitemcooldown = 0; - hyubgone = 0; - mapreset = 0; - nospectategrief = 0; - thwompsactive = false; - spbplace = -1; - // clear special respawning que iquehead = iquetail = 0; diff --git a/src/p_tick.c b/src/p_tick.c index 6a85027f..11adc9d8 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -735,6 +735,11 @@ void P_Ticker(boolean run) if (hyubgone > 0) hyubgone--; + if (G_RaceGametype()) + { + K_UpdateSpectateGrief(); + } + if (G_BattleGametype()) { if (wantedcalcdelay && --wantedcalcdelay <= 0) diff --git a/src/p_user.c b/src/p_user.c index e6ff7d96..a6f13990 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8504,7 +8504,7 @@ void P_PlayerThink(player_t *player) } } - if (netgame && cv_antigrief.value != 0) + if (netgame && cv_antigrief.value != 0 && G_RaceGametype()) { if (!player->spectator && !player->exiting && !(player->pflags & PF_TIMEOVER)) { @@ -8530,7 +8530,7 @@ void P_PlayerThink(player_t *player) XBOXSTATIC UINT8 buf[2]; buf[0] = n; - buf[1] = KICK_MSG_CON_FAIL; + buf[1] = KICK_MSG_GRIEF; SendNetXCmd(XD_KICK, &buf, 2); } else