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 pFtiler 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 mgs_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 * Note: due to a bug in Valve's earlier SDK versions, this
102 * may cause crashes alongside IServerGameDLL003 if the message is
105 * @param msg Case-sensitive string containing the message.
106 * @return A message index, or -1 on failure.
108 virtual int GetMessageIndex(const char *msg) =0;
111 * @brief Sets a hook on a user message.
113 * @param msg_id Message Id.
114 * @param pListener Pointer to an IUserMessageListener.
115 * @param intercept If true, message will be intercepted rather than merely hooked.
116 * @return True on success, false otherwise.
118 virtual bool HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
121 * @brief Unhooks a user message.
123 * @param msg_id Message Id.
124 * @param pListener Pointer to an IUserMessageListener.
125 * @param intercept If true, removed message will from interception pool rather than normal hook pool.
126 * @return True on success, false otherwise.
128 virtual bool UnhookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
131 * @brief Wrapper around UserMessageBegin for more options.
133 * @param mgs_id Message Id.
134 * @param players Array containing player indexes.
135 * @param playersNum Number of players in the array.
136 * @param flags Flags to use for sending the message.
137 * @return bf_write structure to write message with, or NULL on failure.
139 virtual bf_write *StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags) =0;
142 * @brief Wrapper around UserMessageEnd for use with StartMessage().
143 * @return True on success, false otherwise.
145 virtual bool EndMessage() =0;
149 #endif //_INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_