3 * ===============================================================
4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ===============================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
20 #define _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
22 #include <IShareSys.h>
23 #include <sp_vm_api.h>
24 #include <IForwardSys.h>
26 #include <irecipientfilter.h>
29 * @file IUserMessages.h
30 * @brief Contains functions for advanced usermessage hooking.
33 #define SMINTERFACE_USERMSGS_NAME "IUserMessages"
34 #define SMINTERFACE_USERMSGS_VERSION 1
39 * @brief Listens to user messages sent from the server.
41 class IUserMessageListener
45 * @brief Called when a hooked user message is being sent
46 * and all interceptions have finished.
48 * @param msg_id Message Id.
49 * @param bf bf_write structure containing written bytes.
50 * @param pFilter Recipient filter.
52 virtual void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
57 * @brief Called when a hooked user message is intercepted.
59 * @param msg_id Message Id.
60 * @param bf bf_write structure containing written bytes.
61 * @param pFilter Recipient filter.
62 * @return Pl_Continue to allow message, Pl_Stop or Pl_Handled to scrap it.
64 virtual ResultType InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
70 * @brief Called when a hooked user message is sent, regardless of the hook type.
71 * @param msg_id Message Id.
73 virtual void OnUserMessageSent(int msg_id)
78 #define USERMSG_PASSTHRU (1<<0) /**< Message will pass through other SourceMM plugins */
79 #define USERMSG_PASSTHRU_ALL (1<<1) /**< Message will pass through other SourceMM plugins AND SourceMod */
80 #define USERMSG_RELIABLE (1<<2) /**< Message will be set to reliable */
81 #define USERMSG_INITMSG (1<<3) /**< Message will be considered to be an initmsg */
84 * @brief Contains functions for hooking user messages.
86 class IUserMessages : public SMInterface
89 virtual unsigned int GetInterfaceVersion()
91 return SMINTERFACE_USERMSGS_VERSION;
93 virtual const char *GetInterfaceName()
95 return SMINTERFACE_USERMSGS_NAME;
99 * @brief Finds a message id by name.
101 * @param msg Case-sensitive string containing the message.
102 * @return A message index, or -1 on failure.
104 virtual int GetMessageIndex(const char *msg) =0;
107 * @brief Sets a hook on a user message.
109 * @param msg_id Message Id.
110 * @param pListener Pointer to an IUserMessageListener.
111 * @param intercept If true, message will be intercepted rather than merely hooked.
112 * @return True on success, false otherwise.
114 virtual bool HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
117 * @brief Unhooks a user message.
119 * @param msg_id Message Id.
120 * @param pListener Pointer to an IUserMessageListener.
121 * @param intercept If true, removed message will from interception pool rather than normal hook pool.
122 * @return True on success, false otherwise.
124 virtual bool UnhookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
127 * @brief Wrapper around UserMessageBegin for more options.
129 * @param msg_id Message Id.
130 * @param players Array containing player indexes.
131 * @param playersNum Number of players in the array.
132 * @param flags Flags to use for sending the message.
133 * @return bf_write structure to write message with, or NULL on failure.
135 virtual bf_write *StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags) =0;
138 * @brief Wrapper around UserMessageEnd for use with StartMessage().
139 * @return True on success, false otherwise.
141 virtual bool EndMessage() =0;
145 #endif //_INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_