initial commit of ban detection project, still missing features and have to do more in regards to js
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
#pragma semicolon 1
|
||||
#define PLUGIN_AUTHOR "jenz"
|
||||
#define g_dLength 400
|
||||
#define PLUGIN_VERSION "1.0"
|
||||
#pragma newdecls required
|
||||
|
||||
#include <sourcemod>
|
||||
#include <clientprefs>
|
||||
#include <cstrike>
|
||||
#include <sdktools>
|
||||
|
||||
int validate_state [MAXPLAYERS + 1];
|
||||
Database g_dDatabase;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "jenz ban detector",
|
||||
author = PLUGIN_AUTHOR,
|
||||
description = "my ban detector maybe catches you",
|
||||
version = PLUGIN_VERSION,
|
||||
url = "www.unloze.com"
|
||||
};
|
||||
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
if (!g_dDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "jenz_ban_detector");
|
||||
}
|
||||
for (int i = 0; i < MaxClients; i++)
|
||||
{
|
||||
if (IsValidClient(i))
|
||||
{
|
||||
validate_state[i] = 0;
|
||||
}
|
||||
}
|
||||
CreateTimer(10.0, start_checks, _, TIMER_REPEAT);
|
||||
}
|
||||
|
||||
public void SQL_checkEntries(int client)
|
||||
{
|
||||
char sQuery[g_dLength];
|
||||
char sSID[MAX_NAME_LENGTH];
|
||||
char sIP[MAX_NAME_LENGTH];
|
||||
char sName[MAX_NAME_LENGTH];
|
||||
GetClientName(client, sName, sizeof(sName));
|
||||
int size2 = 2 * strlen(sName) + 1;
|
||||
char[] sEscapedName = new char[size2 + 1];
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
g_dDatabase.Escape(sName, sEscapedName, size2 + 1);
|
||||
GetClientIP(client, sIP, sizeof(sIP));
|
||||
|
||||
Format(sQuery, sizeof(sQuery), "UPDATE `ban_detector` SET steamid='%s', name='%s' WHERE ip='%s'; ", sSID, sEscapedName, sIP);
|
||||
//PrintToChatAll("sQuery: %s", sQuery);
|
||||
g_dDatabase.Query(SQL_UpdateEntry, sQuery, _, DBPrio_High);
|
||||
}
|
||||
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
g_dDatabase = db;
|
||||
}
|
||||
|
||||
public void SQL_UpdateEntry(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public Action start_checks(Handle hTimer)
|
||||
{
|
||||
if (!g_dDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "jenz_ban_detector");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < MaxClients; i++)
|
||||
{
|
||||
if (IsValidClient(i) && validate_state[i] == 0)
|
||||
{
|
||||
validate_state[i] = -1;
|
||||
SQL_checkEntries(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
validate_state[client] = -1;
|
||||
}
|
||||
|
||||
public void OnClientPostAdminCheck(int client)
|
||||
{
|
||||
validate_state[client] = -1;
|
||||
CreateTimer(10.0, make_db_entry, client);
|
||||
}
|
||||
|
||||
public Action make_db_entry(Handle hTimer, int client)
|
||||
{
|
||||
if (IsValidClient(client))
|
||||
{
|
||||
validate_state[client] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
stock bool IsValidClient(int client)
|
||||
{
|
||||
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user