NoSteamManager: Connect version. Untested.

Pretty similiar to RevEmu version anyway.
This commit is contained in:
zaCade 2019-03-05 19:23:37 +01:00
parent 25a16ec5cd
commit 3f11595ea3

View File

@ -7,21 +7,22 @@
#pragma newdecls required #pragma newdecls required
/* CONVARS */ /* CONVARS */
ConVar g_hCvar_BlockSpoof;
ConVar g_hCvar_BlockAdmin; ConVar g_hCvar_BlockAdmin;
ConVar g_hCvar_BlockVoice; ConVar g_hCvar_BlockVoice;
/* DATABASE */ /* DATABASE */
Database g_hDatabaseAntiSpoofing; Database g_hDatabase;
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Plugin myinfo = public Plugin myinfo =
{ {
name = "NoSteamManager", name = "NoSteamManager_Connect",
author = "zaCade", author = "zaCade + Neon",
description = "Manage No-Steam clients, denying admin access, ect.", description = "Manage No-Steam clients, denying admin access, ect.",
version = "1.1.0" version = "2.0.0"
}; };
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -29,6 +30,7 @@ public Plugin myinfo =
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnPluginStart() 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_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); 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,13 +41,17 @@ public void OnPluginStart()
RegConsoleCmd("sm_steam", Command_DisplaySteamStats, "Shows the number of Steam and No-Steam players"); RegConsoleCmd("sm_steam", Command_DisplaySteamStats, "Shows the number of Steam and No-Steam players");
AutoExecConfig(); AutoExecConfig();
}
char sError[256]; //----------------------------------------------------------------------------------------------------
if (SQL_CheckConfig("antispoofing")) // Purpose:
g_hDatabaseAntiSpoofing = SQL_Connect("antispoofing", true, sError, sizeof(sError)); //----------------------------------------------------------------------------------------------------
public void OnConfigsExecuted()
{
if(!g_hCvar_BlockSpoof.BoolValue)
return;
if (g_hDatabaseAntiSpoofing == null) Database.Connect(SQL_OnDatabaseConnect, "NoSteamManager");
LogError("Could not connect to database: %s", sError);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -69,10 +75,10 @@ public Action Command_DisplaySteamStats(int client, int args)
{ {
if(IsClientInGame(i) && !IsFakeClient(i)) if(IsClientInGame(i) && !IsFakeClient(i))
{ {
char sSteamID[32]; char sAuthID[32];
GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID)); GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID));
if(!SteamClientAuthenticated(sSteamID)) if(!SteamClientAuthenticated(sAuthID))
{ {
GetClientName(i, aBuf2, sizeof(aBuf2)); GetClientName(i, aBuf2, sizeof(aBuf2));
StrCat(aBuf, sizeof(aBuf), aBuf2); StrCat(aBuf, sizeof(aBuf), aBuf2);
@ -101,10 +107,10 @@ public bool Filter_Steam(const char[] sPattern, Handle hClients)
{ {
if(IsClientInGame(i) && !IsFakeClient(i)) if(IsClientInGame(i) && !IsFakeClient(i))
{ {
char sSteamID[32]; char sAuthID[32];
GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID)); GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID));
if(SteamClientAuthenticated(sSteamID)) if(SteamClientAuthenticated(sAuthID))
PushArrayCell(hClients, i); PushArrayCell(hClients, i);
} }
} }
@ -120,16 +126,33 @@ public bool Filter_NoSteam(const char[] sPattern, Handle hClients)
{ {
if(IsClientInGame(i) && !IsFakeClient(i)) if(IsClientInGame(i) && !IsFakeClient(i))
{ {
char sSteamID[32]; char sAuthID[32];
GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID)); GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID));
if(!SteamClientAuthenticated(sSteamID)) if(!SteamClientAuthenticated(sAuthID))
PushArrayCell(hClients, i); PushArrayCell(hClients, i);
} }
} }
return true; 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: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -141,30 +164,16 @@ public Action OnClientPreAdminCheck(int client)
if(IsFakeClient(client) || IsClientSourceTV(client)) if(IsFakeClient(client) || IsClientSourceTV(client))
return Plugin_Continue; return Plugin_Continue;
char sSteamID[32]; char sAuthID[32];
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID));
if(!SteamClientAuthenticated(sSteamID)) if(!SteamClientAuthenticated(sAuthID))
{ {
LogMessage("%L was not authenticated with steam, denying admin.", client); LogMessage("%L was not authenticated with steam, denying admin.", client);
NotifyPostAdminCheck(client); NotifyPostAdminCheck(client);
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT * from authenticated_steam_ids WHERE steam_auth = '%s'", sSteamID);
SQL_TQuery(g_hDatabaseAntiSpoofing, TQueryCB, sQuery, GetClientUserId(client));
return Plugin_Handled; return Plugin_Handled;
} }
else return Plugin_Continue;
char sIP[32];
GetClientIP(client, sIP, sizeof(sIP));
int iTimestamp = GetTime();
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT INTO authenticated_steam_ids (steam_auth, last_ip, last_connect) VALUES ('%s', '%s', %d) ON DUPLICATE KEY UPDATE last_ip = '%s', last_connect = %d;", sSteamID, sIP, iTimestamp, sIP, iTimestamp);
SQL_FastQuery(g_hDatabaseAntiSpoofing, sQuery);
return Plugin_Continue;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -178,10 +187,10 @@ public void OnClientPostAdminCheck(int client)
if(IsFakeClient(client) || IsClientSourceTV(client)) if(IsFakeClient(client) || IsClientSourceTV(client))
return; return;
char sSteamID[32]; char sAuthID[32];
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID));
if(!SteamClientAuthenticated(sSteamID)) if(!SteamClientAuthenticated(sAuthID))
{ {
LogMessage("%L was not authenticated with steam, muting client.", client); LogMessage("%L was not authenticated with steam, muting client.", client);
BaseComm_SetClientMute(client, true); BaseComm_SetClientMute(client, true);
@ -192,35 +201,70 @@ public void OnClientPostAdminCheck(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void TQueryCB(Handle owner, Handle rs, const char[] error, any data) public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
{ {
int client = 0; if(!db || strlen(error))
{
LogError("Error connecting to database: %s", error);
return;
}
if ((client = GetClientOfUserId(data)) == 0) g_hDatabase = db;
char sQuery[512];
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_OnQueryCompleted(Database db, DBResultSet results, const char[] error, any data)
{
if(!db || strlen(error))
{
LogError("Error connecting to database: %s", error);
return;
}
int client;
if ((client = GetClientFromSerial(data)) == 0)
return; return;
if (SQL_GetRowCount(rs) > 0) char sAuthID[32];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID));
char sAddress[16];
GetClientIP(client, sAddress, sizeof(sAddress));
if(results.RowCount && results.FetchRow())
{ {
char sCurrentIP[32]; int iFieldNum;
GetClientIP(client, sCurrentIP, sizeof(sCurrentIP)); char sResultAddress[16];
char sStoredIP[32]; results.FieldNameToNum("address", iFieldNum);
int iField; results.FetchString(iFieldNum, sResultAddress, sizeof(sResultAddress));
SQL_FetchRow(rs); delete results;
SQL_FieldNameToNum(rs, "last_ip", iField);
SQL_FetchString(rs, iField, sStoredIP, sizeof(sStoredIP));
delete rs;
if (StrEqual(sCurrentIP, sStoredIP)) if(!SteamClientAuthenticated(sAuthID))
{ {
LogMessage("%L tried to join with a known authenticated SteamID while not being authentiated with steam. Allowing connection because IPs match (%s).", client, sCurrentIP); if(StrEqual(sAddress, sResultAddress, false))
{
} LogMessage("%L tried to join with a legitimate steamid while not authenticated with steam. Allowing connection, IPs match. (Known: %s)", client, sAddress);
else }
{ 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, sStoredIP, sCurrentIP); {
KickClient(client, "Trying to join with a known authenticated SteamID while not being authentiated with steam."); LogMessage("%L tried to join with a legitimate steamid while not authenticated with steam. Refusing connection, IPs dont match. (Known: %s | Current: %s)", client, sResultAddress, sAddress);
KickClient(client, "Trying to join with a legitimate steamid while not authenticated with steam.");
return;
}
} }
} }
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT INTO connections (auth, address) VALUES ('%s', '%s') ON DUPLICATE KEY UPDATE address='%s';", sAuthID, sAddress, sAddress);
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, _, DBPrio_Low);
} }