3 * =============================================================================
4 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _eventsmsgs_included
36 #define _eventsmsgs_included
39 * UserMsg helper values.
43 INVALID_MESSAGE_ID = -1,
47 * UserMsg message serialization formats
56 * @section Message Flags.
58 #define USERMSG_RELIABLE (1<<2) /**< Message will be set on the reliable stream */
59 #define USERMSG_INITMSG (1<<3) /**< Message will be considered to be an initmsg */
60 #define USERMSG_BLOCKHOOKS (1<<7) /**< Prevents the message from triggering SourceMod and Metamod hooks */
67 * Returns usermessage serialization type used for the current engine
69 * @return The supported usermessage type.
71 native UserMessageType:GetUserMessageType();
74 * Returns the ID of a given message, or -1 on failure.
76 * @param msg String containing message name (case sensitive).
77 * @return A message index, or INVALID_MESSAGE_ID on failure.
79 native UserMsg:GetUserMessageId(const String:msg[]);
82 * Retrieves the name of a message by ID.
84 * @param msg_id Message index.
85 * @param msg Buffer to store the name of the message.
86 * @param maxlength Maximum length of string buffer.
87 * @return True if message index is valid, false otherwise.
89 native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
92 * Starts a usermessage (network message).
93 * @note Only one message can be active at a time.
94 * @note It is illegal to send any message while a non-intercept hook is in progress.
96 * @param msgname Message name to start.
97 * @param clients Array containing player indexes to broadcast to.
98 * @param numClients Number of players in the array.
99 * @param flags Optional flags to set.
100 * @return A handle to a bf_write bit packing structure, or
101 * INVALID_HANDLE on failure.
102 * @error Invalid message name, unable to start a message, invalid client,
103 * or client not connected.
105 native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
108 * Starts a usermessage (network message).
109 * @note Only one message can be active at a time.
110 * @note It is illegal to send any message while a non-intercept hook is in progress.
112 * @param msg Message index to start.
113 * @param clients Array containing player indexes to broadcast to.
114 * @param numClients Number of players in the array.
115 * @param flags Optional flags to set.
116 * @return A handle to a bf_write bit packing structure, or
117 * INVALID_HANDLE on failure.
118 * @error Invalid message name, unable to start a message, invalid client,
119 * or client not connected.
121 native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
124 * Ends a previously started user message (network message).
131 * Called when a message is hooked
133 * @param msg_id Message index.
134 * @param msg Handle to the input bit buffer or protobuf.
135 * @param players Array containing player indexes.
136 * @param playersNum Number of players in the array.
137 * @param reliable True if message is reliable, false otherwise.
138 * @param init True if message is an initmsg, false otherwise.
139 * @return Ignored for normal hooks. For intercept hooks, Plugin_Handled
140 * blocks the message from being sent, and Plugin_Continue
141 * resumes normal functionality.
143 functag public Action:MsgHook(UserMsg:msg_id, Handle:msg, const players[], playersNum, bool:reliable, bool:init);
146 * Called when a message hook has completed.
148 * @param msg_id Message index.
149 * @param sent True if message was sent, false if blocked.
151 functag public MsgPostHook(UserMsg:msg_id, bool:sent);
154 * Hooks a user message.
156 * @param msg_id Message index.
157 * @param hook Function to use as a hook.
158 * @param intercept If intercept is true, message will be fully intercepted,
159 * allowing the user to block the message. Otherwise,
160 * the hook is normal and ignores the return value.
161 * @param post Notification function.
163 * @error Invalid message index.
165 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgPostHook:post=MsgPostHook:-1);
168 * Removes one usermessage hook.
170 * @param msg_id Message index.
171 * @param hook Function used for the hook.
172 * @param intercept Specifies whether the hook was an intercept hook or not.
174 * @error Invalid message index.
176 native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
179 * Starts a usermessage (network message) that broadcasts to all clients.
180 * @note See StartMessage or StartMessageEx().
182 * @param msgname Message name to start.
183 * @param flags Optional flags to set.
184 * @return A handle to a bf_write bit packing structure, or
185 * INVALID_HANDLE on failure.
187 stock Handle:StartMessageAll(String:msgname[], flags=0)
190 new clients[MaxClients];
191 for (new i=1; i<=MaxClients; i++)
193 if (IsClientConnected(i))
195 clients[total++] = i;
198 return StartMessage(msgname, clients, total, flags);
202 * Starts a simpler usermessage (network message) for one client.
203 * @note See StartMessage or StartMessageEx().
205 * @param msgname Message name to start.
206 * @param client Client to send to.
207 * @param flags Optional flags to set.
208 * @return A handle to a bf_write bit packing structure, or
209 * INVALID_HANDLE on failure.
211 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
217 return StartMessage(msgname, players, 1, flags);