diff --git a/core/smn_player.cpp b/core/smn_player.cpp index 83313cad..ed3640cf 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -18,6 +18,7 @@ #include "HalfLife2.h" #include "sourcemod.h" #include +#include "ChatTriggers.h" ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY|FCVAR_PROTECTED, "Activity display setting (see sourcemod.cfg)"); @@ -822,17 +823,15 @@ static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params) static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params) { + char message[255]; + char buffer[255]; int value = sm_show_activity.GetInt(); - - if (!value) - { - return 0; - } - + unsigned int replyto = g_ChatTriggers.GetReplyTo(); int client = params[1]; const char *name = "Console"; const char *sign = "ADMIN"; + bool display_in_chat = false; if (client != 0) { CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); @@ -847,15 +846,35 @@ static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params) { sign = "PLAYER"; } + + /* Display the message to the client? */ + if (replyto == SM_REPLY_CONSOLE) + { + g_SourceMod.SetGlobalTarget(client); + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2); + UTIL_Format(message, sizeof(message), "[SM] %s\n", buffer); + engine->ClientPrintf(pPlayer->GetEdict(), message); + display_in_chat = true; + } + } else { + g_SourceMod.SetGlobalTarget(LANG_SERVER); + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2); + UTIL_Format(message, sizeof(message), "[SM] %s\n", buffer); + META_CONPRINT(message); + } + + if (!value) + { + return 1; } - char message[255]; - char buffer[255]; int maxClients = g_Players.GetMaxClients(); for (int i=1; i<=maxClients; i++) { CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); - if (!pPlayer->IsInGame() || pPlayer->IsFakeClient()) + if (!pPlayer->IsInGame() + || pPlayer->IsFakeClient() + || (display_in_chat && i == client)) { continue; } diff --git a/plugins/basecommands.sp b/plugins/basecommands.sp index 14343c74..ded18442 100644 --- a/plugins/basecommands.sp +++ b/plugins/basecommands.sp @@ -43,6 +43,87 @@ public OnPluginStart() RegAdminCmd("sm_cvar", Command_Cvar, ADMFLAG_CONVARS, "sm_cvar [value]"); RegAdminCmd("sm_execcfg", Command_ExecCfg, ADMFLAG_CONFIG, "sm_execcfg "); RegAdminCmd("sm_who", Command_Who, ADMFLAG_GENERIC, "sm_who [#userid|name]"); + RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> [reason]"); +} + +public Action:Command_Ban(client, args) +{ + if (args < 2) + { + ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> [reason]"); + return Plugin_Handled; + } + + new String:arg[65]; + GetCmdArg(1, arg, sizeof(arg)); + + new clients[2]; + new numClients = SearchForClients(arg, clients, 2); + + if (numClients == 0) + { + ReplyToCommand(client, "[SM] %t", "No matching client"); + return Plugin_Handled; + } else if (numClients > 1) { + ReplyToCommand(client, "[SM] %t", "More than one client matches", arg); + return Plugin_Handled; + } else if (!CanUserTarget(client, clients[0])) { + ReplyToCommand(client, "[SM] %t", "Unable to target"); + return Plugin_Handled; + } else if (IsFakeClient(clients[0])) { + ReplyToCommand(client, "[SM] %t", "Cannot target bot"); + return Plugin_Handled; + } + + new String:s_time[12]; + GetCmdArg(2, s_time, sizeof(s_time)); + + new time = StringToInt(s_time); + + decl String:reason[128]; + if (args >= 3) + { + GetCmdArg(3, reason, sizeof(reason)); + } else { + reason[0] = '\0'; + } + + new userid = GetClientUserId(clients[0]); + GetClientName(clients[0], arg, sizeof(arg)); + + if (time) + { + if (reason[0] == '\0') + { + ShowActivity(client, "%t", "Permabanned player", arg); + } else { + ShowActivity(client, "%t", "Permabanned player reason", arg, reason); + } + } else { + if (reason[0] == '\0') + { + ShowActivity(client, "%t", "Banned player", arg, time); + } else { + ShowActivity(client, "%t", "Banned player reason", arg, time, reason); + } + } + + LogMessage("\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, clients[0], time, reason); + + if (reason[0] == '\0') + { + strcopy(reason, sizeof(reason), "Banned"); + } + + ServerCommand("banid %d %d", time, userid); + ServerCommand("kickid %d \"%s\"", userid, reason); + + if (time == 0) + { + ServerCommand("writeid"); + } + + return Plugin_Handled; } #define FLAG_STRINGS 14 @@ -171,13 +252,12 @@ public Action:Command_ExecCfg(client, args) return Plugin_Handled; } - LogMessage("\"%L\" executed config (file \"%s\")", client, path[4]); ShowActivity(client, "%t", "Executed config", path[4]); + + LogMessage("\"%L\" executed config (file \"%s\")", client, path[4]); ServerCommand("exec \"%s\"", path[4]); - ReplyToCommand(client, "[SM] %t", "Executed config", path[4]); - return Plugin_Handled; } @@ -244,14 +324,16 @@ public Action:Command_Cvar(client, args) GetCmdArg(2, value, sizeof(value)); - LogMessage("\"%L\" changed cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value); if ((GetConVarFlags(hndl) & FCVAR_PROTECTED) != FCVAR_PROTECTED) { ShowActivity(client, "%t", "Cvar changed", cvarname, value); + } else { + ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value); } + LogMessage("\"%L\" changed cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value); + SetConVarString(hndl, value); - ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value); return Plugin_Handled; } @@ -268,6 +350,7 @@ public Action:Command_Rcon(client, args) GetCmdArgString(argstring, sizeof(argstring)); LogMessage("\"%L\" console command (cmdline \"%s\")", client, argstring); + ServerCommand("%s", argstring); return Plugin_Handled; @@ -290,9 +373,9 @@ public Action:Command_Map(client, args) return Plugin_Handled; } - LogMessage("\"%L\" changed map to \"%s\"", client, map); ShowActivity(client, "%t", "Changing map", map); - ReplyToCommand(client, "%t", "Changing map", map); + + LogMessage("\"%L\" changed map to \"%s\"", client, map); new Handle:dp; CreateDataTimer(3.0, Timer_ChangeMap, dp); @@ -336,6 +419,7 @@ public Action:Command_Kick(client, args) return Plugin_Handled; } else if (!CanUserTarget(client, clients[0])) { ReplyToCommand(client, "[SM] %t", "Unable to target"); + return Plugin_Handled; } new userid = GetClientUserId(clients[0]); @@ -352,9 +436,10 @@ public Action:Command_Kick(client, args) GetCmdArg(2, reason, sizeof(reason)); } - LogMessage("\"%L\" kicked \"%L\" (reason \"%s\")", client, clients[0], reason); ShowActivity(client, "%t", "Kicked player", name); + LogMessage("\"%L\" kicked \"%L\" (reason \"%s\")", client, clients[0], reason); + if (args < 2) { ServerCommand("kickid %d", userid); @@ -362,7 +447,5 @@ public Action:Command_Kick(client, args) ServerCommand("kickid %d \"%s\"", userid, reason); } - ReplyToCommand(client, "[SM] %t", "Client kicked", name); - return Plugin_Handled; } diff --git a/plugins/include/console.inc b/plugins/include/console.inc index 0fc4bba0..d409d01c 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -185,7 +185,9 @@ native ReplySource:GetCmdReplySource(); /** * Displays usage of an admin command to users depending on the - * setting of the sm_show_activity cvar. + * setting of the sm_show_activity cvar. Additionally, the client + * who typed the command will receive the same text without any + * client name prefix (as a confirmation). * * @param client Client index doing the action, or 0 for server. * @param format Formatting rules. diff --git a/translations/common.cfg b/translations/common.cfg index 2d351abe..2a280624 100644 --- a/translations/common.cfg +++ b/translations/common.cfg @@ -17,12 +17,6 @@ "en" "Kicked player '{1}'" } - "Client kicked" - { - "#format" "{1:s}" - "en" "Client '{1}' kicked." - } - "Changing map" { "#format" "{1:s}" @@ -54,4 +48,9 @@ { "en" "See console for output." } + + "Cannot target bot" + { + "en" "Unable to perform this command on a bot." + } } diff --git a/translations/plugin.basecommands.cfg b/translations/plugin.basecommands.cfg index 3771a295..d00d8e3d 100644 --- a/translations/plugin.basecommands.cfg +++ b/translations/plugin.basecommands.cfg @@ -34,4 +34,28 @@ "#format" "{1:s}" "en" "Executed config '{1}'." } + + "Permabanned player" + { + "#format" "{1:s}" + "en" "Permanently banned player '{1}'." + } + + "Permabanned player reason" + { + "#format" "{1:s},{2:s}" + "en" "Permanently banned player '{1}' (reason: {2})." + } + + "Banned player" + { + "#format" "{1:s},{2:d}" + "en" "Banned player '{1}' for {2} minutes." + } + + "Banned player reason" + { + "#format" "{1:s},{2:d},{3:s}" + "en" "Banned player '{1}' for {2} minutes (reason: {3})." + } }