Skip to content

Commit

Permalink
backport antiFakePlayer to game module once again
Browse files Browse the repository at this point in the history
  • Loading branch information
Razish committed Feb 21, 2024
1 parent 69815e9 commit bf4eb9d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
25 changes: 20 additions & 5 deletions codemp/game/g_client.c
Expand Up @@ -2396,13 +2396,14 @@ restarts.
============
*/

static qboolean CompareIPs( const char *ip1, const char *ip2 )
{
while ( 1 ) {
if ( *ip1 != *ip2 )
static qboolean CompareIPs(const char *ip1, const char *ip2) {
while (1) {
if (*ip1 != *ip2) {
return qfalse;
if ( !*ip1 || *ip1 == ':' )
}
if (!*ip1 || *ip1 == ':') {
break;
}
ip1++;
ip2++;
}
Expand Down Expand Up @@ -2451,6 +2452,20 @@ char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot ) {
}
}

// check for >= g_maxConnPerIP connections from same IP
if (g_antiFakePlayer.integer && !isBot && firstTime) {
int count = 0, i = 0;
gclient_t *cl;
for (i = 0, cl = level.clients; i < sv_maxclients.integer; i++, cl++) {
if (cl->pers.connected >= CON_CONNECTING && CompareIPs(tmpIP, cl->sess.IP)) {
count++;
}
}
if (count >= g_maxConnPerIP.integer) {
return "Too many connections from the same IP";
}
}

if ( ent->inuse )
{// if a player reconnects quickly after a disconnect, the client disconnect may never be called, thus flag can get lost in the ether
G_LogPrintf( "Forcing disconnect on active client: %i\n", clientNum );
Expand Down
2 changes: 2 additions & 0 deletions codemp/game/g_xcvar.h
Expand Up @@ -71,6 +71,7 @@ XCVAR_DEF( g_allowHighPingDuelist, "1", NULL, CVAR_NONE, qtrue
XCVAR_DEF( g_allowNPC, "1", NULL, CVAR_CHEAT, qtrue )
XCVAR_DEF( g_allowTeamVote, "1", NULL, CVAR_ARCHIVE, qfalse )
XCVAR_DEF( g_allowVote, "-1", NULL, CVAR_ARCHIVE, qfalse )
XCVAR_DEF( g_antiFakePlayer, "0", NULL, CVAR_ARCHIVE, qfalse )
XCVAR_DEF( g_armBreakage, "0", NULL, CVAR_NONE, qtrue )
XCVAR_DEF( g_austrian, "0", NULL, CVAR_ARCHIVE, qfalse )
XCVAR_DEF( g_autoMapCycle, "0", NULL, CVAR_ARCHIVE|CVAR_NORESTART, qtrue )
Expand Down Expand Up @@ -114,6 +115,7 @@ XCVAR_DEF( g_locationBasedDamage, "1", NULL, CVAR_NONE, qtrue )
XCVAR_DEF( g_log, "games.log", NULL, CVAR_ARCHIVE, qfalse )
XCVAR_DEF( g_logClientInfo, "0", NULL, CVAR_ARCHIVE, qtrue )
XCVAR_DEF( g_logSync, "0", NULL, CVAR_ARCHIVE, qfalse )
XCVAR_DEF( g_maxConnPerIP, "3", NULL, CVAR_ARCHIVE, qfalse )
XCVAR_DEF( g_maxForceRank, "7", NULL, CVAR_SERVERINFO|CVAR_ARCHIVE|CVAR_LATCH, qfalse )
XCVAR_DEF( g_maxGameClients, "0", NULL, CVAR_SERVERINFO|CVAR_LATCH|CVAR_ARCHIVE, qfalse )
XCVAR_DEF( g_maxHolocronCarry, "3", NULL, CVAR_LATCH, qfalse )
Expand Down
2 changes: 1 addition & 1 deletion codemp/server/sv_client.cpp
Expand Up @@ -316,8 +316,8 @@ void SV_DirectConnect( netadr_t from ) {
// save the userinfo
Q_strncpyz( newcl->userinfo, userinfo, sizeof(newcl->userinfo) );

// check for >= sv_maxConnPerIP connections from same IP
if (sv_antiFakePlayer->integer) {
// check for > sv_maxConnPerIP connections from same IP
int count = 0, i = 0;
for (i = 0, cl = svs.clients; i < sv_maxclients->integer; i++, cl++) {
if (cl->state >= CS_CONNECTED && NET_CompareBaseAdr(svs.clients[clientNum].netchan.remoteAddress, svs.clients[i].netchan.remoteAddress)) {
Expand Down

0 comments on commit bf4eb9d

Please sign in to comment.