Couch changes
This commit is contained in:
+74
-33
@@ -4,8 +4,6 @@
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
#define PREFIX "\x01[SM] \x04"
|
||||
|
||||
// So commands fail with a message instead of an unbound-native error while the core is unloaded.
|
||||
bool g_bCoreLoaded;
|
||||
|
||||
@@ -30,13 +28,13 @@ public Plugin myinfo =
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
LoadTranslations("common.phrases"); // FindTarget's replies.
|
||||
LoadTranslations("common.phrases"); // Target errors and multi-target names ("all players").
|
||||
|
||||
g_alBannedAccounts = new ArrayList();
|
||||
|
||||
RegAdminCmd("sm_couchban", Command_CouchBan, ADMFLAG_BAN, "sm_couchban <#userid|name> - bans a player from the couch until the end of the map");
|
||||
RegAdminCmd("sm_couchban", Command_CouchBan, ADMFLAG_BAN, "sm_couchban <#userid|name|@filter> - bans players from the couch until the end of the map");
|
||||
RegAdminCmd("sm_cban", Command_CouchBan, ADMFLAG_BAN, "Alias of sm_couchban");
|
||||
RegAdminCmd("sm_couchunban", Command_CouchUnban, ADMFLAG_BAN, "sm_couchunban <#userid|name> - lifts a couch ban");
|
||||
RegAdminCmd("sm_couchunban", Command_CouchUnban, ADMFLAG_BAN, "sm_couchunban <#userid|name|@filter> - lifts couch bans");
|
||||
RegAdminCmd("sm_cunban", Command_CouchUnban, ADMFLAG_BAN, "Alias of sm_couchunban");
|
||||
}
|
||||
|
||||
@@ -143,24 +141,11 @@ public Action Command_CouchBan(int client, int args)
|
||||
|
||||
if (args < 1)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] Usage: sm_couchban <#userid|name>");
|
||||
ReplyToCommand(client, PREFIX_PLAIN ... " Usage: sm_couchban <#userid|name|@filter>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
char sArg[MAX_TARGET_LENGTH];
|
||||
GetCmdArg(1, sArg, sizeof(sArg));
|
||||
|
||||
int target = FindTarget(client, sArg, true, true);
|
||||
if (target == -1)
|
||||
return Plugin_Handled;
|
||||
|
||||
if (g_bBanned[target])
|
||||
{
|
||||
ReplyToCommand(client, "[SM] %N is already couch-banned.", target);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
DoBan(client, target);
|
||||
ProcessBanCommand(client, true);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
@@ -171,25 +156,83 @@ public Action Command_CouchUnban(int client, int args)
|
||||
|
||||
if (args < 1)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] Usage: sm_couchunban <#userid|name>");
|
||||
ReplyToCommand(client, PREFIX_PLAIN ... " Usage: sm_couchunban <#userid|name|@filter>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
ProcessBanCommand(client, false);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
// Standard SourceMod targeting: a name, #userid or @filter (@all, @t, @zombies ...). Players already in
|
||||
// the wanted state are skipped. One chat line covers the whole command; each ban is still logged.
|
||||
void ProcessBanCommand(int client, bool bBan)
|
||||
{
|
||||
char sArg[MAX_TARGET_LENGTH];
|
||||
GetCmdArg(1, sArg, sizeof(sArg));
|
||||
|
||||
int target = FindTarget(client, sArg, true, true);
|
||||
if (target == -1)
|
||||
return Plugin_Handled;
|
||||
int targets[MAXPLAYERS];
|
||||
char sTargetName[MAX_TARGET_LENGTH];
|
||||
bool bIsML;
|
||||
|
||||
if (!g_bBanned[target])
|
||||
int count = ProcessTargetString(sArg, client, targets, sizeof(targets), COMMAND_FILTER_CONNECTED | COMMAND_FILTER_NO_BOTS, sTargetName, sizeof(sTargetName), bIsML);
|
||||
if (count <= 0)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] %N is not couch-banned.", target);
|
||||
return Plugin_Handled;
|
||||
ReplyToTargetError(client, count);
|
||||
return;
|
||||
}
|
||||
|
||||
DoUnban(client, target);
|
||||
return Plugin_Handled;
|
||||
int affected = 0;
|
||||
int last = 0;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int target = targets[i];
|
||||
if (!IsClientInGame(target) || g_bBanned[target] == bBan)
|
||||
continue;
|
||||
|
||||
if (bBan)
|
||||
DoBan(client, target);
|
||||
else
|
||||
DoUnban(client, target);
|
||||
|
||||
affected++;
|
||||
last = target;
|
||||
}
|
||||
|
||||
if (affected == 0)
|
||||
{
|
||||
if (count == 1)
|
||||
ReplyToCommand(client, PREFIX_PLAIN ... " %N is %s couch-banned.", targets[0], bBan ? "already" : "not");
|
||||
else
|
||||
ReplyToCommand(client, PREFIX_PLAIN ... " No matching players to couch-%s.", bBan ? "ban" : "unban");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Announced to everyone so players know why the couch stopped reacting to someone. A single
|
||||
// player is named even when they were picked out of a filter.
|
||||
if (affected == 1)
|
||||
{
|
||||
if (bBan)
|
||||
ShowActivity2(client, PREFIX, "\x01couch-banned \x04%N\x01 until the end of the map.", last);
|
||||
else
|
||||
ShowActivity2(client, PREFIX, "\x01removed couch-ban from \x04%N\x01.", last);
|
||||
}
|
||||
else if (bIsML)
|
||||
{
|
||||
if (bBan)
|
||||
ShowActivity2(client, PREFIX, "\x01couch-banned \x04%t\x01 until the end of the map.", sTargetName);
|
||||
else
|
||||
ShowActivity2(client, PREFIX, "\x01removed couch-ban from \x04%t\x01.", sTargetName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bBan)
|
||||
ShowActivity2(client, PREFIX, "\x01couch-banned \x04%s\x01 until the end of the map.", sTargetName);
|
||||
else
|
||||
ShowActivity2(client, PREFIX, "\x01removed couch-ban from \x04%s\x01.", sTargetName);
|
||||
}
|
||||
}
|
||||
|
||||
bool RequireCore(int client)
|
||||
@@ -197,7 +240,7 @@ bool RequireCore(int client)
|
||||
if (g_bCoreLoaded)
|
||||
return true;
|
||||
|
||||
ReplyToCommand(client, "[SM] The Couch core plugin is not loaded.");
|
||||
ReplyToCommand(client, PREFIX_PLAIN ... " The Couch core plugin is not loaded.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -205,14 +248,13 @@ bool RequireCore(int client)
|
||||
// Actions
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
// The announcement is the command's job, so a filter doesn't produce a line per player.
|
||||
void DoBan(int client, int target)
|
||||
{
|
||||
g_bBanned[target] = true;
|
||||
RememberAccount(target);
|
||||
Couch_SetClientBlocked(target, true);
|
||||
|
||||
// Announced to everyone so players know why the couch stopped reacting to someone.
|
||||
PrintToChatAll("\x01[SM] \x04%N\x01 couch-banned \x04%N\x01 until the end of the map.", client, target);
|
||||
LogAction(client, target, "\"%L\" couch-banned \"%L\" until the end of the map.", client, target);
|
||||
}
|
||||
|
||||
@@ -222,7 +264,6 @@ void DoUnban(int client, int target)
|
||||
ForgetAccount(target);
|
||||
Couch_SetClientBlocked(target, false);
|
||||
|
||||
PrintToChatAll("\x01[SM] \x04%N\x01 removed couch-ban from \x04%N\x01.", client, target);
|
||||
LogAction(client, target, "\"%L\" removed couch-ban from \"%L\".", client, target);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user