NoSteamManager: Rewrite anti-spoof mechanic into OnClientAuthorized.
This commit is contained in:
parent
7cd0eb9d05
commit
25a16ec5cd
@ -7,11 +7,12 @@
|
||||
#pragma newdecls required
|
||||
|
||||
/* CONVARS */
|
||||
ConVar g_hCvar_BlockSpoof;
|
||||
ConVar g_hCvar_BlockAdmin;
|
||||
ConVar g_hCvar_BlockVoice;
|
||||
|
||||
/* DATABASE */
|
||||
Database g_hDatabaseAntiSpoofing;
|
||||
Database g_hDatabase;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
@ -29,6 +30,7 @@ public Plugin myinfo =
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnPluginStart()
|
||||
{
|
||||
g_hCvar_BlockSpoof = CreateConVar("sm_nosteam_block_spoof", "1", "Kick nosteamers that use authenticated steamids.", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
g_hCvar_BlockAdmin = CreateConVar("sm_nosteam_block_admin", "1", "Should people marked as nosteam be blocked from admin?", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
g_hCvar_BlockVoice = CreateConVar("sm_nosteam_block_voice", "1", "Should people marked as nosteam be blocked from voice?", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
|
||||
@ -39,8 +41,17 @@ public void OnPluginStart()
|
||||
RegConsoleCmd("sm_steam", Command_DisplaySteamStats, "Shows the number of Steam and No-Steam players");
|
||||
|
||||
AutoExecConfig();
|
||||
}
|
||||
|
||||
Database.Connect(OnDatabaseConnect, "antispoofing");
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnConfigsExecuted()
|
||||
{
|
||||
if(!g_hCvar_BlockSpoof.BoolValue)
|
||||
return;
|
||||
|
||||
Database.Connect(SQL_OnDatabaseConnect, "NoSteamManager");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -52,24 +63,6 @@ public void OnPluginEnd()
|
||||
RemoveMultiTargetFilter("@nosteam", Filter_NoSteam);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
{
|
||||
if(db == INVALID_HANDLE || strlen(error) > 0)
|
||||
{
|
||||
LogError("Error connecting to database: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
g_hDatabaseAntiSpoofing = db;
|
||||
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS anti_spoofing (`steam_auth` varchar(64), `last_connection_type` varchar(64), `last_ip` varchar(64), `last_connect` int, PRIMARY KEY (`steam_auth`));");
|
||||
g_hDatabaseAntiSpoofing.Query(SQL_DoNothing, sQuery, DBPrio_High);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -134,6 +127,23 @@ public bool Filter_NoSteam(const char[] sPattern, Handle hClients)
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientAuthorized(int client, const char[] sAuthID)
|
||||
{
|
||||
if(!g_hCvar_BlockSpoof.BoolValue || !g_hDatabase)
|
||||
return;
|
||||
|
||||
if(IsFakeClient(client) || IsClientSourceTV(client))
|
||||
return;
|
||||
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM connections WHERE auth='%s'", sAuthID);
|
||||
|
||||
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, GetClientSerial(client), DBPrio_Low);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -145,32 +155,16 @@ public Action OnClientPreAdminCheck(int client)
|
||||
if(IsFakeClient(client) || IsClientSourceTV(client))
|
||||
return Plugin_Continue;
|
||||
|
||||
char sSteamID[32];
|
||||
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
|
||||
|
||||
if(!RevEmu_IsPlayerSteam(client))
|
||||
{
|
||||
char sConnectionType[32];
|
||||
RevEmu_GetPlayerType(client, sConnectionType, sizeof(sConnectionType));
|
||||
LogMessage("%L was not authenticated with steam (type: %s), denying admin.", client, sConnectionType);
|
||||
|
||||
LogMessage("%L has a illegitimate connection type: '%s', denying admin.", client, sConnectionType);
|
||||
NotifyPostAdminCheck(client);
|
||||
|
||||
if (g_hDatabaseAntiSpoofing == INVALID_HANDLE)
|
||||
return Plugin_Handled;
|
||||
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * from anti_spoofing WHERE steam_auth = '%s'", sSteamID);
|
||||
g_hDatabaseAntiSpoofing.Query(TQueryCB, sQuery, GetClientUserId(client));
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
if (g_hDatabaseAntiSpoofing == INVALID_HANDLE)
|
||||
return Plugin_Continue;
|
||||
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * from anti_spoofing WHERE steam_auth = '%s'", sSteamID);
|
||||
g_hDatabaseAntiSpoofing.Query(TQueryCB, sQuery, GetClientUserId(client));
|
||||
return Plugin_Continue;
|
||||
else return Plugin_Continue;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -186,7 +180,10 @@ public void OnClientPostAdminCheck(int client)
|
||||
|
||||
if(!RevEmu_IsPlayerSteam(client))
|
||||
{
|
||||
LogMessage("%L was not authenticated with steam, muting client.", client);
|
||||
char sConnectionType[32];
|
||||
RevEmu_GetPlayerType(client, sConnectionType, sizeof(sConnectionType));
|
||||
|
||||
LogMessage("%L has a illegitimate connection type: '%s', muting client.", client, sConnectionType);
|
||||
BaseComm_SetClientMute(client, true);
|
||||
return;
|
||||
}
|
||||
@ -195,71 +192,80 @@ public void OnClientPostAdminCheck(int client)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void TQueryCB(Database db, DBResultSet results, const char[] error, any data)
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
{
|
||||
int client = 0;
|
||||
|
||||
if ((client = GetClientOfUserId(data)) == 0)
|
||||
return;
|
||||
|
||||
if(db == INVALID_HANDLE || strlen(error) > 0)
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("SQL query errors: %s", error);
|
||||
LogError("Error connecting to database: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
char sSteamID[32];
|
||||
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
|
||||
g_hDatabase = db;
|
||||
|
||||
char sCurrentIP[32];
|
||||
GetClientIP(client, sCurrentIP, sizeof(sCurrentIP));
|
||||
|
||||
char sCurrentConnectionType[32];
|
||||
RevEmu_GetPlayerType(client, sCurrentConnectionType, sizeof(sCurrentConnectionType));
|
||||
|
||||
int iTimestamp = GetTime();
|
||||
|
||||
if (results.RowCount > 0)
|
||||
{
|
||||
char sLastIP[32];
|
||||
char sLastConnectionType[32];
|
||||
int iField;
|
||||
|
||||
results.FetchRow();
|
||||
|
||||
results.FieldNameToNum("last_ip", iField);
|
||||
results.FetchString(iField, sLastIP, sizeof(sLastIP));
|
||||
|
||||
results.FieldNameToNum("last_connection_type", iField);
|
||||
results.FetchString(iField, sLastConnectionType, sizeof(sLastConnectionType));
|
||||
|
||||
delete results;
|
||||
|
||||
if(!StrEqual(sCurrentConnectionType, sLastConnectionType, false) && StrEqual(sLastConnectionType, "SteamLegit", false))
|
||||
{
|
||||
if (StrEqual(sCurrentIP, sLastIP))
|
||||
LogMessage("%L tried to join with a known authenticated SteamID while not being authentiated with steam (type: %s). Allowing connection because IPs match (%s).", client, sCurrentConnectionType, sCurrentIP);
|
||||
else
|
||||
{
|
||||
LogMessage("%L tried to join with a known authenticated SteamID while not being authentiated with steam. Refusing connection because IPs do not match (Stored: %s)(Current: %s).", client, sLastIP, sCurrentIP);
|
||||
KickClient(client, "Trying to join with a known authenticated SteamID while not being authentiated with steam.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO anti_spoofing (steam_auth, last_connection_type, last_ip, last_connect) VALUES ('%s', '%s', '%s', %d) ON DUPLICATE KEY UPDATE last_connection_type = '%s', last_ip = '%s', last_connect = %d;", sSteamID, sCurrentConnectionType, sCurrentIP, iTimestamp, sCurrentConnectionType, sCurrentIP, iTimestamp);
|
||||
g_hDatabaseAntiSpoofing.Query(SQL_DoNothing, sQuery, GetClientUserId(client));
|
||||
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS connections (`auth` varchar(32), `type` varchar(32), `address` varchar(16), PRIMARY KEY (`auth`))");
|
||||
|
||||
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, _, DBPrio_High);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void SQL_DoNothing(Database db, DBResultSet results, const char[] error, any data)
|
||||
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if(db == INVALID_HANDLE || strlen(error) > 0)
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("SQL query errors: %s", error);
|
||||
LogError("Error connecting to database: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(data)) == 0)
|
||||
return;
|
||||
|
||||
char sAuthID[32];
|
||||
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID));
|
||||
|
||||
char sAddress[16];
|
||||
GetClientIP(client, sAddress, sizeof(sAddress));
|
||||
|
||||
char sConnectionType[32];
|
||||
RevEmu_GetPlayerType(client, sConnectionType, sizeof(sConnectionType));
|
||||
|
||||
if(results.RowCount && results.FetchRow())
|
||||
{
|
||||
int iFieldNum;
|
||||
char sResultAddress[16];
|
||||
char sResultConnectionType[32];
|
||||
|
||||
results.FieldNameToNum("address", iFieldNum);
|
||||
results.FetchString(iFieldNum, sResultAddress, sizeof(sResultAddress));
|
||||
|
||||
results.FieldNameToNum("type", iFieldNum);
|
||||
results.FetchString(iFieldNum, sResultConnectionType, sizeof(sResultConnectionType));
|
||||
|
||||
delete results;
|
||||
|
||||
if(!RevEmu_IsPlayerSteam(client))
|
||||
{
|
||||
if(!StrEqual(sConnectionType, sResultConnectionType, false) && StrEqual(sResultConnectionType, "SteamLegit", false))
|
||||
{
|
||||
if(StrEqual(sAddress, sResultAddress, false))
|
||||
{
|
||||
LogMessage("%L tried to join with a legitimate steamid while having a illegitimate connection type: '%s'. Allowing connection, IPs match. (Known: %s)", client, sConnectionType, sAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMessage("%L tried to join with a legitimate steamid while having a illegitimate connection type: '%s'. Refusing connection, IPs dont match. (Known: %s | Current: %s)", client, sConnectionType, sResultAddress, sAddress);
|
||||
KickClient(client, "Trying to join with a legitimate steamid while having a illegitimate connection.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO connections (auth, type, address) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE type='%s', address='%s';", sAuthID, sConnectionType, sAddress, sConnectionType, sAddress);
|
||||
|
||||
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, _, DBPrio_Low);
|
||||
}
|
Loading…
Reference in New Issue
Block a user