mirror of
https://github.com/ioquake/ioq3.git
synced 2025-05-29 16:11:31 +00:00
- Introduce new NET_CompareBaseAdrMask for easy comparison of ip address ranges
- Overhaul of the new banning functions: * basic check for redundant bans/exceptions * introduction of sv_banFile to make it possible to configure the file where to read bans and exceptions from * bans can now be deleted by giving address ranges, too.
This commit is contained in:
parent
1f779efbb8
commit
50ca55702f
8 changed files with 303 additions and 151 deletions
|
@ -234,18 +234,9 @@ Check whether a certain address is banned
|
|||
|
||||
static qboolean SV_IsBanned(netadr_t *from, qboolean isexception)
|
||||
{
|
||||
int index, addrlen, curbyte, netmask, cmpmask;
|
||||
int index;
|
||||
serverBan_t *curban;
|
||||
byte *addrfrom, *addrban;
|
||||
qboolean differed;
|
||||
|
||||
if(from->type == NA_IP)
|
||||
addrlen = sizeof(from->ip);
|
||||
else if(from->type == NA_IP6)
|
||||
addrlen = sizeof(from->ip6);
|
||||
else
|
||||
return qfalse;
|
||||
|
||||
if(!isexception)
|
||||
{
|
||||
// If this is a query for a ban, first check whether the client is excepted
|
||||
|
@ -257,47 +248,10 @@ static qboolean SV_IsBanned(netadr_t *from, qboolean isexception)
|
|||
{
|
||||
curban = &serverBans[index];
|
||||
|
||||
if(curban->isexception == isexception && from->type == curban->ip.type)
|
||||
if(curban->isexception == isexception)
|
||||
{
|
||||
if(from->type == NA_IP)
|
||||
{
|
||||
addrfrom = from->ip;
|
||||
addrban = curban->ip.ip;
|
||||
}
|
||||
else
|
||||
{
|
||||
addrfrom = from->ip6;
|
||||
addrban = curban->ip.ip6;
|
||||
}
|
||||
|
||||
differed = qfalse;
|
||||
curbyte = 0;
|
||||
|
||||
for(netmask = curban->subnet; netmask > 7; netmask -= 8)
|
||||
{
|
||||
if(addrfrom[curbyte] != addrban[curbyte])
|
||||
{
|
||||
differed = qtrue;
|
||||
break;
|
||||
}
|
||||
|
||||
curbyte++;
|
||||
}
|
||||
|
||||
if(differed)
|
||||
continue;
|
||||
|
||||
if(netmask)
|
||||
{
|
||||
cmpmask = (1 << netmask) - 1;
|
||||
cmpmask <<= 8 - netmask;
|
||||
|
||||
if((addrfrom[curbyte] & cmpmask) == (addrban[curbyte] & cmpmask))
|
||||
return qtrue;
|
||||
}
|
||||
else
|
||||
if(NET_CompareBaseAdrMask(curban->ip, *from, curban->subnet))
|
||||
return qtrue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue