From 82e07467da674895695cac8d219158739bf4ff66 Mon Sep 17 00:00:00 2001 From: z411 Date: Thu, 15 Oct 2020 22:34:29 -0300 Subject: [PATCH] Item respawn fix and ready anti-flood --- qcsrc/server/command/cmd.qc | 6 ++++-- qcsrc/server/command/vote.qh | 1 + qcsrc/server/items/items.qc | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index 0ba8ed300..2772e4f2c 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -376,13 +376,13 @@ void ClientCommand_physics(entity caller, int request, int argc) } } -void ClientCommand_ready(entity caller, int request) // todo: anti-spam for toggling readyness +void ClientCommand_ready(entity caller, int request) { switch (request) { case CMD_REQUEST_COMMAND: { - if (IS_CLIENT(caller)) + if (IS_CLIENT(caller) && caller.last_ready < time - 3) // anti-spam { if (warmup_stage || sv_ready_restart || g_race_qualifying == 2) { @@ -402,6 +402,8 @@ void ClientCommand_ready(entity caller, int request) // todo: anti-spam for tog if(IS_PLAYER(caller) || caller.caplayer == 1) bprint("\{1}", playername(caller, false), "^2 is ready\n"); } + + caller.last_ready = time; // cannot reset the game while a timeout is active! if (!timeout_status) ReadyCount(); diff --git a/qcsrc/server/command/vote.qh b/qcsrc/server/command/vote.qh index 6c4d30d17..8d70e7693 100644 --- a/qcsrc/server/command/vote.qh +++ b/qcsrc/server/command/vote.qh @@ -57,6 +57,7 @@ float readycount; // amount of players who are ready float readyrestart_happened; // keeps track of whether a restart has already happened float restart_mapalreadyrestarted; // bool, indicates whether reset_map() was already executed .float ready; // flag for if a player is ready +.float last_ready; // z411 time of the last readyup for anti-spam .int team_saved; // team number to restore upon map reset .void(entity this) reset; // if set, an entity is reset using this .void(entity this) reset2; // if set, an entity is reset using this (after calling ALL the reset functions for other entities) diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index 906e89aea..93da11a47 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -222,6 +222,8 @@ void Item_Respawn(entity this) void Item_RespawnCountdown(entity this) { + if(game_timeout) { this.nextthink = time + 1; return; } + if(this.item_respawncounter >= ITEM_RESPAWN_TICKS) { if(this.waypointsprite_attached) @@ -231,7 +233,11 @@ void Item_RespawnCountdown(entity this) else { this.nextthink = time + 1; - this.item_respawncounter += 1; + this.item_respawncounter = floor((time - timeout_total_time) - (this.scheduledrespawntime - ITEM_RESPAWN_TICKS)) + 1; + //this.item_respawncounter += 1; + //LOG_INFOF("Respawncounter: %d", this.item_respawncounter); + if(this.item_respawncounter < 1) return; + if(this.item_respawncounter == 1) { do { @@ -296,9 +302,12 @@ void Item_ScheduleRespawnIn(entity e, float t) if ((Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS) || MUTATOR_CALLHOOK(Item_ScheduleRespawn, e, t)) && (t - ITEM_RESPAWN_TICKS) > 0) { setthink(e, Item_RespawnCountdown); - e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS); - e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS; + //e.nextthink = time - timeout_total_time + max(0, t - ITEM_RESPAWN_TICKS); + //e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS; + e.nextthink = time; + e.scheduledrespawntime = time - timeout_total_time + t; e.item_respawncounter = 0; + if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS)) { t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime); -- 2.39.2