Raised This Month: $7 Target: $400
 1% 

menu_item_getinfo function problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KWo
AMX Mod X Beta Tester
Join Date: Jul 2004
Location: Poland
Old 05-06-2014 , 04:59   menu_item_getinfo function problem
Reply With Quote #1

In "my" version of CSDM (latest version called as 2.1.3c) I'm using couple of menus to let the user/admin change setting via them.
One of such menus is CSDM Settings Menu.
This is the part of code to invoke/use it:
Code:
public plugin_init()
{
(...)
	register_clcmd("csdm_menu", "csdm_menu", ADMIN_MENU, "CSDM Menu")
	register_clcmd("csdm_sett_menu", "csdm_sett_menu", ADMIN_MENU, "CSDM Settings Menu")
	register_clcmd("csdm_main_sett_menu", "csdm_main_sett_menu", ADMIN_MENU, "CSDM Main Settings Menu")
(...)
	AddMenuItem("CSDM Menu", "csdm_menu", D_ACCESS, D_PLUGIN)
	g_MainMenu = menu_create("CSDM Menu", "use_csdm_menu")
(...)
	g_SettingsMenu = menu_create("CSDM Settings Menu", "use_csdm_sett_menu")
(...)
	menu_additem(g_MainMenu, "CSDM Settings", "csdm_sett_menu", D_ACCESS)
(...)
}

public csdm_menu(id, level, cid)
{
	if (!cmd_access(id, level, cid, 1))
		return PLUGIN_HANDLED
	
	menu_display(id, g_MainMenu, 0)
	
	return PLUGIN_HANDLED
}

public csdm_sett_menu(id, level, cid)
{
	if (!cmd_access(id, level, cid, 1))
		return PLUGIN_HANDLED
	
	menu_display(id, g_SettingsMenu, 0)

	return PLUGIN_HANDLED
}

public use_csdm_menu(id, menu, item)
{
	if (item < 0)
		return PLUGIN_CONTINUE
	
	new command[24], paccess, call
	if (!menu_item_getinfo(g_MainMenu, item, paccess, command, 23, _, 0, call))
	{
		log_amx("Error: csdm_menu_item() failed (menu %d) (page %d) (item %d)", g_MainMenu, 0, item)
		return PLUGIN_HANDLED
	}
	if (paccess && !(get_user_flags(id) & paccess))
	{
		client_print(id, print_chat, "You do not have access to this menu option.")
		return PLUGIN_HANDLED
	}
	
	client_cmd(id, command)
	
	return PLUGIN_HANDLED
}

