From 950e63d62fe6cddeb403414ca4bd8af1ac0b9d61 Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 11 Jul 2022 13:20:30 +0000 Subject: [PATCH] https://github.com/alliedmodders/amxmodx/pull/576 --- plugins/lang/pluginmenu.txt | 75 +++++ plugins/pluginmenu.sma | 642 ++++++++++++++++-------------------- support/PackageScript | 1 + 3 files changed, 366 insertions(+), 352 deletions(-) create mode 100644 plugins/lang/pluginmenu.txt diff --git a/plugins/lang/pluginmenu.txt b/plugins/lang/pluginmenu.txt new file mode 100644 index 00000000..33fc9c52 --- /dev/null +++ b/plugins/lang/pluginmenu.txt @@ -0,0 +1,75 @@ +[en] +PLUGINCVARMENU_DESC = - displays the plugin cvar menu +PLUGINCMDMENU_DESC = - displays the plugin command menu +PLUGIN_NOT_RUNNING = Plugin %s is not running +CVAR_NOT_CHANGED = Cvar not changed +CVAR_PTR_ERROR = There was an error extracting the cvar pointer (name = "%s") +CVAR_TYPE_NEW_VALUE = Type in the new value for %s or !cancel to cancel +CVARS = Cvars +CMD_NAME_ERROR = There was an error extracting the command name +CMD_TYPE_PARAMS = Type in the parameters for %s or !cancel to cancel +CMD_EXEC_NO_PARAMS = Command "%s" executed with no parameters +EXEC_WITH_PARAMS = Execute with parameters +EXEC_WITHOUT_PARAMS = Execute with no parameters +CMD_NOT_EXECUTED = Command not executed +CMD_EXECUTED = Command "%s" executed with "%s" +COMMANDS = Commands +PLUGIN_CVAR_MENU = Plugin Cvar Menu +PLUGIN_CMD_MENU = Plugin Command Menu + +[mk] +PLUGINCVARMENU_DESC = - prikazhuva menu so cvarovi za pluginite +PLUGINCMDMENU_DESC = - prikazhuva menu so komandi za pluginite +PLUGIN_NOT_RUNNING = Pluginot %s ne raboti +CVAR_NOT_CHANGED = Cvarot ne e promenen +CVAR_PTR_ERROR = Se pojavi greshka pri izvlekuvanje na cvar pointerot (ime = "%s") +CVAR_TYPE_NEW_VALUE = Vnesete ja novata vrednost za %s ili !cancel za da otkazhete +CVARS = Cvarovi +CMD_NAME_ERROR = Se pojavi greshka pri izvlekuvanjeto na imeto na komandata +CMD_TYPE_PARAMS = Vnesete gi parametrite za %s ili !cancel za da otkazhete +CMD_EXEC_NO_PARAMS = Komandata "%s" e izvrshena bez parametri +EXEC_WITH_PARAMS = Izvrshi so parametri +EXEC_WITHOUT_PARAMS = Izvrshi bez parametri +CMD_NOT_EXECUTED = Komandata ne e izvrshena +CMD_EXECUTED = Komandata "%s" e izvrshena so "%s" +COMMANDS = Komandi +PLUGIN_CVAR_MENU = Menu so cvarovi za pluginite +PLUGIN_CMD_MENU = Menu so komandi za pluginite + +[bg] +PLUGINCVARMENU_DESC = - pokazva menu s cvarove za pluginite +PLUGINCMDMENU_DESC = - pokazva menu s komandi za pluginite +PLUGIN_NOT_RUNNING = Pluginut %s ne raboti +CVAR_NOT_CHANGED = Cvarut ne e promenen +CVAR_PTR_ERROR = Poqvi se greshka pri izvlichaneto na cvar pointera (ime = "%s") +CVAR_TYPE_NEW_VALUE = Vuvedete novata stoinost za %s ili !cancel za da otkajete +CVARS = Cvarove +CMD_NAME_ERROR = Poqvi se gresha pri izvlichaneto na imeto na komandata +CMD_TYPE_PARAMS = Vuvedete parametrite za %s ili !cancel za da otkajete +CMD_EXEC_NO_PARAMS = Komandata "%s" e izpulnena bez parametri +EXEC_WITH_PARAMS = Izpulni s parametri +EXEC_WITHOUT_PARAMS = Izpulni bez parametri +CMD_NOT_EXECUTED = Komandata ne e izpulnena +CMD_EXECUTED = Komandata "%s" e izpulnena s "%s" +COMMANDS = Komandi +PLUGIN_CVAR_MENU = Menu s cvarove za pluginite +PLUGIN_CMD_MENU = Menu s komandi za pluginite + +[de] +PLUGINCVARMENU_DESC = - zeigt das Plugin-CVAR-Menü an +PLUGINCMDMENU_DESC = - zeigt das Plugin-Befehlsmenü an +PLUGIN_NOT_RUNNING = Plugin %s läuft nicht +CVAR_NOT_CHANGED = CVAR unverändert +CVAR_PTR_ERROR = Beim Versuch den Wert der CVAR (Name = "%s") auszugeben ist ein Fehler aufgetreten. +CVAR_TYPE_NEW_VALUE = Geben Sie den neuen Wert für %s ein - oder "!cancel", um abzubrechen. +CVARS = CVARs +CMD_NAME_ERROR = Beim Versuch den Befehlsnamen auszugeben ist ein Fehler aufgetreten. +CMD_TYPE_PARAMS = Geben Sie die Parameter für %s ein - oder "!cancel", um abzubrechen. +CMD_EXEC_NO_PARAMS = Befehl "%s" wurde ohne Parameter ausgeführt. +EXEC_WITH_PARAMS = Mit Parameter(n) ausführen +EXEC_WITHOUT_PARAMS = Ohne Parameter ausführen +CMD_NOT_EXECUTED = Befehl wurde nicht ausgeführt. +CMD_EXECUTED = Befehl "%s" wurde mit "%s" ausgeführt. +COMMANDS = Befehle +PLUGIN_CVAR_MENU = Plugin-CVAR-Menü +PLUGIN_CMD_MENU = Plugin-Befehlsmenü \ No newline at end of file diff --git a/plugins/pluginmenu.sma b/plugins/pluginmenu.sma index 2d7e2aeb..c02e1d6d 100644 --- a/plugins/pluginmenu.sma +++ b/plugins/pluginmenu.sma @@ -14,48 +14,48 @@ #include #include - - -new DisabledCallback; -new EnabledCallback; +new g_disabled_callback; +new g_enabled_callback; // pcvar that the client is currently modifying -new CurrentCvar[MAX_PLAYERS + 1]; +new g_current_cvar[MAX_PLAYERS + 1]; // Name of the cvar being modified -new CurrentCvarName[MAX_PLAYERS + 1][32]; +new g_current_cvar_name[MAX_PLAYERS + 1][32]; // Plugin ID that the client is modifying -new CurrentPlid[MAX_PLAYERS + 1]; +new g_current_player_id[MAX_PLAYERS + 1]; // Page that the client is currently on -new CurrentPage[MAX_PLAYERS + 1]; +new g_current_page[MAX_PLAYERS + 1]; // Menu function ID that the client is in -new CurrentMenuFunction[MAX_PLAYERS + 1] = { -1,... }; +new g_current_menu_function[MAX_PLAYERS + 1] = { -1, ... }; -new CurrentCommand[MAX_PLAYERS + 1][32]; -new cvarmenu_cmdid; -new cmdmenu_cmdid; +new g_current_command[MAX_PLAYERS + 1][32]; +new g_cvarmenu_cmdid; +new g_cmdmenu_cmdid; -new ExplicitPlugin[MAX_PLAYERS + 1]; +new g_explicit_plugin[MAX_PLAYERS + 1]; public plugin_init() { - register_plugin("Plugin Menu",AMXX_VERSION_STR,"AMXX Dev Team"); + register_plugin("Plugin Menu", AMXX_VERSION_STR, "AMXX Dev Team"); + register_dictionary("admincmd.txt"); //Needed for CVAR_CHANGED register_dictionary("common.txt"); register_dictionary("pausecfg.txt"); // Needed for PAUSE_COULDNT_FIND + register_dictionary("pluginmenu.txt"); - cvarmenu_cmdid=register_clcmd("amx_plugincvarmenu", "CvarMenuCommand", ADMIN_CVAR, " - displays the plugin cvar menu"); - cmdmenu_cmdid=register_clcmd("amx_plugincmdmenu", "CommandMenuCommand", ADMIN_MENU, " - displays the plugin command menu"); + g_cvarmenu_cmdid = register_clcmd("amx_plugincvarmenu", "CvarMenuCommand", ADMIN_CVAR, "PLUGINCVARMENU_DESC", .info_ml = true); + g_cmdmenu_cmdid = register_clcmd("amx_plugincmdmenu", "CommandMenuCommand", ADMIN_MENU, "PLUGINCMDMENU_DESC", .info_ml = true); - register_clcmd("amx_changecvar","CommandChangeCvar"); - register_clcmd("amx_executecmd","CommandExecuteCommand"); + register_clcmd("amx_changecvar", "CommandChangeCvar"); + register_clcmd("amx_executecmd", "CommandExecuteCommand"); // Register global menu callbacks. - DisabledCallback=menu_makecallback("AlwaysDisableCallback"); - EnabledCallback=menu_makecallback("AlwaysEnableCallback"); + g_disabled_callback = menu_makecallback("AlwaysDisableCallback"); + g_enabled_callback = menu_makecallback("AlwaysEnableCallback"); } // Add these menus to the amxmodmenu @@ -63,24 +63,20 @@ public plugin_cfg() { set_task(0.1, "addToMenuFront"); } + public addToMenuFront() { - new PluginFileName[64]; - - get_plugin(-1, PluginFileName, charsmax(PluginFileName)); - new cvarflags; - new cmdflags; - new garbage[1]; - new cmd[32]; - - get_concmd(cmdmenu_cmdid, cmd, charsmax(cmd), cmdflags, garbage, charsmax(garbage), -1); + new plugin_filename[64], cmd[32], garbage[1], cvarflags, cmdflags; + get_plugin(-1, plugin_filename, charsmax(plugin_filename)); + get_concmd(g_cmdmenu_cmdid, cmd, charsmax(cmd), cmdflags, garbage, charsmax(garbage), -1); if (strcmp(cmd, "amx_plugincmdmenu") != 0) { // this should never happen, but just incase! cmdflags = ADMIN_MENU; } - get_concmd(cvarmenu_cmdid, cmd, charsmax(cmd), cvarflags, garbage, charsmax(garbage), -1); + + get_concmd(g_cvarmenu_cmdid, cmd, charsmax(cmd), cvarflags, garbage, charsmax(garbage), -1); if (strcmp(cmd, "amx_plugincvarmenu") != 0) { @@ -88,76 +84,66 @@ public addToMenuFront() cvarflags = ADMIN_CVAR; } - AddMenuItem("Plugin Cvars", "amx_plugincvarmenu", cvarflags, PluginFileName); - AddMenuItem("Plugin Commands", "amx_plugincmdmenu", cmdflags, PluginFileName); + AddMenuItem("Plugin Cvars", "amx_plugincvarmenu", cvarflags, plugin_filename); + AddMenuItem("Plugin Commands", "amx_plugincmdmenu", cmdflags, plugin_filename); } // Reset all fields for each client as they connect. public client_connect(id) { - CurrentCvar[id]=0; - CurrentPlid[id]=0; - CurrentMenuFunction[id]=-1; - CurrentCvarName[id][0]=0; - CurrentCommand[id][0]=0; - ExplicitPlugin[id]=-1; - + g_current_cvar[id] = 0; + g_current_player_id[id] = 0; + g_current_menu_function[id] = -1; + g_current_cvar_name[id][0] = 0; + g_current_command[id][0] = 0; + g_explicit_plugin[id] = -1; } /** * Creates a plugin list menu. * - * @param MenuText The text to display as the title. + * @param menu_lang The text to display as the title. * @param Handler The function to call when an item is selected. * @param Command The function to pass to the handler. It will be passed as "PLID Command". * @param Callback Function to call for each plugin to be listed. Displays a number next to it (how many cvars, etc.) */ -stock DisplayPluginMenu(id,const MenuText[], const Handler[], const Command[], const Callback[]) +stock DisplayPluginMenu(id, const menu_lang[], const Handler[], const Command[], const Callback[]) { - new Menu=menu_create(MenuText,Handler); - - - new PluginState[32]; - new PluginName[64]; - new func=get_func_id(Callback); - new tally; - new PluginCmd[64]; - new MenuText[64]; - for (new i=0, max=get_pluginsnum(); - i0) + + if ((tally = callfunc_end()) > 0) { - get_plugin(i,"",0,PluginName,charsmax(PluginName),"",0,"",0,PluginState,charsmax(PluginState)); + get_plugin(i, _, _, plugin_name, charsmax(plugin_name), _, _, _, _, plugin_state, charsmax(plugin_state)); // Command syntax is: "# Function", # being plugin ID, function being public function to call. - formatex(PluginCmd,charsmax(PluginCmd),"%d %s",i,Command); - formatex(MenuText,charsmax(MenuText),"%s - %d",PluginName,tally); + formatex(plugincmd, charsmax(plugincmd), "%d %s", i, Command); + formatex(menu_text, charsmax(menu_text), "%s - %d", plugin_name, tally); + // If the plugin is running, add this as an activated menu item. - if (strcmp(PluginState,"running",true)==0 || - strcmp(PluginState,"debug", true)==0) + if (strcmp(plugin_state, "running", true) == 0 || strcmp(plugin_state, "debug", true) == 0) { - menu_additem(Menu,MenuText,PluginCmd,EnabledCallback); + menu_additem(menu, menu_text, plugincmd, g_enabled_callback); } else { - menu_additem(Menu,MenuText,"",_,DisabledCallback); + menu_additem(menu, menu_text, "", _, g_disabled_callback); } } } } - menu_setprop(Menu,MPROP_BACKNAME,fmt("%L", id, "BACK")); - menu_setprop(Menu,MPROP_NEXTNAME,fmt("%L", id, "MORE")); - menu_setprop(Menu,MPROP_EXITNAME,fmt("%L", id, "EXIT")); - menu_setprop(Menu,MPROP_NUMBER_COLOR,"\y"); - menu_setprop(Menu,MPROP_EXIT,MEXIT_ALL); - menu_display(id,Menu,0); - + menu_setprop(menu, MPROP_NUMBER_COLOR, "\y"); + menu_setprop(menu, MPROP_EXIT, MEXIT_ALL); + menu_display(id, menu, 0); } /** @@ -171,45 +157,40 @@ stock bool:GetPlidForValidPlugins(id, &plid) { // If arguments have been passed, then we were given // a specific plugin to examine. - if (read_argc()>1) + if (read_argc() > 1) { // Yes, we were provided a plugin. - new TargetPlugin[64]; - read_argv(1,TargetPlugin,charsmax(TargetPlugin)); + new buffer_name[64], buffer_file[64] ,buffer_state[64], target_plugin[64]; + read_argv(1, target_plugin, charsmax(target_plugin)); - new BufferName[64]; - new BufferFile[64]; - new BufferState[64]; // Scan for the plugin ID. - for (new i=0, max=get_pluginsnum(); - i<%s><>^" set cvar (name ^"%s^") (value ^"%s^")", Name, get_user_userid(id), AuthID, CurrentCvarName[id], Args); + client_print(id, print_chat, "%l", "CVAR_CHANGED", g_current_cvar_name[id], args); + log_amx("Cmd: ^"%N^" set cvar (name ^"%s^") (value ^"%s^")", id, g_current_cvar_name[id], args); - - new cvar_val[64]; - for (new i = 1; i <= MaxClients; i++) + new cvar_val[64], players[MAX_PLAYERS], pnum; + get_players_ex(players, pnum, GetPlayers_ExcludeBots); + + for (new player, i; i < pnum; i++) { - if (is_user_connected(i) && !is_user_bot(i)) + player = players[i]; + + if (get_pcvar_flags(pointer) & FCVAR_PROTECTED || equali(args, "rcon_password")) { - if (get_pcvar_flags(pointer) & FCVAR_PROTECTED || equali(Args, "rcon_password")) - { - formatex(cvar_val, charsmax(cvar_val), "*** %L ***", i, "PROTECTED"); - } - else - { - copy(cvar_val, charsmax(cvar_val), Args); - } - show_activity_id(i, id, Name, "%L", i, "SET_CVAR_TO", "", CurrentCvarName[id], cvar_val); + formatex(cvar_val, charsmax(cvar_val), "*** %L ***", player, "PROTECTED"); } + else + { + copy(cvar_val, charsmax(cvar_val), args); + } + + show_activity_id(player, id, fmt("%n", id), "%L", player, "SET_CVAR_TO", "", g_current_cvar_name[id], cvar_val); } - console_print(id, "[AMXX] %L", id, "CVAR_CHANGED", CurrentCvarName[id], Args); - + + console_print(id, "[AMXX] %l", "CVAR_CHANGED", g_current_cvar_name[id], args); } // Now redraw the menu for the client - if (CurrentMenuFunction[id]!=-1 && callfunc_begin_i(CurrentMenuFunction[id])==1) + if (g_current_menu_function[id] != -1 && callfunc_begin_i(g_current_menu_function[id]) == 1) { callfunc_push_int(id); - callfunc_push_int(CurrentPlid[id]); - callfunc_push_int(CurrentPage[id]); + callfunc_push_int(g_current_player_id[id]); + callfunc_push_int(g_current_page[id]); callfunc_end(); } @@ -464,55 +430,53 @@ public CommandChangeCvar(id) */ public CvarMenuSelection(id, menu, item) { - - if (item==MENU_EXIT) + if (item == MENU_EXIT) { menu_destroy(menu); - if (ExplicitPlugin[id]==-1) + if (g_explicit_plugin[id] == -1) { - DisplayPluginMenu(id,"Plugin Cvar Menu:", "PluginMenuSelection","DisplayCvarMenu","GetNumberOfCvarsForPlid"); + DisplayPluginMenuDefault(id); } } - else if (item==MENU_BACK) + else if (item == MENU_BACK) { - --CurrentPage[id]; - client_print(id,print_chat,"MENU_BACK"); + --g_current_page[id]; + client_print(id, print_chat, "MENU_BACK"); } - else if (item==MENU_MORE) + else if (item == MENU_MORE) { - ++CurrentPage[id]; - client_print(id,print_chat,"MENU_MORE"); + ++g_current_page[id]; + client_print(id, print_chat, "MENU_MORE"); } else { - new CvarName[64]; - new Command[32]; - new Dummy[1]; + new cvar_name[64], command[32]; + // pcvar pointer is stored in command, extract the name of the cvar from the name field. - menu_item_getinfo(menu, item, Dummy[0], Command, charsmax(Command),CvarName,charsmax(CvarName),Dummy[0]); + menu_item_getinfo(menu, item, _, command, charsmax(command), cvar_name, charsmax(cvar_name)); + g_current_cvar[id] = str_to_num(command); - CurrentCvar[id]=str_to_num(Command); - - if (CurrentCvar[id]==0) // This should never happen, but just incase.. + if (g_current_cvar[id] == 0) // This should never happen, but just incase.. { - client_print(id,print_chat,"[AMXX] There was an error extracting the cvar pointer. (Name=^"%s^")",CvarName); + client_print(id, print_chat, "%l", "CVAR_PTR_ERROR", cvar_name); return PLUGIN_HANDLED; } // TODO: ML this - // Scan up "CvarName" and stop at the first space - for (new i=0;i) should be filtered out already. * - * @param Command The command that is being checked. + * @param command The command that is being checked. */ -stock bool:IsDisplayableCmd(const Command[]) +stock bool:IsDisplayableCmd(const command[]) { // Block "say" and "say_team" - if (equal(Command,"say",3)) + if (equal(command, "say", 3)) { return false; } return true; } + /** * Displays a command list for the specified plugin. * @@ -848,54 +795,39 @@ stock bool:IsDisplayableCmd(const Command[]) */ public DisplayCmdMenu(id, plid, page) { - new PluginName[32]; - new MenuTitle[64]; - get_plugin(plid,"",0,PluginName,charsmax(PluginName),"",0,"",0,"",0); + new menu_title[64], command[64], plugin_name[32], cid_string[32], command_access; + get_plugin(plid, _, _, plugin_name, charsmax(plugin_name)); + formatex(menu_title, charsmax(menu_title), "%s %L:", plugin_name, id, "COMMANDS"); - formatex(MenuTitle,charsmax(MenuTitle),"%s Commands:",PluginName); + new menu = menu_create(menu_title, "CommandMenuSelection"); + new userflags = get_user_flags(id); + new bool:isadmin = bool:is_user_admin(id); - new Menu=menu_create(MenuTitle,"CommandMenuSelection"); - - new Command[64]; - new CidString[32]; - new CommandAccess; - new userflags=get_user_flags(id); - new bool:isadmin=bool:is_user_admin(id); - - - for (new i=0, max=get_concmdsnum(-1,-1); - i