Skip to content

Commit

Permalink
Improved behavior of sv_filterban 0. Fixes #1027
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed May 10, 2024
1 parent 47ffe4b commit 383d60a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
<li>sv_net_incoming_decompression_max_size <16|65536> // Sets the max allowed size for decompressed file transfer data. Default: 65536 bytes
<li>sv_net_incoming_decompression_punish // Time in minutes for which the player will be banned for malformed/abnormal bzip2 fragments (0 - Permanent, use a negative number for a kick). Default: -1
<li>sv_tags &lt;comma-delimited string list of tags&gt; // Sets a string defining the "gametags" for this server, this is optional, but if it is set it allows users/scripts to filter in the matchmaking/server-browser interfaces based on the value. Default: ""
<li>sv_filterban &lt;-1|0|1&gt;// Set packet filtering by IP mode. -1 - All players will be rejected without any exceptions. 0 - No checks will happen. 1 - All incoming players will be checked if they're IP banned (if they have an IP filter entry), if they are, they will be kicked. Default: 1
</ul>
</details>

Expand Down
14 changes: 11 additions & 3 deletions rehlds/engine/sv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3834,15 +3834,22 @@ void SV_ProcessFile(client_t *cl, char *filename)
Con_NetPrintf("Error parsing custom decal from %s\n", cl->name);
}

qboolean SV_FilterPacket(void)
qboolean SV_FilterPacket()
{
// sv_filterban filtering IP mode
// -1: all players will be rejected without any exceptions
// 0: no checks will happen
// 1: all incoming players will be checked if they're IP banned (if they have an IP filter entry), if they are, they will be kicked

qboolean bNegativeFilter = (sv_filterban.value == 1) ? TRUE : FALSE;

for (int i = numipfilters - 1; i >= 0; i--)
{
ipfilter_t* curFilter = &ipfilters[i];
if (curFilter->compare.u32 == 0xFFFFFFFF || curFilter->banEndTime == 0.0f || curFilter->banEndTime > realtime)
{
if ((*(uint32*)net_from.ip & curFilter->mask) == curFilter->compare.u32)
return (int)sv_filterban.value;
return bNegativeFilter;
}
else
{
Expand All @@ -3852,7 +3859,8 @@ qboolean SV_FilterPacket(void)
--numipfilters;
}
}
return sv_filterban.value == 0.0f;

return !bNegativeFilter;
}

void SV_SendBan(void)
Expand Down

0 comments on commit 383d60a

Please sign in to comment.