Raised This Month: $32 Target: $400
 8% 

Messagemode API


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Technical/Development       
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-22-2019 , 13:20   Messagemode API
Reply With Quote #1


This is a replacement for the messagemode/messagemode2 commands.


About the plugin [top]
So as everyone probably already knows, Valve added messagemode to the list of the commands that cannot be executed by the game server for security reasons (visit this site for more informations: https://thehackernews.com/2019/03/co...e-servers.html). This compromised the plugins that use the command, so that's why I did this API. It allows you to retrieve what the player write in chat through say/say_team. This could be done even without it, but I thought interesting to do for flexibility reasons.


Functions [top]
Code:
/**  * Registers a messagemode hook.  *  * @note  Below is the prototype of callback:  *        -  *          Called when player write the data.  *  *          @param index         Client index  *          @param message       Text that the player wrote  *  *          @noreturn  *  *          public OnWriteData(index, message[])  *        -  * @param callback   The forward to call  * @param cancel       If true, player will be able to cancel the hook by typing /cancel  *  * @return     Returns a handle to the forward on success, -1 otherwise.  * @error            If the specified callback is invalid, an error will be thrown.  */ native mm_register_hook(const callback[], bool:cancel = true);

Code:
/**  * Starts a messagemode hook.  *  * @param func_id     The forward to start  * @param index         Client index  *  * @return     1 on success, 0 otherwise.  * @error            If the index is not within the range of 1 to MaxClients or  *                      the client is not connected, or if the specified function is invalid,  *            an error will be thrown.  */ native mm_parse_hook(func_id, index);


Installation [top]
  • Download and compile messagemode_api.sma and put the compiled binary (.amxx) in addons/amxmodx/plugins, then enabled it in addons/amxmodx/configs/plugins.ini.
  • Download messagemode_api.inc and put it in addons/amxmodx/scripting/include.
  • Download messagemode_api.txt and put it in addons/amxmodx/data/lang.


Examples [top]
Code:
#include <amxmodx> #include <amxmisc> #include <messagemode_api> new g_iHookId; public plugin_init() {     register_plugin("Messagemode API - Example", "1.0", "Crazy");     g_iHookId = mm_register_hook("OnWriteData", true);     register_concmd("amx_messagemode", "CmdMessageMode", ADMIN_CHAT); } public OnWriteData(index, message[]) {     new szName[32];     get_user_name(index, szName, charsmax(szName));     log_amx("Admin %s says ^"%s^"", szName, message); } public CmdMessageMode(index, level, command_id) {     if (!(cmd_access(index, level, command_id, 1)))         return PLUGIN_HANDLED;     mm_parse_hook(g_iHookId, index);     return PLUGIN_HANDLED; }


messagemode_api.inc [top]
Code:
#if defined _messagemode_api_included
	#endinput
#endif
#define _messagemode_api_included

#pragma reqlib messagemode_api
#if !defined AMXMODX_NOAUTOLOAD
	#pragma loadlib messagemode_api
#endif

/**
 * Registers a messagemode hook.
 *
 * @note  Below is the prototype of callback:
 *        -
 *          Called when player write the data.
 *
 *          @param index         Client index
 *          @param message       Text that the player wrote
 *
 *          @noreturn
 *
 *          public OnWriteData(index, message[])
 *        -
 * @param callback 		The forward to call
 * @param cancel 		If true, player will be able to cancel the hook by typing /cancel
 *
 * @return 				Returns a handle to the forward on success, -1 otherwise.
 * @error				If the specified callback is invalid, an error will be thrown. 
 */
native mm_register_hook(const callback[], bool:cancel = true);

/**
 * Starts a messagemode hook (replaces the current hook of the player if any).
 *
 * @param func_id 		The forward to start
 * @param index 		Client index
 *
 * @return 				1 on success, 0 otherwise.
 * @error				If the index is not within the range of 1 to MaxClients or
 *                  	the client is not connected, or if the specified function is invalid,
 *						an error will be thrown. 
 */
native mm_parse_hook(func_id, index);

messagemode_api.txt [top]

Code:
[en]

MM_TYPE_START = * You are in input mode, type /cancel to back to chat.
MM_TYPE_CANCEL = * You are no longer in input mode.

[bp]

MM_TYPE_START = * Voce esta no modo de entrada de texto, digite /cancel para voltar ao chat.
MM_TYPE_CANCEL = * Voce nao esta mais no modo de entrada de texto.

Credits [top]
Attached Files
File Type: inc messagemode_api.inc (1.3 KB, 96 views)
File Type: txt messagemode_api.txt (303 Bytes, 110 views)
File Type: sma Get Plugin or Get Source (messagemode_api.sma - 388 views - 3.0 KB)

Last edited by CrazY.; 03-22-2019 at 14:08.
CrazY. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-22-2019 , 13:30   Re: Messagemode API
Reply With Quote #2

Code:
++g_iHookCount - 1
is the same as:

Code:
g_iHookCount++
Or just remove the variable entirely (why keep track of something that's already done for you?):

Code:
ArraySize(g_arrayHooks) - 1
__________________
fysiks is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-22-2019 , 14:07   Re: Messagemode API
Reply With Quote #3

It's a habit. Fixed, thank you for the suggestion.
off: I don't know if I posted in the right section since it's a simple plugin.
__________________









Last edited by CrazY.; 03-22-2019 at 14:09.
CrazY. is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 03-22-2019 , 14:11   Re: Messagemode API
Reply With Quote #4

Quote:
Originally Posted by CrazY. View Post
It's a habit. Fixed, thank you for the suggestion.
off: I don't know if I posted in the right section since it's a simple plugin.
Better here: https://forums.alliedmods.net/forumdisplay.php?f=83
__________________
My English is A0
E1_531G is offline
Old 03-22-2019, 15:48
<VeCo>
This message has been deleted by <VeCo>. Reason: nvm, use quotes in command
thEsp
BANNED
Join Date: Aug 2017
Old 03-23-2019 , 08:22   Re: Messagemode API
Reply With Quote #5

Is this like a input/output inc?
thEsp is offline
DruGzOG
Veteran Member
Join Date: Nov 2007
Location: Unknown
Old 03-23-2019 , 08:26   Re: Messagemode API
Reply With Quote #6

Isn't this now useless since they granted privilege for it again?

https://github.com/ValveSoftware/hal...ment-475757876
__________________
DruGzOG is offline
Send a message via AIM to DruGzOG
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-23-2019 , 08:58   Re: Messagemode API
Reply With Quote #7

Quote:
Originally Posted by thEsp View Post
Is this like a input/output inc?
Well I believe so.
Code:
- You request the data
- Player write the required data (input)
- You retrieve the data through a forward (output)
Sorry if I misunderstood you.

Quote:
Originally Posted by DruGzOG View Post
Isn't this now useless since they granted privilege for it again?

https://github.com/ValveSoftware/hal...ment-475757876
Not really, you still can implement this plugin if you prefer to work with say/say_team than messagemode.
__________________








CrazY. 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 12:47.


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