228 lines
7.1 KiB
SourcePawn
228 lines
7.1 KiB
SourcePawn
#pragma semicolon 1
|
|
|
|
#include <sourcemod>
|
|
#include <basecomm>
|
|
#include <connect>
|
|
|
|
#pragma newdecls required
|
|
|
|
/* CONVARS */
|
|
ConVar g_hCvar_BlockAdmin;
|
|
ConVar g_hCvar_BlockVoice;
|
|
|
|
/* DATABASE */
|
|
Database g_hDatabaseSB;
|
|
Database g_hDatabaseAntiSpoofing;
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
// Purpose:
|
|
//----------------------------------------------------------------------------------------------------
|
|
public Plugin myinfo =
|
|
{
|
|
name = "NoSteamManager",
|
|
author = "zaCade",
|
|
description = "Manage No-Steam clients, denying admin access, ect.",
|
|
version = "1.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();
|
|
|
|
char sError[256];
|
|
|
|
if (SQL_CheckConfig("sourcebans"))
|
|
g_hDatabaseSB = SQL_Connect("sourcebans", true, sError, sizeof(sError));
|
|
|
|
if (g_hDatabaseSB == null)
|
|
LogError("Could not connect to database: %s", sError);
|
|
|
|
if (SQL_CheckConfig("antispoofing"))
|
|
g_hDatabaseAntiSpoofing = SQL_Connect("antispoofing", true, sError, sizeof(sError));
|
|
|
|
if (g_hDatabaseAntiSpoofing == null)
|
|
LogError("Could not connect to database: %s", sError);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
// Purpose:
|
|
//----------------------------------------------------------------------------------------------------
|
|
public void OnPluginEnd()
|
|
{
|
|
RemoveMultiTargetFilter("@steam", Filter_Steam);
|
|
RemoveMultiTargetFilter("@nosteam", Filter_NoSteam);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
// 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))
|
|
{
|
|
char sSteamID[32];
|
|
GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID));
|
|
|
|
if(!SteamClientAuthenticated(sSteamID))
|
|
{
|
|
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 bool Filter_Steam(const char[] sPattern, Handle hClients)
|
|
{
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if(IsClientInGame(i) && !IsFakeClient(i))
|
|
{
|
|
char sSteamID[32];
|
|
GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID));
|
|
|
|
if(SteamClientAuthenticated(sSteamID))
|
|
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))
|
|
{
|
|
char sSteamID[32];
|
|
GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID));
|
|
|
|
if(!SteamClientAuthenticated(sSteamID))
|
|
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(!SteamClientAuthenticated(sSteamID))
|
|
{
|
|
LogMessage("%L was not authenticated with steam, denying admin.", client);
|
|
NotifyPostAdminCheck(client);
|
|
|
|
char sQuery[512];
|
|
Format(sQuery, sizeof(sQuery), "SELECT * from sb_admins WHERE authid = '%s'", sSteamID);
|
|
SQL_TQuery(g_hDatabaseSB, TQueryCB, sQuery, GetClientUserId(client));
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
else
|
|
{
|
|
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';", sSteamID, sIP, iTimestamp, sIP);
|
|
SQL_TQuery(g_hDatabaseAntiSpoofing, TQueryCB2, sQuery, GetClientUserId(client));
|
|
|
|
}
|
|
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
// Purpose:
|
|
//----------------------------------------------------------------------------------------------------
|
|
public void OnClientPostAdminCheck(int client)
|
|
{
|
|
if(!g_hCvar_BlockVoice.BoolValue)
|
|
return;
|
|
|
|
if(IsFakeClient(client) || IsClientSourceTV(client))
|
|
return;
|
|
|
|
char sSteamID[32];
|
|
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
|
|
|
|
if(!SteamClientAuthenticated(sSteamID))
|
|
{
|
|
LogMessage("%L was not authenticated with steam, muting client.", client);
|
|
BaseComm_SetClientMute(client, true);
|
|
return;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
// Purpose:
|
|
//----------------------------------------------------------------------------------------------------
|
|
public void TQueryCB(Handle owner, Handle rs, const char[] error, any data)
|
|
{
|
|
int client = 0;
|
|
|
|
if ((client = GetClientOfUserId(data)) == 0)
|
|
return;
|
|
|
|
if (SQL_GetRowCount(rs) > 0)
|
|
{
|
|
LogMessage("%L tried to join with an Admin-SteamID while not being authentiated with steam.", client);
|
|
KickClient(client, "Trying to join with an Admin-SteamID while not being authentiated with steam.");
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
// Purpose:
|
|
//----------------------------------------------------------------------------------------------------
|
|
public void TQueryCB2(Handle owner, Handle rs, const char[] error, any data)
|
|
{
|
|
|
|
}
|