summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-04-13 11:30:00 +0000
committer/dev/humancontroller <devhc@example.com>2017-04-15 17:24:22 +0200
commit5510cfbeec0bcb59eac770fdb9b5132d7c61b426 (patch)
tree2a71ecfe949c306bbeadc5eca7b69e23dbbdf477 /src
parent56d892b6df06a88694988a2c8410dfaebc9bf9ac (diff)
Add a cool down timer to !revert.
This will prevent two (or more) admins from trying to !revert simultaneously and accidentally undoing innocent players' progress.
Diffstat (limited to 'src')
-rw-r--r--src/game/g_admin.c22
-rw-r--r--src/game/g_local.h3
-rw-r--r--src/game/g_main.c6
3 files changed, 29 insertions, 2 deletions
diff --git a/src/game/g_admin.c b/src/game/g_admin.c
index 3b5c8a3..8a77326 100644
--- a/src/game/g_admin.c
+++ b/src/game/g_admin.c
@@ -7997,9 +7997,13 @@ int G_admin_autorevert( gentity_t *ent )
return count;
}
+static int lastRevertCookie = 0;
+static int lastRevertTime = 0;
+static int consoleRevertCookie = 0;
+
qboolean G_admin_revert( gentity_t *ent, int skiparg )
{
- int i = 0, j = 0, repeat = 1, ID = 0, len, matchlen=0;
+ int i = 0, j = 0, repeat = 1, ID = 0, len, matchlen=0, *cookie;
pTeam_t team = PTE_NONE;
qboolean force = qfalse, reached = qfalse;
gentity_t *builder = NULL, *targ;
@@ -8017,6 +8021,18 @@ qboolean G_admin_revert( gentity_t *ent, int skiparg )
ADMP( "^3!revert: ^7usage: !revert (^5xnum^7) (^5#ID^7) (^5-name|num^7) (^5a|h^7)\n" );
return qfalse;
}
+ if( ent )
+ cookie = &ent->client->revertCookie;
+ else
+ cookie = &consoleRevertCookie;
+ if( lastRevertCookie > 0 &&
+ ( lastRevertTime + g_revertCooldownTime.integer * 1000 > level.time ) &&
+ *cookie < lastRevertCookie )
+ {
+ ADMP( "^3!revert: ^7someone just reverted, repeat this command if it's not an error\n" );
+ *cookie = lastRevertCookie;
+ return qfalse;
+ }
for( i = 1; i + skiparg < G_SayArgc( ); i++ )
{
char arg[ 64 ], err[ MAX_STRING_CHARS ];
@@ -8224,6 +8240,10 @@ qboolean G_admin_revert( gentity_t *ent, int skiparg )
{
ADMP( va( "^3!revert: ^7reverted %d buildlog events\n", matchlen ) );
}
+
+ lastRevertTime = level.time;
+ lastRevertCookie++;
+ *cookie = lastRevertCookie;
return qtrue;
}
diff --git a/src/game/g_local.h b/src/game/g_local.h
index 46c53ba..6e077bd 100644
--- a/src/game/g_local.h
+++ b/src/game/g_local.h
@@ -549,6 +549,7 @@ struct gclient_s
int tkcredits[ MAX_CLIENTS ];
+ int revertCookie;
};
@@ -1541,6 +1542,8 @@ extern vmCvar_t g_reportWelcomeComment;
extern vmCvar_t g_scrimMode;
+extern vmCvar_t g_revertCooldownTime;
+
void trap_Printf( const char *fmt );
void trap_Error( const char *fmt );
int trap_Milliseconds( void );
diff --git a/src/game/g_main.c b/src/game/g_main.c
index a8677eb..5cfc383 100644
--- a/src/game/g_main.c
+++ b/src/game/g_main.c
@@ -282,6 +282,8 @@ vmCvar_t g_reportWelcomeComment;
vmCvar_t g_scrimMode;
+vmCvar_t g_revertCooldownTime;
+
static cvarTable_t gameCvarTable[ ] =
{
// don't override the cheat state set by the system
@@ -541,7 +543,9 @@ static cvarTable_t gameCvarTable[ ] =
{ &g_reportWelcomeComment, "g_reportWelcomeComment", "", CVAR_ARCHIVE, 0, qfalse },
- { &g_scrimMode, "g_scrimMode", "0", CVAR_ARCHIVE, 0, qfalse }
+ { &g_scrimMode, "g_scrimMode", "0", CVAR_ARCHIVE, 0, qfalse },
+
+ { &g_revertCooldownTime, "g_revertCooldownTime", "30", CVAR_ARCHIVE, 0, qfalse }
};
static int gameCvarTableSize = sizeof( gameCvarTable ) / sizeof( gameCvarTable[ 0 ] );