fix issue with ban expire times.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4779 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2014-10-27 15:27:51 +00:00
parent ea3aa75290
commit 661d64056a

View file

@ -964,9 +964,6 @@ void SV_KillExpiredBans(void)
if (reevaluatebantime && curtime > reevaluatebantime) if (reevaluatebantime && curtime > reevaluatebantime)
{ {
reevaluatebantime = 0; reevaluatebantime = 0;
reevaluatebantime = ~reevaluatebantime; //should be 64bit safe?
if (reevaluatebantime < 0)
reevaluatebantime = (unsigned long long)reevaluatebantime>>1;
for(link = &svs.bannedips; (banip = *link) != NULL; ) for(link = &svs.bannedips; (banip = *link) != NULL; )
{ {
if (banip->expiretime) if (banip->expiretime)
@ -978,8 +975,8 @@ void SV_KillExpiredBans(void)
Z_Free(banip); Z_Free(banip);
continue; continue;
} }
if (reevaluatebantime > banip->expiretime) if (!reevaluatebantime || reevaluatebantime > banip->expiretime)
reevaluatebantime = banip->expiretime; reevaluatebantime = banip->expiretime+1;
} }
link = &banip->next; link = &banip->next;
} }
@ -1021,10 +1018,8 @@ static qboolean SV_AddBanEntry(bannedips_t *proto, char *reason)
return false; return false;
} }
if (!nb->banflags) if (!nb->banflags)
{
reevaluatebantime = nb->expiretime = 1; //make sure it expires 'soon'. reevaluatebantime = nb->expiretime = 1; //make sure it expires 'soon'.
} }
}
nb = nb->next; nb = nb->next;
} }
@ -1042,7 +1037,7 @@ static qboolean SV_AddBanEntry(bannedips_t *proto, char *reason)
*link = nb; *link = nb;
reevaluatebans = true; //make sure the new ban/penalty applies to the right IPs. reevaluatebans = true; //make sure the new ban/penalty applies to the right IPs.
if (nb->expiretime && reevaluatebantime > nb->expiretime) if (nb->expiretime && (!reevaluatebantime || reevaluatebantime > nb->expiretime))
reevaluatebantime = nb->expiretime; reevaluatebantime = nb->expiretime;
return true; return true;
} }
@ -1070,7 +1065,7 @@ static int SV_ToggleBan(bannedips_t *proto, char *reason)
nb->banflags &= ~proto->banflags; nb->banflags &= ~proto->banflags;
reevaluatebans = true; reevaluatebans = true;
if (!nb->banflags) if (!nb->banflags)
reevaluatebantime = nb->expiretime = 1; //make sure it expires 'soon'. reevaluatebantime = nb->expiretime = 1; //make sure it expires 'soon' (in the past).
} }
} }
nb = nb->next; nb = nb->next;
@ -1177,7 +1172,15 @@ static void SV_FilterIP_f (void)
s = Cmd_Argv(3); s = Cmd_Argv(3);
if (*s == '+') if (*s == '+')
proto.expiretime = SV_BanTime() + strtoull(s+1, NULL, 0); {
time_t secs = strtoull(s+1, &s, 0);
if (*s == ':')
{
secs*=60;
secs+=strtoull(s+1, &s, 0);
}
proto.expiretime = SV_BanTime() + secs;
}
else else
proto.expiretime = strtoull(s, NULL, 0); proto.expiretime = strtoull(s, NULL, 0);
@ -1220,6 +1223,7 @@ static void SV_FilterList_f (void)
char adr[MAX_ADR_SIZE]; char adr[MAX_ADR_SIZE];
char banflags[1024]; char banflags[1024];
int i; int i;
time_t curtime = SV_BanTime();
static const char *banflagnames[] = { static const char *banflagnames[] = {
"ban", "ban",
"safe", "safe",
@ -1249,6 +1253,12 @@ static void SV_FilterList_f (void)
} }
} }
if (nb->expiretime)
{
time_t secs = nb->expiretime - curtime;
Con_Printf("%s %s +%llu:%02llu\n", NET_AdrToStringMasked(adr, sizeof(adr), &nb->adr, &nb->adrmask), banflags, (unsigned long long)(secs/60), (unsigned long long)(secs%60));
}
else
Con_Printf("%s %s\n", NET_AdrToStringMasked(adr, sizeof(adr), &nb->adr, &nb->adrmask), banflags); Con_Printf("%s %s\n", NET_AdrToStringMasked(adr, sizeof(adr), &nb->adr, &nb->adrmask), banflags);
filtercount++; filtercount++;
nb = nb->next; nb = nb->next;