BlockNosteamBhop: overall improvements including asynchronous mysql calls to prevent server freezes and proper velocity blocking
This commit is contained in:
parent
a213549293
commit
9605db094d
172
BlockNosteamBhop/scripting/BlockNosteamBhop.sp
Normal file
172
BlockNosteamBhop/scripting/BlockNosteamBhop.sp
Normal file
@ -0,0 +1,172 @@
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
#include <PlayerManager>
|
||||
|
||||
#define PLUGIN_AUTHOR "jenz"
|
||||
#define PLUGIN_VERSION "1.1"
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "nosteam bhop blocker",
|
||||
author = PLUGIN_AUTHOR,
|
||||
description = "no more bhop for meatbags ",
|
||||
version = PLUGIN_VERSION,
|
||||
url = ""
|
||||
};
|
||||
|
||||
bool bhop_restricted_nosteamer[MAXPLAYERS + 1];
|
||||
int buttons_old[MAXPLAYERS + 1];
|
||||
int flags_old[MAXPLAYERS + 1];
|
||||
|
||||
Database g_hDatabase;
|
||||
|
||||
ConVar g_hCvar_TriggerVelocity;
|
||||
ConVar g_hCvar_SlowedVelocity;
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
g_hCvar_TriggerVelocity = CreateConVar("sm_nosteam_bhop_trigger_velocity", "320", "Horizontal velocity at which nosteamers will be slowed during bhop.", FCVAR_NONE, true, 0.0);
|
||||
g_hCvar_SlowedVelocity = CreateConVar("sm_nosteam_bhop_slowed_velocity", "200", "Horizontal velocity which nosteamers will be slowed to.", FCVAR_NONE, true, 0.0);
|
||||
|
||||
AutoExecConfig();
|
||||
}
|
||||
|
||||
public void OnConfigsExecuted()
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "bhopnosteam");
|
||||
}
|
||||
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
g_hDatabase = db;
|
||||
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS bhop_whitelist (`steam_auth` VARCHAR(32) NOT NULL, `name` VARCHAR(64) NOT NULL, PRIMARY KEY (`steam_auth`))");
|
||||
|
||||
g_hDatabase.Query(SQL_OnConnectFinished, sQuery, _, DBPrio_High);
|
||||
}
|
||||
|
||||
public void SQL_OnConnectFinished(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if (IsClientConnected(i) && IsClientAuthorized(i))
|
||||
{
|
||||
char sAuthID[32];
|
||||
GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID));
|
||||
OnClientAuthorized(i, sAuthID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientAuthorized(int client, const char[] sAuthID)
|
||||
{
|
||||
if (!IsFakeClient(client) && !IsClientSourceTV(client) && !PM_IsPlayerSteam(client))
|
||||
{
|
||||
bhop_restricted_nosteamer[client] = true;
|
||||
buttons_old[client] = 0;
|
||||
flags_old[client] = 0;
|
||||
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM bhop_whitelist WHERE steam_auth = '%s'", sAuthID);
|
||||
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, GetClientSerial(client));
|
||||
}
|
||||
else
|
||||
bhop_restricted_nosteamer[client] = false;
|
||||
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(data)) == 0)
|
||||
return;
|
||||
|
||||
if (results.RowCount && results.FetchRow())
|
||||
{
|
||||
int iFieldNum;
|
||||
results.FieldNameToNum("name", iFieldNum);
|
||||
char sName[MAX_NAME_LENGTH];
|
||||
results.FetchString(iFieldNum, sName, sizeof(sName));
|
||||
|
||||
bhop_restricted_nosteamer[client] = false;
|
||||
LogMessage("%L was found as \'%s\' on the whitelist and therefore will be allowed to bhop", client, sName);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
bhop_restricted_nosteamer[client] = false;
|
||||
buttons_old[client] = 0;
|
||||
flags_old[client] = 0;
|
||||
}
|
||||
|
||||
public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype,
|
||||
int cmdnum, int tickcount, int seed, const int mouse[2])
|
||||
{
|
||||
if (!IsValidClient(client) || !IsPlayerAlive(client) || !bhop_restricted_nosteamer[client]) return;
|
||||
if (!(buttons_old[client] & IN_JUMP) && (!(buttons & IN_JUMP)))
|
||||
{
|
||||
flags_old[client] = GetEntityFlags(client);
|
||||
return;
|
||||
}
|
||||
if (buttons_old[client] & IN_JUMP)
|
||||
{
|
||||
if (!(buttons & IN_JUMP))
|
||||
if (GetEntityFlags(client) & FL_ONGROUND)
|
||||
buttons_old[client] = buttons;
|
||||
return;
|
||||
}
|
||||
if (!(flags_old[client] & FL_ONGROUND))
|
||||
return;
|
||||
|
||||
float vVel[3];
|
||||
GetEntPropVector(client, Prop_Data, "m_vecVelocity", vVel);
|
||||
float fVelocity = SquareRoot(Pow(vVel[0], 2.0) + Pow(vVel[1], 2.0));
|
||||
|
||||
if (fVelocity > g_hCvar_TriggerVelocity.FloatValue)
|
||||
{
|
||||
float fNormalized[3];
|
||||
fNormalized[0] = vVel[0] / fVelocity;
|
||||
fNormalized[1] = vVel[1] / fVelocity;
|
||||
fNormalized[2] = 0.0;
|
||||
|
||||
float fTargetVelocity = g_hCvar_SlowedVelocity.FloatValue;
|
||||
float fFinal[3];
|
||||
fFinal[0] = fNormalized[0] * fTargetVelocity;
|
||||
fFinal[1] = fNormalized[1] * fTargetVelocity;
|
||||
fFinal[2] = vVel[2];
|
||||
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, fFinal);
|
||||
}
|
||||
|
||||
buttons_old[client] = buttons;
|
||||
}
|
||||
|
||||
stock int IsValidClient(int client, bool nobots = true)
|
||||
{
|
||||
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
|
||||
return false;
|
||||
|
||||
return IsClientInGame(client);
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
#include <PlayerManager>
|
||||
#pragma semicolon 1
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#define PLUGIN_AUTHOR "jenz"
|
||||
#define PLUGIN_VERSION "1.0"
|
||||
#define generic_length 256
|
||||
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "nosteam bhop blocker",
|
||||
author = PLUGIN_AUTHOR,
|
||||
description = "no more bhop for meatbags ",
|
||||
version = PLUGIN_VERSION,
|
||||
url = ""
|
||||
};
|
||||
|
||||
bool bhop_restricted_nosteamer[MAXPLAYERS + 1];
|
||||
int buttons_old[MAXPLAYERS + 1];
|
||||
int flags_old[MAXPLAYERS + 1];
|
||||
Database g_dDatabase;
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
SQL_StartConnection();
|
||||
for (int i = 1; i <= MAXPLAYERS; i++)
|
||||
{
|
||||
if (IsValidClient(i))
|
||||
OnClientPostAdminCheck(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
SQL_StartConnection();
|
||||
}
|
||||
|
||||
public void SQL_StartConnection()
|
||||
{
|
||||
char error[512];
|
||||
if (SQL_CheckConfig("bhopnosteam"))
|
||||
g_dDatabase = SQL_Connect("bhopnosteam", true, error, sizeof(error));
|
||||
if (g_dDatabase == null)
|
||||
{
|
||||
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to MYSQL-DB!");
|
||||
}
|
||||
//create table
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS bhop_whitelist (`steam_auth` VARCHAR(254) NOT NULL, `name` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_auth`))");
|
||||
SQL_TQuery(g_dDatabase, DummyCallbackSimple, sQuery);
|
||||
}
|
||||
|
||||
public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)
|
||||
{
|
||||
if (hOwner == null || hChild == null)
|
||||
LogError("Query error. (%s)", err);
|
||||
}
|
||||
|
||||
stock bool IsValidClient(int client)
|
||||
{
|
||||
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
bhop_restricted_nosteamer[client] = false;
|
||||
buttons_old[client] = 0;
|
||||
flags_old[client] = 0;
|
||||
}
|
||||
|
||||
public void OnClientPostAdminCheck(int client)
|
||||
{
|
||||
if (!IsFakeClient(client) && !IsClientSourceTV(client) && !PM_IsPlayerSteam(client))
|
||||
{
|
||||
bhop_restricted_nosteamer[client] = true;
|
||||
buttons_old[client] = 0;
|
||||
flags_old[client] = 0;
|
||||
if (g_dDatabase)
|
||||
{
|
||||
DBResultSet rs;
|
||||
char steam_auth[512];
|
||||
GetClientAuthId(client, AuthId_Steam2, steam_auth, sizeof(steam_auth));
|
||||
strcopy(steam_auth, sizeof(steam_auth), steam_auth[8]);
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM bhop_whitelist WHERE steam_auth = '%s'", steam_auth);
|
||||
if ((rs = SQL_Query(g_dDatabase, sQuery)) != null)
|
||||
{
|
||||
rs.FetchRow();
|
||||
if (rs.RowCount > 0)
|
||||
{
|
||||
bhop_restricted_nosteamer[client] = false;
|
||||
PrintToChat(client, "bhop unrestricted!");
|
||||
}
|
||||
}
|
||||
delete rs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype,
|
||||
int cmdnum, int tickcount, int seed, const int mouse[2])
|
||||
{
|
||||
if (!IsValidClient(client) || !IsPlayerAlive(client) || !bhop_restricted_nosteamer[client]) return;
|
||||
if (!(buttons_old[client] & IN_JUMP) && (!(buttons & IN_JUMP)))
|
||||
{
|
||||
flags_old[client] = GetEntityFlags(client);
|
||||
return;
|
||||
}
|
||||
if (buttons_old[client] & IN_JUMP)
|
||||
{
|
||||
if (!(buttons & IN_JUMP))
|
||||
if (GetEntityFlags(client) & FL_ONGROUND)
|
||||
buttons_old[client] = buttons;
|
||||
return;
|
||||
}
|
||||
if (!(flags_old[client] & FL_ONGROUND))
|
||||
return;
|
||||
float vVel[3];
|
||||
GetEntPropVector(client, Prop_Data, "m_vecVelocity", vVel);
|
||||
float fVelocity = SquareRoot(Pow(vVel[0], 2.0) + Pow(vVel[1], 2.0));
|
||||
float velocity_block[3];
|
||||
velocity_block[0] = vel[0];
|
||||
velocity_block[1] = vel[1];
|
||||
velocity_block[2] = vel[2];
|
||||
velocity_block[1] = 0.0;
|
||||
if (fVelocity > 320.0)
|
||||
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, velocity_block);
|
||||
buttons_old[client] = buttons;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user