AntiSlotFill: initial commit

This commit is contained in:
hubdom 2020-06-03 13:27:49 +02:00
parent f7dc06a6e5
commit a91ad11ced

View File

@ -0,0 +1,56 @@
#include <sourcemod>
#include <connect>
char g_sIPs[MAXPLAYERS+1][32];
ConVar g_hCVar_MaximumConnectionsPerIP;
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
g_hCVar_MaximumConnectionsPerIP = CreateConVar("sm_max_connections_per_ip", "3", "", FCVAR_PROTECTED, true, 1.0);
AutoExecConfig(true);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public EConnect OnClientPreConnectEx(const char[] sName, char sPassword[255], const char[] sIP, const char[] sSteam32ID, char sRejectReason[255])
{
int iCount = 1;
for(int i = 1; i <= MaxClients; i++)
{
if (StrEqual(sIP, g_sIPs[i], false))
{
iCount++;
if (iCount > g_hCVar_MaximumConnectionsPerIP.IntValue)
{
LogAction(i, -1, "\"%L\" is using too many connections. (IP: %s)", i, sIP);
sRejectReason = "Too many connections from your IP";
return k_OnClientPreConnectEx_Reject;
}
}
}
return k_OnClientPreConnectEx_Accept;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientConnected(int client)
{
char sIP[32]
GetClientIP(client, sIP, sizeof(sIP));
g_sIPs[client] = sIP;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientDisconnect(int client)
{
g_sIPs[client] = "";
}