[Radiomute] Added scuffed timed mutes
This commit is contained in:
parent
484430cd50
commit
4f57a8957c
@ -1,23 +1,38 @@
|
||||
#pragma semicolon 1
|
||||
|
||||
//Yes, this should be a convar. No, I cant be bothered to do the convar hooks.
|
||||
#define DEFAULT_BAN 60
|
||||
|
||||
#include <sourcemod>
|
||||
#include <clientprefs>
|
||||
|
||||
#pragma newdecls required
|
||||
|
||||
bool g_bLateLoad = false;
|
||||
bool g_bProtoBuf;
|
||||
bool g_bBlocked[MAXPLAYERS + 1];
|
||||
|
||||
int g_iBanTime[MAXPLAYERS + 1]; //CAREFUL! 0 ON THIS VARIABLE MEANS NOT BANNED, BUT 0 FROM COOKIE OUTPUT IS AN ERROR!
|
||||
Cookie g_CookieBanTime = null;
|
||||
|
||||
//bool g_bBlocked[MAXPLAYERS + 1];
|
||||
|
||||
int g_iMessageClient = -1;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "RadioMute",
|
||||
description = "Very simple plugin to block players from using the in-game radio in supported games.",
|
||||
author = "Obus",
|
||||
version = "1.0.1",
|
||||
description = "(No longer that) Very simple plugin to block players from using the in-game radio in supported games.",
|
||||
author = "Obus, Pan32",
|
||||
version = "1.1.0",
|
||||
url = ""
|
||||
}
|
||||
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
||||
{
|
||||
g_bLateLoad = late;
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
LoadTranslations("common.phrases");
|
||||
@ -35,31 +50,46 @@ public void OnPluginStart()
|
||||
if (SendAudio == INVALID_MESSAGE_ID)
|
||||
SetFailState("This game does not support the \"SendAudio\" UserMessage.");
|
||||
|
||||
g_CookieBanTime = new Cookie("radiomute_ban_time", "Stores the unix epoch time in which a players ban expires", CookieAccess_Private);
|
||||
|
||||
RegAdminCmd("sm_radiomute", Command_RadioMute, ADMFLAG_BAN, "Block a client from using the in-game radio.");
|
||||
RegAdminCmd("sm_radiounmute", Command_RadioUnmute, ADMFLAG_BAN, "Unblock a client from using the in-game radio.");
|
||||
|
||||
HookUserMessage(RadioText, _hkRadioText, true);
|
||||
HookUserMessage(SendAudio, _hkSendAudio, true);
|
||||
|
||||
if (g_bLateLoad)
|
||||
{
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if (IsClientConnected(i) && IsClientInGame(i))
|
||||
{
|
||||
OnClientCookiesCached(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapEnd()
|
||||
{
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
g_bBlocked[i] = false;
|
||||
//g_bBlocked[i] = false;
|
||||
g_iBanTime[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
g_bBlocked[client] = false;
|
||||
//g_bBlocked[client] = false;
|
||||
g_iBanTime[client] = 0;
|
||||
}
|
||||
|
||||
public Action Command_RadioMute(int client, int argc)
|
||||
{
|
||||
if (argc < 1)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] Usage: sm_radiomute <target>");
|
||||
ReplyToCommand(client, "[SM] Usage: sm_radiomute <target> <time>");
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
@ -79,13 +109,47 @@ public Action Command_RadioMute(int client, int argc)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
int iBanTime = DEFAULT_BAN;
|
||||
if (argc > 1)
|
||||
{
|
||||
GetCmdArg(2, sArgs, sizeof(sArgs));
|
||||
//BUGBUG Not checking for string to int errors, as people are used to 0 for perm and 0 is also the error value
|
||||
iBanTime = StringToInt(sArgs);
|
||||
if (iBanTime < 0)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] Invalid ban time");
|
||||
}
|
||||
|
||||
if (iBanTime == 0)
|
||||
{
|
||||
//Does this technically violate the previous check? Yes, but the banned value is this. Tought.
|
||||
iBanTime = -1;
|
||||
}
|
||||
}
|
||||
|
||||
char sBanTimeStamp[64];
|
||||
int iBanTimeStamp;
|
||||
|
||||
if (iBanTime == -1) //Permanent ban
|
||||
{
|
||||
iBanTimeStamp = -1;
|
||||
Format(sBanTimeStamp, sizeof(sBanTimeStamp), "-1");
|
||||
}
|
||||
else //Timestamp + time
|
||||
{
|
||||
iBanTimeStamp = GetTime() + MinsToSecs(iBanTime);
|
||||
Format(sBanTimeStamp, sizeof(sBanTimeStamp), "%d", iBanTimeStamp);
|
||||
}
|
||||
|
||||
for (int i = 0; i < iTargetCount; i++)
|
||||
{
|
||||
g_bBlocked[iTargets[i]] = true;
|
||||
g_CookieBanTime.Set(iTargets[i], sBanTimeStamp);
|
||||
g_iBanTime[iTargets[i]] = iBanTimeStamp;
|
||||
//g_bBlocked[iTargets[i]] = true;
|
||||
}
|
||||
|
||||
ShowActivity2(client, "\x01[SM] \x04", "\x01Radio muted \x04%s\x01", sTargetName);
|
||||
LogAction(client, -1, "\"%L\" radio muted \"%s\"", client, sTargetName);
|
||||
LogMessage("\"%L\" radio muted \"%s\" for %d minutes.", client, sTargetName, iBanTime);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
@ -116,11 +180,14 @@ public Action Command_RadioUnmute(int client, int argc)
|
||||
|
||||
for (int i = 0; i < iTargetCount; i++)
|
||||
{
|
||||
g_bBlocked[iTargets[i]] = false;
|
||||
g_CookieBanTime.Set(iTargets[i], "");
|
||||
g_iBanTime[iTargets[i]] = 0;
|
||||
//g_bBlocked[iTargets[i]] = false;
|
||||
}
|
||||
|
||||
ShowActivity2(client, "\x01[SM] \x04", "\x01Radio unmuted \x04%s\x01", sTargetName);
|
||||
LogAction(client, -1, "\"%L\" radio unmuted \"%s\"", client, sTargetName);
|
||||
//Originally LogAction, but for some reason its not logging, so LogMessage it is
|
||||
LogMessage("\"%L\" radio unmuted \"%s\"", client, sTargetName);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
@ -137,7 +204,8 @@ public Action _hkRadioText(UserMsg msg_id, Handle bf, const int[] players, int p
|
||||
g_iMessageClient = BfReadByte(bf);
|
||||
}
|
||||
|
||||
if (g_bBlocked[g_iMessageClient])
|
||||
//if (g_bBlocked[g_iMessageClient])
|
||||
if (IsRadioBanned(g_iMessageClient))
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
@ -160,7 +228,8 @@ public Action _hkSendAudio(UserMsg msg_id, Handle bf, const int[] players, int p
|
||||
if (strncmp(sSound[6], "lock", 4, false) == 0)
|
||||
return Plugin_Continue;
|
||||
|
||||
if (g_bBlocked[g_iMessageClient])
|
||||
//if (g_bBlocked[g_iMessageClient])
|
||||
if (IsRadioBanned(g_iMessageClient))
|
||||
{
|
||||
g_iMessageClient = -1;
|
||||
|
||||
@ -171,3 +240,46 @@ public Action _hkSendAudio(UserMsg msg_id, Handle bf, const int[] players, int p
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public void OnClientCookiesCached(int client)
|
||||
{
|
||||
//Get cookie
|
||||
char sBanTime[64];
|
||||
g_CookieBanTime.Get(client, sBanTime, sizeof(sBanTime));
|
||||
if (StrEqual(sBanTime, "")) //If string is empty, no ban ongoing.
|
||||
{
|
||||
g_iBanTime[client] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int epochTime = StringToInt(sBanTime);
|
||||
if (epochTime == 0) //0 Means the string to int errored out, log and empty out the string
|
||||
{
|
||||
char steamId[32];
|
||||
GetClientAuthId(client, AuthId_Steam2, steamId, sizeof(steamId));
|
||||
LogError("Failed to interpret correctly the ban time length from cookie for user %N (%s)", client, steamId);
|
||||
g_CookieBanTime.Set(client, "");
|
||||
g_iBanTime[client] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (epochTime < GetTime()) //Player is no longer banned
|
||||
{
|
||||
g_CookieBanTime.Set(client, "");
|
||||
g_iBanTime[client] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
g_iBanTime[client] = epochTime;
|
||||
}
|
||||
|
||||
//If this turns out to be very expensive, we can convert it back to boolean and banned players will only get unbanned on reconnect or mapchange. But this would work as an ongoing thing.
|
||||
public bool IsRadioBanned(int client)
|
||||
{
|
||||
return (g_iBanTime[client] == -1 || g_iBanTime[client] >= GetTime());
|
||||
}
|
||||
|
||||
public int MinsToSecs(int mins)
|
||||
{
|
||||
return mins*60;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user