From 53156446d4e34d3433addb4cbcb9be29b9e3d107 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 21 Oct 2007 23:50:37 +0000 Subject: [PATCH] - updated basecommands and basefuncommands to use ProcessTargetString() and ShowActivity2() - moved a bunch of translation phrases around - ShowActivity2() no longer prints to console - fixed a memory corruption bug in the translation parser --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401630 --- core/Translator.cpp | 1 + core/smn_player.cpp | 150 +++++++++++++++++++++-- plugins/basecommands.sp | 2 +- plugins/basecommands/kick.sp | 4 +- plugins/basefuncommands.sp | 46 +++++-- plugins/basefuncommands/burn.sp | 53 +++++--- plugins/basefuncommands/slap.sp | 63 ++++++---- plugins/basefuncommands/slay.sp | 53 +++++--- plugins/basefunvotes.sp | 1 + plugins/include/console.inc | 3 +- translations/basefuncommands.phrases.txt | 46 +++++++ translations/basefunvotes.phrases.txt | 7 +- translations/common.phrases.txt | 66 ++++------ translations/core.phrases.txt | 2 +- translations/plugin.basecommands.txt | 2 +- 15 files changed, 362 insertions(+), 137 deletions(-) create mode 100644 translations/basefuncommands.phrases.txt diff --git a/core/Translator.cpp b/core/Translator.cpp index e50345c5..20a708d3 100644 --- a/core/Translator.cpp +++ b/core/Translator.cpp @@ -473,6 +473,7 @@ SMCParseResult CPhraseFile::ReadSMC_KeyValue(const char *key, const char *value, pPhrase = (phrase_t *)m_pMemory->GetAddress(m_CurPhrase); pTrans = (trans_t *)m_pMemory->GetAddress(pPhrase->trans_tbl); fmt_list = (int *)m_pMemory->GetAddress(pPhrase->fmt_list); + out_buf = (char *)m_pMemory->GetAddress(out_idx); pTrans = &pTrans[lang]; /* Now it's safe to save the index */ diff --git a/core/smn_player.cpp b/core/smn_player.cpp index 38861968..78646639 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -884,8 +884,7 @@ static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params) static cell_t _ShowActivity(IPluginContext *pContext, const cell_t *params, const char *tag, - cell_t fmt_param, - unsigned int mode) + cell_t fmt_param) { char message[255]; char buffer[255]; @@ -926,10 +925,6 @@ static cell_t _ShowActivity(IPluginContext *pContext, engine->ClientPrintf(pPlayer->GetEdict(), message); display_in_chat = true; } - else if (mode == 2) - { - display_in_chat = true; - } } else { @@ -1013,9 +1008,146 @@ static cell_t _ShowActivity(IPluginContext *pContext, return 1; } +static cell_t _ShowActivity2(IPluginContext *pContext, + const cell_t *params, + const char *tag, + cell_t fmt_param) +{ + char message[255]; + char buffer[255]; + int value = sm_show_activity.GetInt(); + unsigned int replyto = g_ChatTriggers.GetReplyTo(); + int client = params[1]; + + const char *name = "Console"; + const char *sign = "ADMIN"; + if (client != 0) + { + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); + if (!pPlayer || !pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + name = pPlayer->GetName(); + AdminId id = pPlayer->GetAdminId(); + if (id == INVALID_ADMIN_ID + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) + { + sign = "PLAYER"; + } + + g_SourceMod.SetGlobalTarget(client); + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetContext()->n_err != SP_ERROR_NONE) + { + return 0; + } + + /* We don't display directly to the console because the chat text + * simply gets added to the console, so we don't want it to print + * twice. + */ + if (replyto == SM_REPLY_CONSOLE) + { +#if 0 + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); + engine->ClientPrintf(pPlayer->GetEdict(), message); +#endif + UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); + g_HL2.TextMsg(client, HUD_PRINTTALK, message); + } + else + { + UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); + g_HL2.TextMsg(client, HUD_PRINTTALK, message); + } + } + else + { + g_SourceMod.SetGlobalTarget(LANG_SERVER); + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetContext()->n_err != SP_ERROR_NONE) + { + return 0; + } + + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); + META_CONPRINT(message); + } + + if (!value) + { + return 1; + } + + int maxClients = g_Players.GetMaxClients(); + for (int i=1; i<=maxClients; i++) + { + CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); + if (!pPlayer->IsInGame() + || pPlayer->IsFakeClient() + || i == client) + { + continue; + } + AdminId id = pPlayer->GetAdminId(); + g_SourceMod.SetGlobalTarget(i); + if (id == INVALID_ADMIN_ID + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) + { + /* Treat this as a normal user */ + if ((value & 1) || (value & 2)) + { + const char *newsign = sign; + if ((value & 2)) + { + newsign = name; + } + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetContext()->n_err != SP_ERROR_NONE) + { + return 0; + } + + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); + g_HL2.TextMsg(i, HUD_PRINTTALK, message); + } + } + else + { + /* Treat this as an admin user */ + bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective); + if ((value & 4) + || (value & 8) + || ((value & 16) && is_root)) + { + const char *newsign = sign; + if ((value & 8) || ((value & 16) && is_root)) + { + newsign = name; + } + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetContext()->n_err != SP_ERROR_NONE) + { + return 0; + } + + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); + g_HL2.TextMsg(i, HUD_PRINTTALK, message); + } + } + } + + return 1; +} + static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params) { - return _ShowActivity(pContext, params, "[SM] ", 2, 1); + return _ShowActivity(pContext, params, "[SM] ", 2); } static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params) @@ -1023,7 +1155,7 @@ static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params) char *str; pContext->LocalToString(params[2], &str); - return _ShowActivity(pContext, params, str, 3, 1); + return _ShowActivity(pContext, params, str, 3); } static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params) @@ -1031,7 +1163,7 @@ static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params) char *str; pContext->LocalToString(params[2], &str); - return _ShowActivity(pContext, params, str, 3, 2); + return _ShowActivity2(pContext, params, str, 3); } static cell_t KickClient(IPluginContext *pContext, const cell_t *params) diff --git a/plugins/basecommands.sp b/plugins/basecommands.sp index 5eec5a32..a29f7556 100644 --- a/plugins/basecommands.sp +++ b/plugins/basecommands.sp @@ -20,7 +20,7 @@ * this program. If not, see . * * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the + * code of this program (as well as its derivative 1works) to "Half-Life 2," the * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * by the Valve Corporation. You must obey the GNU General Public License in * all respects for all other code used. Additionally, AlliedModders LLC grants diff --git a/plugins/basecommands/kick.sp b/plugins/basecommands/kick.sp index 635fe5cd..2c97002e 100644 --- a/plugins/basecommands/kick.sp +++ b/plugins/basecommands/kick.sp @@ -77,7 +77,7 @@ public MenuHandler_Kick(Handle:menu, MenuAction:action, param1, param2) { decl String:name[MAX_NAME_LENGTH]; GetClientName(target, name, sizeof(name)); - ShowActivity2(param1, "[SM] ", "%t", "Kicked target", "_S", name); + ShowActivity2(param1, "[SM] ", "%t", "Kicked target", "_s", name); PerformKick(param1, target, ""); } @@ -129,7 +129,7 @@ public Action:Command_Kick(client, args) } else { - ShowActivity2(client, "[SM] ", "%t", "Kicked target", "_S", target_name); + ShowActivity2(client, "[SM] ", "%t", "Kicked target", "_s", target_name); } new kick_self = 0; diff --git a/plugins/basefuncommands.sp b/plugins/basefuncommands.sp index 9d1d2985..bfbf6139 100644 --- a/plugins/basefuncommands.sp +++ b/plugins/basefuncommands.sp @@ -58,6 +58,7 @@ new g_SlapDamage[MAXPLAYERS+1]; public OnPluginStart() { LoadTranslations("common.phrases"); + LoadTranslations("basefuncommands.phrases"); RegAdminCmd("sm_burn", Command_Burn, ADMFLAG_SLAY, "sm_burn <#userid|name> [time]"); RegAdminCmd("sm_slap", Command_Slap, ADMFLAG_SLAY, "sm_slap <#userid|name> [damage]"); @@ -127,12 +128,6 @@ public Action:Command_Play(client, args) decl String:Arg[65]; new len = BreakString(Arguments, Arg, sizeof(Arg)); - new target = FindTarget(client, Arg); - if (target == -1) - { - return Plugin_Handled; - } - /* Make sure it does not go out of bound by doing "sm_play user "*/ if (len == -1) { @@ -151,13 +146,38 @@ public Action:Command_Play(client, args) Arguments[FileLen - 1] = '\0'; } } - - GetClientName(target, Arg, sizeof(Arg)); - ShowActivity(client, "%t", "Played Sound", Arg); - LogAction(client, target, "\"%L\" played sound on \"%L\" (file \"%s\")", client, target, Arguments[len]); - - ClientCommand(target, "playgamesound \"%s\"", Arguments[len]); + + decl String:target_name[MAX_TARGET_LENGTH]; + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml; + + if ((target_count = ProcessTargetString( + Arg, + client, + target_list, + MAXPLAYERS, + COMMAND_FILTER_NO_BOTS, + target_name, + sizeof(target_name), + tn_is_ml)) <= 0) + { + ReplyToTargetError(client, target_count); + return Plugin_Handled; + } + + for (new i = 0; i < target_count; i++) + { + ClientCommand(target_list[i], "playgamesound \"%s\"", Arguments[len]); + LogAction(client, target_list[i], "\"%L\" played sound on \"%L\" (file \"%s\")", client, target_list[i], Arguments[len]); + } + + if (tn_is_ml) + { + ShowActivity2(client, "[SM] ", "%t", "Played sound to target", target_name); + } + else + { + ShowActivity2(client, "[SM] ", "%t", "Played sound to target", "_s", target_name); + } return Plugin_Handled; } - diff --git a/plugins/basefuncommands/burn.sp b/plugins/basefuncommands/burn.sp index fe22a0a4..6a1fac8c 100644 --- a/plugins/basefuncommands/burn.sp +++ b/plugins/basefuncommands/burn.sp @@ -1,16 +1,5 @@ PerformBurn(client, target, Float:seconds) { - new String:name[32]; - - GetClientName(target, name, sizeof(name)); - - if (!IsPlayerAlive(target)) - { - ReplyToCommand(client, "[SM] %t", "Cannot be performed on dead", name); - return; - } - - ShowActivity(client, "%t", "Ignited player", name); LogAction(client, target, "\"%L\" ignited \"%L\" (seconds \"%f\")", client, target, seconds); IgniteEntity(target, seconds); } @@ -77,7 +66,10 @@ public MenuHandler_Burn(Handle:menu, MenuAction:action, param1, param2) } else { + new String:name[32]; + GetClientName(target, name, sizeof(name)); PerformBurn(param1, target, 20.0); + ShowActivity2(param1, "[SM] ", "%t", "Set target on fire", "_s", name); } /* Re-draw the menu if they're still valid */ @@ -99,12 +91,6 @@ public Action:Command_Burn(client, args) decl String:arg[65]; GetCmdArg(1, arg, sizeof(arg)); - new target = FindTarget(client, arg); - if (target == -1) - { - return Plugin_Handled; - } - new Float:seconds = 20.0; if (args > 1) @@ -118,7 +104,36 @@ public Action:Command_Burn(client, args) } } - PerformBurn(client, target, seconds); + decl String:target_name[MAX_TARGET_LENGTH]; + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml; + + if ((target_count = ProcessTargetString( + arg, + client, + target_list, + MAXPLAYERS, + COMMAND_FILTER_NO_BOTS, + target_name, + sizeof(target_name), + tn_is_ml)) <= 0) + { + ReplyToTargetError(client, target_count); + return Plugin_Handled; + } + + for (new i = 0; i < target_count; i++) + { + PerformBurn(client, target_list[i], seconds); + } + + if (tn_is_ml) + { + ShowActivity2(client, "[SM] ", "%t", "Set target on fire", target_name); + } + else + { + ShowActivity2(client, "[SM] ", "%t", "Set target on fire", "_s", target_name); + } return Plugin_Handled; -} \ No newline at end of file +} diff --git a/plugins/basefuncommands/slap.sp b/plugins/basefuncommands/slap.sp index 27d1554f..de89c7fa 100644 --- a/plugins/basefuncommands/slap.sp +++ b/plugins/basefuncommands/slap.sp @@ -1,16 +1,5 @@ PerformSlap(client, target, damage) { - new String:name[32]; - - GetClientName(target, name, sizeof(name)); - - if (!IsPlayerAlive(target)) - { - ReplyToCommand(client, "[SM] %t", "Cannot be performed on dead", name); - return; - } - - ShowActivity(client, "%t", "Slapped player", name); LogAction(client, target, "\"%L\" slapped \"%L\" (damage \"%d\")", client, target, damage); SlapPlayer(target, damage, true); } @@ -119,16 +108,19 @@ public MenuHandler_Slap(Handle:menu, MenuAction:action, param1, param2) { PrintToChat(param1, "[SM] %t", "Unable to target"); } + else if (!IsPlayerAlive(target)) + { + ReplyToCommand(param1, "[SM] %t", "Player has since died"); + } else { + decl String:name[32]; + GetClientName(target, name, sizeof(name)); PerformSlap(param1, target, g_SlapDamage[param1]); + ShowActivity2(param1, "[SM] ", "%t", "Slapped target", "_s", name); } - /* Re-draw the menu if they're still valid */ - if (IsClientInGame(param1) && !IsClientInKickQueue(param1)) - { - DisplaySlapTargetMenu(param1); - } + DisplaySlapTargetMenu(param1); } } @@ -143,12 +135,6 @@ public Action:Command_Slap(client, args) decl String:arg[65]; GetCmdArg(1, arg, sizeof(arg)); - new target = FindTarget(client, arg); - if (target == -1) - { - return Plugin_Handled; - } - new damage = 0; if (args > 1) { @@ -160,8 +146,37 @@ public Action:Command_Slap(client, args) return Plugin_Handled; } } + + decl String:target_name[MAX_TARGET_LENGTH]; + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml; + + if ((target_count = ProcessTargetString( + arg, + client, + target_list, + MAXPLAYERS, + COMMAND_FILTER_NO_BOTS, + target_name, + sizeof(target_name), + tn_is_ml)) <= 0) + { + ReplyToTargetError(client, target_count); + return Plugin_Handled; + } + + for (new i = 0; i < target_count; i++) + { + PerformSlap(client, target_list[i], damage); + } - PerformSlap(client, target, damage); + if (tn_is_ml) + { + ShowActivity2(client, "[SM] ", "%t", "Slapped target", target_name); + } + else + { + ShowActivity2(client, "[SM] ", "%t", "Slapped target", "_s", target_name); + } return Plugin_Handled; -} \ No newline at end of file +} diff --git a/plugins/basefuncommands/slay.sp b/plugins/basefuncommands/slay.sp index 774521ca..532a0d6e 100644 --- a/plugins/basefuncommands/slay.sp +++ b/plugins/basefuncommands/slay.sp @@ -1,17 +1,6 @@ PerformSlay(client, target) { - decl String:name[32]; - - GetClientName(target, name, sizeof(name)); - - if (!IsPlayerAlive(target)) - { - ReplyToCommand(client, "[SM] %t", "Cannot be performed on dead", name); - return; - } - - ShowActivity(client, "%t", "Slayed player", name); LogAction(client, target, "\"%L\" slayed \"%L\"", client, target); ForcePlayerSuicide(target); } @@ -76,16 +65,19 @@ public MenuHandler_Slay(Handle:menu, MenuAction:action, param1, param2) { PrintToChat(param1, "[SM] %t", "Unable to target"); } + else if (!IsPlayerAlive(target)) + { + ReplyToCommand(param1, "[SM] %t", "Player has since died"); + } else { + decl String:name[32]; + GetClientName(target, name, sizeof(name)); PerformSlay(param1, target); + ShowActivity2(param1, "[SM] ", "%t", "Slayed target", "_s", name); } - /* Re-draw the menu if they're still valid */ - if (IsClientInGame(param1) && !IsClientInKickQueue(param1)) - { - DisplaySlayMenu(param1); - } + DisplaySlayMenu(param1); } } @@ -100,13 +92,36 @@ public Action:Command_Slay(client, args) decl String:arg[65]; GetCmdArg(1, arg, sizeof(arg)); - new target = FindTarget(client, arg); - if (target == -1) + decl String:target_name[MAX_TARGET_LENGTH]; + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml; + + if ((target_count = ProcessTargetString( + arg, + client, + target_list, + MAXPLAYERS, + COMMAND_FILTER_NO_BOTS, + target_name, + sizeof(target_name), + tn_is_ml)) <= 0) { + ReplyToTargetError(client, target_count); return Plugin_Handled; } - PerformSlay(client, target); + for (new i = 0; i < target_count; i++) + { + PerformSlay(client, target_list[i]); + } + + if (tn_is_ml) + { + ShowActivity2(client, "[SM] ", "%t", "Slayed target", target_name); + } + else + { + ShowActivity2(client, "[SM] ", "%t", "Slayed target", "_s", target_name); + } return Plugin_Handled; } diff --git a/plugins/basefunvotes.sp b/plugins/basefunvotes.sp index 08555ea1..14285fef 100644 --- a/plugins/basefunvotes.sp +++ b/plugins/basefunvotes.sp @@ -96,6 +96,7 @@ public OnPluginStart() LoadTranslations("common.phrases"); LoadTranslations("basevotes.phrases"); LoadTranslations("basefunvotes.phrases"); + LoadTranslations("basefuncommands.phrases"); RegAdminCmd("sm_votegravity", Command_VoteGravity, ADMFLAG_VOTE, "sm_votegravity [amount2] ... [amount5]"); RegAdminCmd("sm_voteburn", Command_VoteBurn, ADMFLAG_VOTE|ADMFLAG_SLAY, "sm_voteburn "); diff --git a/plugins/include/console.inc b/plugins/include/console.inc index 0f1feb93..7a821ff3 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -246,8 +246,7 @@ native bool:IsChatTrigger(); * the message based on the current ReplySource. * * @param client Client index doing the action, or 0 for server. - * @param tag Tag to display before the message string. For example, - * "[SM] " would show "[SM] ". + * @param tag Tag to prepend to the message. * @param format Formatting rules. * @param ... Variable number of format parameters. * @noreturn diff --git a/translations/basefuncommands.phrases.txt b/translations/basefuncommands.phrases.txt new file mode 100644 index 00000000..6eb1f9f6 --- /dev/null +++ b/translations/basefuncommands.phrases.txt @@ -0,0 +1,46 @@ +"Phrases" +{ + "Played sound to target" + { + "#format" "{1:t}" + "en" "Played sound to {1}" + } + + "Burn player" + { + "en" "Burn player" + } + + "Slap player" + { + "en" "Slap player" + } + + "Slap damage" + { + "en" "Slap damage" + } + + "Slay player" + { + "en" "Slay player" + } + + "Slapped target" + { + "#format" "{1:t}" + "en" "Slapped {1}." + } + + "Slayed target" + { + "#format" "{1:t}" + "en" "Slayed {1}." + } + + "Set target on fire" + { + "#format" "{1:t}" + "en" "Set {1} on fire." + } +} diff --git a/translations/basefunvotes.phrases.txt b/translations/basefunvotes.phrases.txt index c92d0858..90844f1c 100644 --- a/translations/basefunvotes.phrases.txt +++ b/translations/basefunvotes.phrases.txt @@ -100,4 +100,9 @@ "en" "Slay vote" } -} \ No newline at end of file + "Ignited player" + { + "#format" "{1:s}" + "en" "Set player '{1}' on fire" + } +} diff --git a/translations/common.phrases.txt b/translations/common.phrases.txt index 7f205cff..78789984 100644 --- a/translations/common.phrases.txt +++ b/translations/common.phrases.txt @@ -88,35 +88,6 @@ { "en" "Unable to perform this command on a bot." } - - "Ignited player" - { - "#format" "{1:s}" - "en" "Set player '{1}' on fire" - } - - "Slapped player" - { - "#format" "{1:s}" - "en" "Slapped player '{1}'" - } - - "Slay player" - { - "en" "Slay player" - } - - "Slayed player" - { - "#format" "{1:s}" - "en" "Slayed player '{1}'" - } - - "Played Sound" - { - "#format" "{1:s}" - "en" "Played sound on player '{1}'" - } "Unable to find cvar" { @@ -206,7 +177,6 @@ "Player has since died" { - "#format" "{1:s}" "en" "Action cannot be performed, the player has since died." } @@ -307,21 +277,6 @@ { "en" "Ban reason" } - - "Burn player" - { - "en" "Burn player" - } - - "Slap player" - { - "en" "Slap player" - } - - "Slap damage" - { - "en" "Slap damage" - } "Command is in-game only" { @@ -342,4 +297,25 @@ { "en" "The given player is not fully in-game yet." } + + /* :UNUSED: */ + "Played Sound" + { + "#format" "{1:s}" + "en" "Played sound on player '{1}'" + } + + /* :UNUSED: */ + "Slapped player" + { + "#format" "{1:s}" + "en" "Slapped player '{1}'" + } + + /* :UNUSED: */ + "Slayed player" + { + "#format" "{1:s}" + "en" "Slayed player '{1}'" + } } diff --git a/translations/core.phrases.txt b/translations/core.phrases.txt index 6c4900b9..f5abbe59 100644 --- a/translations/core.phrases.txt +++ b/translations/core.phrases.txt @@ -51,7 +51,7 @@ } /* This is a special "pass-thru" translation */ - "_S" + "_s" { "#format" "{1:s}" "en" "{1}" diff --git a/translations/plugin.basecommands.txt b/translations/plugin.basecommands.txt index 85191c99..1bb556fe 100644 --- a/translations/plugin.basecommands.txt +++ b/translations/plugin.basecommands.txt @@ -116,6 +116,6 @@ "Kicked target" { "#format" "{1:t}" - "en" "Kicked {1}" + "en" "Kicked {1}." } }