Implemented amb397 - amx_add{client}menuitem now accepts filenames as well as registered plugin names

(is_plugin_loaded() now has an optional second parameter to search for filenames)
This commit is contained in:
Steve Dudenhoeffer 2007-07-25 18:54:32 +00:00
parent ced56c79b6
commit 9ce9b142e7
4 changed files with 52 additions and 16 deletions

View File

@ -3124,6 +3124,7 @@ static cell AMX_NATIVE_CALL is_module_loaded(AMX *amx, cell *params)
}
// native is_plugin_loaded(const name[]);
// 1.8 changed to: is_plugin_loaded(const name[], bool:usefilename=false);
static cell AMX_NATIVE_CALL is_plugin_loaded(AMX *amx, cell *params)
{
// param1: name
@ -3131,12 +3132,29 @@ static cell AMX_NATIVE_CALL is_plugin_loaded(AMX *amx, cell *params)
char *name = get_amxstring(amx, params[1], 0, len);
int id = 0;
for (CPluginMngr::iterator iter = g_plugins.begin(); iter; ++iter)
if (params[0] / sizeof(cell) == 1 || // compiled pre-1.8 - assume plugin's registered name
params[2] == 0) // compiled post 1.8 - wants plugin's registered name
{
if (stricmp((*iter).getTitle(), name) == 0)
return id;
// searching for registered plugin name
for (CPluginMngr::iterator iter = g_plugins.begin(); iter; ++iter)
{
if (stricmp((*iter).getTitle(), name) == 0)
return id;
++id;
++id;
}
}
else
{
// searching for filename
// filename search is case sensitive
for (CPluginMngr::iterator iter = g_plugins.begin(); iter; ++iter)
{
if (strcmp((*iter).getName(), name) == 0)
return id;
++id;
}
}
return -1;

View File

@ -604,9 +604,23 @@ native get_module(id, name[], nameLen, author[], authorLen, version[], versionLe
/* Returns number of currently registered modules */
native get_modulesnum();
/* Checks whether a plugin is loaded. If it is not, the return value is -1, otherwise
* the return value is the plugin id. The function is case insensitive. */
native is_plugin_loaded(const name[]);
/**
* Checks whether a plugin is loaded by the given registered name (such as "Admin Base"), or, optionally
* the given filename ("admin.amxx").
*
* @param name Either the plugin name to lookup, or the plugin filename to lookup.
* @param usefilename Set to true if you want to search for the plugin by the filename, false to search
* by the plugin's registered name.
*
* @return Plugin ID of the matching plugin on a successful search, -1 on a failed search.
*
* @note Prior to 1.8, this function would only search for plugins registered names, not
* the filename.
*
* @note The plugin registered name search is a case insensitive search, however, the plugin
* filename search is case sensitive.
*/
native is_plugin_loaded(const name[], bool:usefilename=false);
/* Gets info about plugin by given index.
* Function returns -1 if plugin doesn't exist with given index.

View File

@ -191,7 +191,9 @@ displayMenu(id, pos)
for (new a = start; a < end; ++a)
{
if (access(id, g_menuAccess[a]) && (is_plugin_loaded(g_menuPlugin[a]) != -1))
if ( access(id, g_menuAccess[a]) &&
((is_plugin_loaded(g_menuPlugin[a]) != -1) || // search plugins for registered name
(is_plugin_loaded(g_menuPlugin[a], true) != -1))) // search plugins for filename
{
keys |= (1<<b)
@ -250,7 +252,9 @@ clientDisplayMenu(id, pos)
for (new a = start; a < end; ++a)
{
if (access(id, g_clientMenuAccess[a]) && (is_plugin_loaded(g_clientMenuPlugin[a]) != -1))
if ( access(id, g_clientMenuAccess[a]) &&
((is_plugin_loaded(g_clientMenuPlugin[a]) != -1) || // search plugins for registered name
(is_plugin_loaded(g_clientMenuPlugin[a], true) != -1))) // search plugins for file name
{
keys |= (1<<b)
@ -350,8 +354,8 @@ public plugin_init()
register_clcmd("amxmodmenu", "cmdMenu", ADMIN_MENU, "- displays menus")
register_clcmd("amx_menu", "clientCmdMenu", 0, "- displays menus available to client")
register_srvcmd("amx_addmenuitem", "addmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name> - Add a menu item to Menus Front-End")
register_srvcmd("amx_addclientmenuitem", "addclientmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name> - Add a menu item to Client Menus Front-End")
register_srvcmd("amx_addmenuitem", "addmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name | plugin filename> - Add a menu item to Menus Front-End")
register_srvcmd("amx_addclientmenuitem", "addclientmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name | plugin filename> - Add a menu item to Client Menus Front-End")
g_coloredMenus = colored_menus()

View File

@ -80,11 +80,11 @@ public plugin_init()
// Add these menus to the amxmodmenu
public plugin_cfg()
{
new PluginName[64];
new PluginFileName[64];
get_plugin(-1,"",0,PluginName,sizeof(PluginName)-1);
AddMenuItem("Plugin Cvars", "amx_plugincvarmenu", ADMIN_CVAR, PluginName);
AddMenuItem("Plugin Commands", "amx_plugincmdmenu", ADMIN_MENU, PluginName);
get_plugin(-1, PluginFileName, charsmax(PluginFileName));
AddMenuItem("Plugin Cvars", "amx_plugincvarmenu", ADMIN_CVAR, PluginFileName);
AddMenuItem("Plugin Commands", "amx_plugincmdmenu", ADMIN_MENU, PluginFileName);
}
// Reset all fields for each client as they connect.