Skip to content

Commit

Permalink
refactor: remove steam id storage and optimize client data handling (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rushaway authored Feb 11, 2025
1 parent aa78949 commit 0342581
Showing 1 changed file with 44 additions and 43 deletions.
87 changes: 44 additions & 43 deletions addons/sourcemod/scripting/FixVoiceDataExploit.sp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
ConVar g_cvMaxVoicePackets;
ConVar g_cvPunishement;

char g_sSteamIDs[MAXPLAYERS + 1][64];
char sPlayerIP[MAXPLAYERS + 1][32];

int g_voicePacketCount[MAXPLAYERS + 1];
int iPunishMent;
int iMaxVoicePackets;
Expand All @@ -21,15 +18,17 @@ bool g_Plugin_basebans = false;
bool g_Plugin_SourceBans = false;
bool g_Plugin_SourceComms = false;

public Plugin myinfo = {
public Plugin myinfo =
{
name = "Fix Voice Data Exploit",
author = "Ember, V1sual, Franc1sco Franug, .Rushaway",
description = "Block overflowing voice data to crash the server",
version = "1.5.1",
version = "1.5.2",
url = ""
};

public void OnPluginStart() {
public void OnPluginStart()
{
g_cvPunishement = CreateConVar("sm_fixvoicedataexploit_punishment", "1", "Punishment. 0 = Mute | 1 = Kick | 2 = Ban 5 mins", _, true, 0.0, true, 2.0);
g_cvMaxVoicePackets = CreateConVar("sm_fixvoicedataexploit_count", "92", "How many packets per second max?");

Expand All @@ -42,7 +41,8 @@ public void OnPluginStart() {
g_cvMaxVoicePackets.AddChangeHook(OnConVarHook);
}

public void OnAllPluginsLoaded() {
public void OnAllPluginsLoaded()
{
char filename[200];
BuildPath(Path_SM, filename, sizeof(filename), "plugins/basebans.smx");

Expand All @@ -51,55 +51,46 @@ public void OnAllPluginsLoaded() {
g_Plugin_SourceComms = LibraryExists("sourcecomms++");
}

public void OnLibraryAdded(const char[] sName) {
public void OnLibraryAdded(const char[] sName)
{
if (strcmp(sName, "sourcebans++", false) == 0)
g_Plugin_SourceBans = true;
if (strcmp(sName, "sourcecomms++", false) == 0)
else if (strcmp(sName, "sourcecomms++", false) == 0)
g_Plugin_SourceComms = true;
}

public void OnLibraryRemoved(const char[] sName) {
public void OnLibraryRemoved(const char[] sName)
{
if (strcmp(sName, "sourcebans++", false) == 0)
g_Plugin_SourceBans = false;
if (strcmp(sName, "sourcecomms++", false) == 0)
else if (strcmp(sName, "sourcecomms++", false) == 0)
g_Plugin_SourceComms = false;
}

public void OnConVarHook(ConVar cvar, const char[] oldVal, const char[] newVal) {
public void OnConVarHook(ConVar cvar, const char[] oldVal, const char[] newVal)
{
if (cvar == g_cvPunishement)
iPunishMent = cvar.IntValue;
else if (cvar == g_cvMaxVoicePackets)
iMaxVoicePackets = cvar.IntValue;
}

public void OnClientPutInServer(int client) {
char sSteamID[64];
GetClientAuthId(client, AuthId_Steam3, sSteamID, sizeof(sSteamID), false);
FormatEx(g_sSteamIDs[client], sizeof(g_sSteamIDs[]), "%s", sSteamID);

char sIP[32];
GetClientIP(client, sIP, sizeof(sIP));
FormatEx(sPlayerIP[client], sizeof(sPlayerIP[]), "%s", sIP);
}

public void OnClientDisconnect(int client) {
FormatEx(g_sSteamIDs[client], sizeof(g_sSteamIDs[]), "");
FormatEx(sPlayerIP[client], sizeof(sPlayerIP[]), "");
}

public void OnMapStart() {
public void OnMapStart()
{
CreateTimer(1.0, ResetCount, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public Action ResetCount(Handle timer) {
public Action ResetCount(Handle timer)
{
for (int i = 1; i <= MaxClients; i++) {
g_voicePacketCount[i] = 0;
}

return Plugin_Continue;
}

public void OnClientSpeaking(int client) {
public void OnClientSpeaking(int client)
{
if (!IsClientInGame(client))
return;

Expand All @@ -110,7 +101,11 @@ public void OnClientSpeaking(int client) {

g_voicePacketCount[client]++;

if (g_voicePacketCount[client] > iMaxVoicePackets) {
if (g_voicePacketCount[client] > iMaxVoicePackets)
{
char sPlayerIP[32];
GetClientIP(client, sPlayerIP, sizeof(sPlayerIP));

char sReason[128];
Format(sReason, sizeof(sReason), "Voice data overflow detected. (Total packets: %i)", g_voicePacketCount[client]);

Expand All @@ -123,36 +118,42 @@ public void OnClientSpeaking(int client) {
SourceComms_SetClientMute(client, true, 10, true, sReason);

char sPunishment[64];
switch (iPunishMent) {
case 0: {
switch (iPunishMent)
{
case 0:
strcopy(sPunishment, sizeof(sPunishment), "muted");
}
case 1: {
case 1:
{
strcopy(sPunishment, sizeof(sPunishment), "kicked");
if (IsClientConnected(client))
KickClient(client, sReason);
}
case 2: {
if (g_Plugin_basebans || g_Plugin_SourceBans) {
case 2:
{
if (g_Plugin_basebans || g_Plugin_SourceBans)
{
strcopy(sPunishment, sizeof(sPunishment), "banned");
ServerCommand("sm_ban #%d 5 %s", GetClientUserId(client), sReason);
} else {
}
else
{
strcopy(sPunishment, sizeof(sPunishment), "kicked (Can't perform ban, sbpp not loaded..)");
if (IsClientConnected(client))
KickClient(client, sReason);
}
}
}

LogAction(-1, -1, "%N (%s) was %s for trying to crash the server with voice data overflow. Total packets: %i",
client, g_sSteamIDs[client], sPunishment, g_voicePacketCount[client]);
LogAction(-1, -1, "%L was %s for trying to crash the server with voice data overflow. Total packets: %i",
client, sPunishment, g_voicePacketCount[client]);

LogToPluginFile("%N (%s | IP: %s) was %s for trying to crash the server with voice data overflow. Total packets: %i",
client, g_sSteamIDs[client], sPlayerIP[client], sPunishment, g_voicePacketCount[client]);
LogToPluginFile("%L (IP: %s) was %s for trying to crash the server with voice data overflow. Total packets: %i",
client, sPlayerIP, sPunishment, g_voicePacketCount[client]);
}
}

stock void LogToPluginFile(const char[] format, any ...) {
stock void LogToPluginFile(const char[] format, any ...)
{
char f_sBuffer[1024], f_sPath[1024];
VFormat(f_sBuffer, sizeof(f_sBuffer), format, 2);
BuildPath(Path_SM, f_sPath, sizeof(f_sPath), PATH);
Expand Down

0 comments on commit 0342581

Please sign in to comment.