This commit is contained in:
zaCade 2019-02-20 13:12:16 +01:00
commit b8b460b6a7
3 changed files with 470 additions and 0 deletions

View File

@ -0,0 +1,82 @@
#pragma semicolon 1
#include <sourcemod>
#include <No_Steam_Info>
#pragma newdecls required
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = "NoSteamManagerFailSafe_RevEmu",
author = "Neon",
description = "FailSafe to prevent No-Steam clients from getting admin access.",
version = "1.0.0"
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientPostAdminCheck(int client)
{
if(IsFakeClient(client) || IsClientSourceTV(client))
return;
if(!CheckCommandAccess(client, "sm_admin", ADMFLAG_GENERIC, true))
return;
if(!IsSteam(client))
{
char sConnectionType[32];
GetConnectionType(client, sConnectionType, sizeof(sConnectionType));
LogMessage("%L got admin access while not being authentiated with steam (type: %s). Attempting to kick.", sConnectionType);
LogAction(client, -1, "\"%L\"got admin access while not being authentiated with steam (type: %s). Attempting to kick.", sConnectionType);
KickClient(client, "Security Validation failed. Please contact an Administrator.");
return;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void GetConnectionType(int client, char[] sConnectionType, int iMaxLength)
{
char sConnectionTypeInternal[32];
RevEmu_PlayerType PlayerType = RevEmu_GetPlayerType(client);
if (PlayerType == ErrorGet)
sConnectionTypeInternal = "Error";
else if (PlayerType == SteamLegitUser)
sConnectionTypeInternal = "SteamLegit";
else if (PlayerType == SteamCrackedUser)
sConnectionTypeInternal = "SteamCracked";
else if (PlayerType == RevEmuUser)
sConnectionTypeInternal = "RevEmu";
else if (PlayerType == RevEmuUserOld)
sConnectionTypeInternal = "RevEmuOld";
else if (PlayerType == SettiSRCScanBot)
sConnectionTypeInternal = "SettiSRCScanBot";
else if (PlayerType == RevEmuUserV74)
sConnectionTypeInternal = "RevEmuV74";
else if (PlayerType == RevEmuUserVeryOld)
sConnectionTypeInternal = "RevEmuVeryOld";
else if (PlayerType == UnknownUser)
sConnectionTypeInternal = "Unknown";
else if (PlayerType == Steam2Legit)
sConnectionTypeInternal = "Steam2Legit";
else if (PlayerType == Steam2Cracked)
sConnectionTypeInternal = "Steam2Cracked";
strcopy(sConnectionType, iMaxLength, sConnectionTypeInternal);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public bool IsSteam(int client)
{
return (RevEmu_GetPlayerType(client) == SteamLegitUser);
}

View File

@ -0,0 +1,323 @@
#pragma semicolon 1
#include <sourcemod>
#include <basecomm>
#include <No_Steam_Info>
#pragma newdecls required
/* CONVARS */
ConVar g_hCvar_BlockAdmin;
ConVar g_hCvar_BlockVoice;
/* DATABASE */
Database g_hDatabaseAntiSpoofing;
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = "NoSteamManager_RevEmu",
author = "zaCade + Neon",
description = "Manage No-Steam clients, denying admin access, ect.",
version = "2.0.0"
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
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);
AddMultiTargetFilter("@steam", Filter_Steam, "Steam Players", false);
AddMultiTargetFilter("@nosteam", Filter_NoSteam, "No-Steam Players", false);
RegConsoleCmd("sm_nosteam", 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();
Database.Connect(OnDatabaseConnect, "antispoofing");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginEnd()
{
RemoveMultiTargetFilter("@steam", Filter_Steam);
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);
SetFailState("Error connecting to database. Reconnecting on map change.");
}
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:
//----------------------------------------------------------------------------------------------------
public Action Command_DisplaySteamStats(int client, int args)
{
char aBuf[1024];
char aBuf2[MAX_NAME_LENGTH];
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
if(!IsSteam(i))
{
GetClientName(i, aBuf2, sizeof(aBuf2));
StrCat(aBuf, sizeof(aBuf), aBuf2);
StrCat(aBuf, sizeof(aBuf), ", ");
}
}
}
if(strlen(aBuf))
{
aBuf[strlen(aBuf) - 2] = 0;
ReplyToCommand(client, "[SM] No-Steam clients online: %s", aBuf);
if(CheckCommandAccess(client, "sm_rcon", ADMFLAG_RCON, false))
{
aBuf = "##################################################\n";
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i) && !IsSteam(i))
{
char sConnectionType[32];
GetConnectionType(i, sConnectionType, sizeof(sConnectionType));
Format(aBuf, sizeof(aBuf), "%s%L %s \n", aBuf, i, sConnectionType);
}
}
Format(aBuf, sizeof(aBuf), "%s##################################################", aBuf);
if(client)
{
ReplyToCommand(client, "Check Console for additional information.");
PrintToConsole(client, aBuf);
}
else
ReplyToCommand(client, aBuf);
}
}
else
ReplyToCommand(client, "[SM] No-Steam clients online: none");
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public bool Filter_Steam(const char[] sPattern, Handle hClients)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
if(IsSteam(i))
PushArrayCell(hClients, i);
}
}
return true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public bool Filter_NoSteam(const char[] sPattern, Handle hClients)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
if(!IsSteam(i))
PushArrayCell(hClients, i);
}
}
return true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnClientPreAdminCheck(int client)
{
if(!g_hCvar_BlockAdmin.BoolValue)
return Plugin_Continue;
if(IsFakeClient(client) || IsClientSourceTV(client))
return Plugin_Continue;
char sSteamID[32];
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
if(!IsSteam(client))
{
char sConnectionType[32];
GetConnectionType(client, sConnectionType, sizeof(sConnectionType));
LogMessage("%L was not authenticated with steam (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;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientPostAdminCheck(int client)
{
if(!g_hCvar_BlockVoice.BoolValue)
return;
if(IsFakeClient(client) || IsClientSourceTV(client))
return;
if(!IsSteam(client))
{
LogMessage("%L was not authenticated with steam, muting client.", client);
BaseComm_SetClientMute(client, true);
return;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void TQueryCB(Database db, DBResultSet results, const char[] error, any data)
{
int client = 0;
if ((client = GetClientOfUserId(data)) == 0)
return;
char sSteamID[32];
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
char sCurrentIP[32];
GetClientIP(client, sCurrentIP, sizeof(sCurrentIP));
char sCurrentConnectionType[32];
GetConnectionType(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));
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void GetConnectionType(int client, char[] sConnectionType, int iMaxLength)
{
char sConnectionTypeInternal[32];
RevEmu_PlayerType PlayerType = RevEmu_GetPlayerType(client);
if (PlayerType == ErrorGet)
sConnectionTypeInternal = "Error";
else if (PlayerType == SteamLegitUser)
sConnectionTypeInternal = "SteamLegit";
else if (PlayerType == SteamCrackedUser)
sConnectionTypeInternal = "SteamCracked";
else if (PlayerType == RevEmuUser)
sConnectionTypeInternal = "RevEmu";
else if (PlayerType == RevEmuUserOld)
sConnectionTypeInternal = "RevEmuOld";
else if (PlayerType == SettiSRCScanBot)
sConnectionTypeInternal = "SettiSRCScanBot";
else if (PlayerType == RevEmuUserV74)
sConnectionTypeInternal = "RevEmuV74";
else if (PlayerType == RevEmuUserVeryOld)
sConnectionTypeInternal = "RevEmuVeryOld";
else if (PlayerType == UnknownUser)
sConnectionTypeInternal = "Unknown";
else if (PlayerType == Steam2Legit)
sConnectionTypeInternal = "Steam2Legit";
else if (PlayerType == Steam2Cracked)
sConnectionTypeInternal = "Steam2Cracked";
strcopy(sConnectionType, iMaxLength, sConnectionTypeInternal);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public bool IsSteam(int client)
{
return (RevEmu_GetPlayerType(client) == SteamLegitUser);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void SQL_DoNothing(Database db, DBResultSet results, const char[] error, any data)
{
if(db == INVALID_HANDLE || strlen(error) > 0)
{
LogError("SQL query errors: %s", error);
SetFailState("Lost connection to database. Reconnecting on map change.");
}
}

View File

@ -0,0 +1,65 @@
#if defined _No_Steam_Info_included
#endinput
#endif
#define _No_Steam_Info_included
enum RevEmu_PlayerType
{
ErrorGet = -1, //Failed determine PlayerType
SteamLegitUser = 0,
SteamCrackedUser,
RevEmuUser,
RevEmuUserOld,
SettiSRCScanBot,
RevEmuUserV74,
RevEmuUserVeryOld,
UnknownUser,
Steam2Legit,
Steam2Cracked
};
/**
* Checking if player is no-steam.
* @param iClient Index player.
* -
* @return True if no-steam.
* -
* @error Invalid player index or player not in game or player is a bot.
*/
#pragma deprecated Use RevEmu_GetPlayerType instead
native bool IsPlayerNoSteam(int iClient);
/**
* Get the type of player
* @param iClient Index player.
* -
* @return Returns RevEmu_PlayerType value.
* -
* @error Invalid player index or player not in game or player is bot.
*/
native RevEmu_PlayerType RevEmu_GetPlayerType(int iClient);
public Extension __ext_No_Steam_Info =
{
name = "No_Steam_Info",
file = "No_Steam_Info.ext",
#if defined AUTOLOAD_EXTENSIONS
autoload = 1,
#else
autoload = 0,
#endif
#if defined REQUIRE_EXTENSIONS
required = 1,
#else
required = 0,
#endif
};
#if !defined REQUIRE_EXTENSIONS
public __ext_No_Steam_Info_SetNTVOptional()
{
MarkNativeAsOptional("IsPlayerNoSteam");
MarkNativeAsOptional("RevEmu_GetPlayerType");
}
#endif