Base Votes import.
3 * ================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #ifndef _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
34 #define _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
36 #include <IShareSys.h>
37 #include <sp_vm_api.h>
38 #include <IForwardSys.h>
40 #include <irecipientfilter.h>
43 * @file IUserMessages.h
44 * @brief Contains functions for advanced usermessage hooking.
47 #define SMINTERFACE_USERMSGS_NAME "IUserMessages"
48 #define SMINTERFACE_USERMSGS_VERSION 1
53 * @brief Listens to user messages sent from the server.
55 class IUserMessageListener
59 * @brief Called when a hooked user message is being sent
60 * and all interceptions have finished.
62 * @param msg_id Message Id.
63 * @param bf bf_write structure containing written bytes.
64 * @param pFilter Recipient filter.
66 virtual void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
71 * @brief Called when a hooked user message is intercepted.
73 * @param msg_id Message Id.
74 * @param bf bf_write structure containing written bytes.
75 * @param pFilter Recipient filter.
76 * @return Pl_Continue to allow message, Pl_Stop or Pl_Handled to scrap it.
78 virtual ResultType InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
84 * @brief Called when a hooked user message is sent, regardless of the hook type.
85 * @param msg_id Message Id.
87 virtual void OnUserMessageSent(int msg_id)
92 #define USERMSG_RELIABLE (1<<2) /**< Message will be set to reliable */
93 #define USERMSG_INITMSG (1<<3) /**< Message will be considered to be an initmsg */
94 #define USERMSG_BLOCKHOOKS (1<<7) /**< Prevents the message from triggering SourceMod and Metamod hooks */
97 * @brief Contains functions for hooking user messages.
99 class IUserMessages : public SMInterface
102 virtual unsigned int GetInterfaceVersion()
104 return SMINTERFACE_USERMSGS_VERSION;
106 virtual const char *GetInterfaceName()
108 return SMINTERFACE_USERMSGS_NAME;
112 * @brief Finds a message id by name.
114 * @param msg Case-sensitive string containing the message.
115 * @return A message index, or -1 on failure.
117 virtual int GetMessageIndex(const char *msg) =0;
120 * @brief Sets a hook on a user message.
122 * @param msg_id Message Id.
123 * @param pListener Pointer to an IUserMessageListener.
124 * @param intercept If true, message will be intercepted rather than merely hooked.
125 * @return True on success, false otherwise.
127 virtual bool HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
130 * @brief Unhooks a user message.
132 * @param msg_id Message Id.
133 * @param pListener Pointer to an IUserMessageListener.
134 * @param intercept If true, removed message will from interception pool rather than normal hook pool.
135 * @return True on success, false otherwise.
137 virtual bool UnhookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
140 * @brief Wrapper around UserMessageBegin for more options.
142 * @param msg_id Message Id.
143 * @param players Array containing player indexes.
144 * @param playersNum Number of players in the array.
145 * @param flags Flags to use for sending the message.
146 * @return bf_write structure to write message with, or NULL on failure.
148 virtual bf_write *StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags) =0;
151 * @brief Wrapper around UserMessageEnd for use with StartMessage().
152 * @return True on success, false otherwise.
154 virtual bool EndMessage() =0;
158 #endif //_INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_