sm-plugins/NoSteamManager/scripting/NoSteamManager_RevEmu.sp
2019-02-24 18:04:00 +01:00

307 lines
10 KiB
SourcePawn

#pragma semicolon 1
#include <sourcemod>
#include <basecomm>
#include <RevEmuAPI>
#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");
RegAdminCmd("sm_usertype", Command_DisplayUserTypes, ADMFLAG_BAN, "Show the usertypes 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);
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:
//----------------------------------------------------------------------------------------------------
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(!RevEmu_IsPlayerSteam(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);
}
else
ReplyToCommand(client, "[SM] No-Steam clients online: none");
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Command_DisplayUserTypes(int client, int args)
{
PrintToConsole(client, "# %8s %40s %24s %12s %s",
"userid", "name", "uniqueid", "type", "steam");
for(int player = 1; player <= MaxClients; player++)
{
if(!IsClientConnected(player) || IsFakeClient(player))
continue;
char sPlayerID[8];
char sPlayerName[MAX_NAME_LENGTH + 2];
char sPlayerAuth[24];
char sPlayerType[64];
char sPlayerSteam[64];
FormatEx(sPlayerID, sizeof(sPlayerID), "%d", GetClientUserId(player));
FormatEx(sPlayerName, sizeof(sPlayerName), "\"%N\"", player);
if(!GetClientAuthId(player, AuthId_Steam2, sPlayerAuth, sizeof(sPlayerAuth)))
FormatEx(sPlayerAuth, sizeof(sPlayerAuth), "STEAM_ID_PENDING");
if(!RevEmu_GetPlayerType(player, sPlayerType, sizeof(sPlayerType)))
FormatEx(sPlayerType, sizeof(sPlayerType), "Invalid");
if (RevEmu_IsPlayerSteam(player))
FormatEx(sPlayerSteam, sizeof(sPlayerSteam), "Yes");
else
FormatEx(sPlayerSteam, sizeof(sPlayerSteam), "No");
PrintToConsole(client, "# %8s %40s %24s %12s %s",
sPlayerID, sPlayerName, sPlayerAuth, sPlayerType, sPlayerSteam);
}
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(RevEmu_IsPlayerSteam(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(!RevEmu_IsPlayerSteam(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(!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);
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(!RevEmu_IsPlayerSteam(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;
if(db == INVALID_HANDLE || strlen(error) > 0)
{
LogError("SQL query errors: %s", error);
return;
}
char sSteamID[32];
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
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));
}
//----------------------------------------------------------------------------------------------------
// 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);
return;
}
}