public use_csdm_sett_menu(id, menu, item)
{
	if (item < 0)
		return PLUGIN_CONTINUE
	
	new command[24], paccess, call
	if (!menu_item_getinfo(g_SettingsMenu, item, paccess, command, 23, _, 0, call))
	{
		log_amx("Error: csdm_menu_item() failed (menu %d) (page %d) (item %d)", g_SettingsMenu, 0, item)
		return PLUGIN_HANDLED
	}
	if (paccess && !(get_user_flags(id) & paccess))
	{
		client_print(id, print_chat, "You do not have access to this menu option.")
		return PLUGIN_HANDLED
	}

	client_cmd(id, command)

	return PLUGIN_HANDLED
}
I don't know exactly when, but it stopped to work with displaying CSDM Settings Menu and the user gets the info in the console "Server tried to send invalid command:"csdm_sett_menu " (many spaces next to csdm_sett_menu then qutoes - I cannot show it here exactly how does it look like in the console).
It was working for sure with AMXMODX 1.8.0 version, but it stopped probably with 1.8.2 (for both - CS1.6/CZERO). It looks like the function "menu_item_getinfo" started working a bit different way, beacuse if I'm shorting the name of my command "csdm_sett_menu" to for example "csdm_smenu" (in all paces of above code) it works again. The change of the string length of "command" didn't help even if I doubled it.
Dunno if this is the bug in the function "menu_item_getinfo" or I should rewrite some of my plugins to get them working again. But what about the compatibility with oldest AMXX versions?
__________________
The Fullpack of podbot mm V3B22 - 24 apr 2012!!! is available here.
The All-In-One 3.2a package - 02 jun 2013 (AMX X 1.8.2 [with ATAC 3.0.1b , CSDM2.1.3c beta, CM OE 0.6.5, podbot mm V3B22c and mm 1.20) is available here.
The newest Beta V3B23a (rel. 28 august 2018!!!) is available here.

Last edited by KWo; 05-06-2014 at 05:02.
KWo is offline
GinNNy
Senior Member
Join Date: Mar 2014
Old 05-06-2014 , 05:13   Re: menu_item_getinfo function problem
Reply With Quote #2

KWo
Valve blocked it so will show Server tried to send invalid command:"csdm_sett_menu "
But there is other methods but its not allowed

EDIT: You can't use client_cmd to make the users do somethin'

Last edited by GinNNy; 05-06-2014 at 05:25.
GinNNy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-06-2014 , 06:05   Re: menu_item_getinfo function problem
Reply With Quote #3

There is no reason to send the client a command to open a menu. Just show them the menu.
__________________
fysiks is offline
KWo
AMX Mod X Beta Tester
Join Date: Jul 2004
Location: Poland
Old 05-06-2014 , 08:21   Re: menu_item_getinfo function problem
Reply With Quote #4

The same command is used if the user/admin wants to open that menu just after typing the command in the console.
Actually it's nothing else like extended the functionality BAILOPAN wrote in his csdm_main original plugins:
Code:
public use_csdm_menu(id, menu, item)
{
	if (item < 0)
		return PLUGIN_CONTINUE
	
	new command[24], paccess, call
	if (!menu_item_getinfo(g_MainMenu, item, paccess, command, 23, _, 0, call))
	{
		log_amx("Error: csdm_menu_item() failed (menu %d) (page %d) (item %d)", g_MainMenu, 0, item)
		return PLUGIN_HANDLED
	}
	if (paccess && !(get_user_flags(id) & paccess))
	{
		client_print(id, print_chat, "You do not have access to this menu option.")
		return PLUGIN_HANDLED
	}
	
	client_cmd(id, command)
	
	return PLUGIN_HANDLED
}
Because there might be several menus and submenus, that's why they are invoked as commands. But - as I wrote before - it was working, now it stopped working, but if I make shorter name of my function, it starts working again (no matter if VALVE is blocking it or not).

[EDIT]
Even couple of default amxx plugins is using client_cmd to do something on clients.
[/EDIT]
__________________
The Fullpack of podbot mm V3B22 - 24 apr 2012!!! is available here.
The All-In-One 3.2a package - 02 jun 2013 (AMX X 1.8.2 [with ATAC 3.0.1b , CSDM2.1.3c beta, CM OE 0.6.5, podbot mm V3B22c and mm 1.20) is available here.
The newest Beta V3B23a (rel. 28 august 2018!!!) is available here.

Last edited by KWo; 05-06-2014 at 08:27.
KWo is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-08-2014 , 12:48   Re: menu_item_getinfo function problem
Reply With Quote #5

CSDM and official plugins are old. They would need to be cleaned up a bit. Using client_cmd is not a proper way to call internal functions. Call them directly as suggested fysiks. If you want to simulate a player entering the command in the console, then you might take a look to the new natives in 1.8.3, amxclient_cmd(), which is basically like engclient_cmd(), but notify plugins which hook the command.
__________________
Arkshine is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-09-2014 , 07:57   Re: menu_item_getinfo function problem
Reply With Quote #6

Quote:
Originally Posted by Arkshine View Post
CSDM and official plugins are old. They would need to be cleaned up a bit. Using client_cmd is not a proper way to call internal functions. Call them directly as suggested fysiks. If you want to simulate a player entering the command in the console, then you might take a look to the new natives in 1.8.3, amxclient_cmd(), which is basically like engclient_cmd(), but notify plugins which hook the command.
so basically it does not affect the client because it's still blocked but if the command is hooked it will still call the function?
gonna give an example of client_cmd(id,"say test") with a custom chat plugin that ditches cs chat and prints all messages to clients with a prefix
aron9forever is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-09-2014 , 10:41   Re: menu_item_getinfo function problem
Reply With Quote #7

Quote:
Originally Posted by aron9forever View Post
so basically it does not affect the client because it's still blocked but if the command is hooked it will still call the function?
gonna give an example of client_cmd(id,"say test") with a custom chat plugin that ditches cs chat and prints all messages to clients with a prefix
What???
__________________
fysiks is offline
KWo
AMX Mod X Beta Tester
Join Date: Jul 2004
Location: Poland
Old 05-20-2014 , 14:40   Re: menu_item_getinfo function problem
Reply With Quote #8

After analizing a bit more the code of CSDM2 plugins, I think I know the reason why it was written as client commands. The main plugin (csdm_main) registers the Main CSDM menu. But items to that menu can be added also from other plugins with their commands/functions. These items might be also some submenus. These plugins might be loaded or it's possible it will not be loaded (depanding of the configuration on the server). So it cannot be hardcoded in the main plugin which menu should be displayed (because other commands to open other menus are unknown for the main plugin). That was the point of the modular structure of CSDM2. The only way (at least that time it was written) was to use client command and ask the main plugin to run the command (if exists) on the client (admin/user). Do You have guys a good example how it was solved in other modular plugins/mods?
__________________
The Fullpack of podbot mm V3B22 - 24 apr 2012!!! is available here.
The All-In-One 3.2a package - 02 jun 2013 (AMX X 1.8.2 [with ATAC 3.0.1b , CSDM2.1.3c beta, CM OE 0.6.5, podbot mm V3B22c and mm 1.20) is available here.
The newest Beta V3B23a (rel. 28 august 2018!!!) is available here.
KWo is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-21-2014 , 04:11   Re: menu_item_getinfo function problem
Reply With Quote #9

With AMXX 1.8.3, you could use amxclient_cmd.
Or It's possible if I understand well, to create dynamic natives in main plugin, like on each sub-plugins, you need to register the menu e.g. CSDM_RegisterMenu ; and the main plugin would be notified about that and can build the CSDM menu. Something like that.
__________________
Arkshine is offline
KWo
AMX Mod X Beta Tester
Join Date: Jul 2004
Location: Poland
Old 05-21-2014 , 04:55   Re: menu_item_getinfo function problem
Reply With Quote #10

The menu is build on the initialisation with the function menu_create.
Code:
public plugin_init()
{
(...)
	g_MainMenu = menu_create("CSDM Menu", "use_csdm_menu")
(...)
}

public use_csdm_menu(id, menu, item)
{
	if (item < 0)
		return PLUGIN_CONTINUE
	
	new command[48], paccess, call
	if (!menu_item_getinfo(g_MainMenu, item, paccess, command, 47, _, 0, call))
	{
		log_amx("Error: csdm_menu_item() failed (menu %d) (page %d) (item %d)", g_MainMenu, 0, item)
		return PLUGIN_HANDLED
	}
	if (paccess && !(get_user_flags(id) & paccess))
	{
		client_print(id, print_chat, "You do not have access to this menu option.")
		return PLUGIN_HANDLED
	}

	if (equali(command,"csdm_ctrl"))
	{
		csdm_ctrl(id, paccess, 0)
		return PLUGIN_HANDLED
	}
	else if (equali(command,"csdm_st_menu"))
	{
		csdm_st_menu(id, paccess, 0)
		return PLUGIN_HANDLED
	}
	else if (equali(command,"csdm_reload"))
	{
		csdm_reload(id, paccess, 0)
		return PLUGIN_HANDLED
	}

//	client_cmd(id, command)
	
	return PLUGIN_HANDLED
}
As You can see there can be only one function written to handle one menu. If in the same menu there are other items added from other plugins (with the function menu_additem), the function use_csdm_menu cannot predict what natives might be used overthere, to handle them (and do corresponding reaction on the user action). So this is why it was called client_cmd (commented out by me for tests here). Maybe there is a way to call also some unnamed function, depanding on what "command" comes with from other plugin.

In the main plugin there are some natives, like:
Code:
public plugin_natives()
{
	register_native("csdm_main_menu", "native_main_menu")
	register_native("csdm_settings_menu", "native_settings_menu")
	register_native("csdm_set_mainoption", "__csdm_allow_option")
	register_native("csdm_fwd_drop", "__csdm_fwd_drop")
	register_native("csdm_write_cfg", "native_write_cfg")
	register_library("csdm_main")
}

public native_main_menu(id, num)
{
	return g_MainMenu
}

public native_settings_menu(id, num)
{
	return g_SettingsMenu
}
What exactly should I write in the main plugin and what in other plugins to get them communicate correctly and use one menu called and handled from the main plugin?
__________________
The Fullpack of podbot mm V3B22 - 24 apr 2012!!! is available here.
The All-In-One 3.2a package - 02 jun 2013 (AMX X 1.8.2 [with ATAC 3.0.1b , CSDM2.1.3c beta, CM OE 0.6.5, podbot mm V3B22c and mm 1.20) is available here.
The newest Beta V3B23a (rel. 28 august 2018!!!) is available here.

Last edited by KWo; 05-21-2014 at 04:56.
KWo is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:56.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode