|
faluco@505
|
1 |
/** |
|
faluco@505
|
2 |
* vim: set ts=4 : |
|
faluco@505
|
3 |
* =============================================================== |
|
faluco@505
|
4 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
faluco@505
|
5 |
* =============================================================== |
|
faluco@505
|
6 |
* |
|
faluco@505
|
7 |
* This file is part of the SourceMod/SourcePawn SDK. This file may only be used |
|
faluco@505
|
8 |
* or modified under the Terms and Conditions of its License Agreement, which is found |
|
faluco@505
|
9 |
* in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins |
|
faluco@505
|
10 |
* may change at any time. To view the latest information, see: |
|
faluco@505
|
11 |
* http://www.sourcemod.net/license.php |
|
faluco@505
|
12 |
* |
|
faluco@505
|
13 |
* Version: $Id$ |
|
faluco@505
|
14 |
*/ |
|
faluco@505
|
15 |
|
|
faluco@505
|
16 |
#if defined _eventsmsgs_included |
|
faluco@505
|
17 |
#endinput |
|
faluco@505
|
18 |
#endif |
|
faluco@505
|
19 |
#define _eventsmsgs_included |
|
faluco@505
|
20 |
|
|
dvander@619
|
21 |
/** |
|
dvander@619
|
22 |
* UserMsg helper values. |
|
dvander@619
|
23 |
*/ |
|
faluco@505
|
24 |
enum UserMsg |
|
faluco@505
|
25 |
{ |
|
faluco@505
|
26 |
INVALID_MESSAGE_ID = -1, |
|
faluco@505
|
27 |
}; |
|
faluco@505
|
28 |
|
|
faluco@505
|
29 |
#define USERMSG_PASSTHRU (1<<0) /**< Message will pass through other SourceMM plugins */ |
|
faluco@505
|
30 |
#define USERMSG_PASSTHRU_ALL (1<<1) /**< Message will pass through other SourceMM plugins AND SourceMod */ |
|
faluco@505
|
31 |
#define USERMSG_RELIABLE (1<<2) /**< Message will be set to reliable */ |
|
faluco@505
|
32 |
#define USERMSG_INITMSG (1<<3) /**< Message will be considered to be an initmsg */ |
|
faluco@505
|
33 |
|
|
faluco@505
|
34 |
/** |
|
faluco@505
|
35 |
* Returns the ID of a given message, or -1 on failure. |
|
faluco@505
|
36 |
* |
|
faluco@505
|
37 |
* @param msg String containing message name (case sensitive). |
|
faluco@505
|
38 |
* @return A message index, or INVALID_MESSAGE_ID on failure. |
|
faluco@505
|
39 |
*/ |
|
faluco@505
|
40 |
native UserMsg:GetUserMessageId(const String:msg[]); |
|
faluco@505
|
41 |
|
|
faluco@505
|
42 |
/** |
|
ds@512
|
43 |
* Retrieves the name of a message by ID. |
|
ds@512
|
44 |
* |
|
ds@512
|
45 |
* @param msg_id Message index. |
|
ds@512
|
46 |
* @param msg Buffer to store the name of the message. |
|
ds@512
|
47 |
* @param maxlength Maximum length of string buffer. |
|
ds@512
|
48 |
* @return True if message index is valid, false otherwise. |
|
ds@512
|
49 |
*/ |
|
ds@512
|
50 |
native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength); |
|
ds@512
|
51 |
|
|
ds@512
|
52 |
/** |
|
faluco@505
|
53 |
* Starts a usermessage (network message). |
|
faluco@505
|
54 |
* @note Only one message can be active at a time. |
|
dvander@508
|
55 |
* @note It is illegal to send any message while a non-intercept hook is in progress. |
|
faluco@505
|
56 |
* |
|
faluco@505
|
57 |
* @param msgname Message name to start. |
|
faluco@505
|
58 |
* @param clients Array containing player indexes to broadcast to. |
|
faluco@505
|
59 |
* @param numClients Number of players in the array. |
|
ds@621
|
60 |
* @param flags Optional flags to set. |
|
faluco@505
|
61 |
* @return A handle to a bf_write bit packing structure, or |
|
faluco@505
|
62 |
* INVALID_HANDLE on failure. |
|
dvander@508
|
63 |
* @error Invalid message name or unable to start a message. |
|
faluco@505
|
64 |
*/ |
|
ds@621
|
65 |
native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0); |
|
faluco@505
|
66 |
|
|
faluco@505
|
67 |
/** |
|
faluco@505
|
68 |
* Starts a usermessage (network message). |
|
faluco@505
|
69 |
* @note Only one message can be active at a time. |
|
dvander@508
|
70 |
* @note It is illegal to send any message while a non-intercept hook is in progress. |
|
faluco@505
|
71 |
* |
|
faluco@505
|
72 |
* @param msg Message index to start. |
|
faluco@505
|
73 |
* @param clients Array containing player indexes to broadcast to. |
|
faluco@505
|
74 |
* @param numClients Number of players in the array. |
|
ds@621
|
75 |
* @param flags Optional flags to set. |
|
faluco@505
|
76 |
* @return A handle to a bf_write bit packing structure, or |
|
faluco@505
|
77 |
* INVALID_HANDLE on failure. |
|
dvander@508
|
78 |
* @error Invalid message name or unable to start a message. |
|
faluco@505
|
79 |
*/ |
|
ds@621
|
80 |
native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0); |
|
faluco@505
|
81 |
|
|
faluco@505
|
82 |
/** |
|
faluco@505
|
83 |
* Ends a previously started user message (network message). |
|
faluco@505
|
84 |
* |
|
faluco@505
|
85 |
* @noreturn |
|
faluco@505
|
86 |
*/ |
|
faluco@505
|
87 |
native EndMessage(); |
|
faluco@505
|
88 |
|
|
faluco@505
|
89 |
/** |
|
dvander@508
|
90 |
* @brief Called when a message is hooked |
|
dvander@508
|
91 |
* |
|
dvander@508
|
92 |
* @param msg_id Message index. |
|
faluco@552
|
93 |
* @param bf Handle to the input bit buffer of the message. |
|
dvander@508
|
94 |
* @param players Array containing player indexes. |
|
dvander@508
|
95 |
* @param playersNum Number of players in the array. |
|
dvander@508
|
96 |
* @param reliable True if message is reliable, false otherwise. |
|
dvander@508
|
97 |
* @param init True if message is an initmsg, false otherwise. |
|
dvander@508
|
98 |
* @return Ignored for normal hooks. For intercept hooks, false blocks |
|
dvander@508
|
99 |
* the message from being sent, and true continues. |
|
dvander@508
|
100 |
*/ |
|
faluco@552
|
101 |
functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init); |
|
faluco@552
|
102 |
|
|
faluco@552
|
103 |
/** |
|
faluco@552
|
104 |
* @brief Called when a message is finished sending. |
|
faluco@552
|
105 |
* |
|
faluco@552
|
106 |
* @param msg_id Message index. |
|
faluco@552
|
107 |
*/ |
|
faluco@552
|
108 |
functag MsgSentNotify public(UserMsg:msg_id); |
|
dvander@508
|
109 |
|
|
dvander@508
|
110 |
/** |
|
dvander@508
|
111 |
* @brief Hooks a user message. |
|
dvander@508
|
112 |
* |
|
dvander@508
|
113 |
* @param msg_id Message index. |
|
dvander@508
|
114 |
* @param hook Function to use as a hook. |
|
dvander@508
|
115 |
* @param intercept If intercept is true, message will be fully intercepted, |
|
dvander@508
|
116 |
* allowing the user to block the message. Otherwise, |
|
dvander@508
|
117 |
* the hook is normal and ignores the return value. |
|
faluco@552
|
118 |
* @param notify Notification function. |
|
dvander@508
|
119 |
* @noreturn |
|
dvander@508
|
120 |
* @error Invalid message index. |
|
dvander@508
|
121 |
*/ |
|
faluco@552
|
122 |
native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1); |
|
dvander@508
|
123 |
|
|
dvander@508
|
124 |
/** |
|
dvander@508
|
125 |
* @brief Removes one usermessage hook. |
|
dvander@508
|
126 |
* |
|
dvander@508
|
127 |
* @param msg_id Message index. |
|
dvander@508
|
128 |
* @param hook Function used for the hook. |
|
dvander@508
|
129 |
* @param intercept Specifies whether the hook was an intercept hook or not. |
|
dvander@508
|
130 |
* @noreturn |
|
dvander@508
|
131 |
* @error Invalid message index. |
|
dvander@508
|
132 |
*/ |
|
ds@626
|
133 |
native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false); |
|
dvander@508
|
134 |
|
|
dvander@508
|
135 |
/** |
|
faluco@505
|
136 |
* Starts a usermessage (network message) that broadcasts to all clients. |
|
dvander@508
|
137 |
* @note See StartMessage or StartMessageEx(). |
|
faluco@505
|
138 |
* |
|
faluco@505
|
139 |
* @param msgname Message name to start. |
|
faluco@505
|
140 |
* @param flags Optional flags to set. |
|
faluco@505
|
141 |
* @return A handle to a bf_write bit packing structure, or |
|
faluco@505
|
142 |
* INVALID_HANDLE on failure. |
|
faluco@505
|
143 |
*/ |
|
faluco@505
|
144 |
stock Handle:StartMessageAll(String:msgname[], flags=0) |
|
faluco@505
|
145 |
{ |
|
faluco@505
|
146 |
new maxClients = GetMaxClients(); |
|
faluco@505
|
147 |
new total = 0; |
|
faluco@505
|
148 |
new clients[maxClients]; |
|
faluco@505
|
149 |
for (new i=1; i<=maxClients; i++) |
|
faluco@505
|
150 |
{ |
|
faluco@505
|
151 |
if (IsClientConnected(i)) |
|
faluco@505
|
152 |
{ |
|
faluco@505
|
153 |
clients[total++] = i; |
|
faluco@505
|
154 |
} |
|
faluco@505
|
155 |
} |
|
faluco@505
|
156 |
return StartMessage(msgname, clients, total, flags); |
|
faluco@505
|
157 |
} |
|
faluco@505
|
158 |
|
|
faluco@505
|
159 |
/** |
|
faluco@505
|
160 |
* Starts a simpler usermessage (network message) for one client. |
|
dvander@508
|
161 |
* @note See StartMessage or StartMessageEx(). |
|
faluco@505
|
162 |
* |
|
faluco@505
|
163 |
* @param msgname Message name to start. |
|
faluco@505
|
164 |
* @param client Client to send to. |
|
faluco@505
|
165 |
* @param flags Optional flags to set. |
|
faluco@505
|
166 |
* @return A handle to a bf_write bit packing structure, or |
|
faluco@505
|
167 |
* INVALID_HANDLE on failure. |
|
faluco@505
|
168 |
*/ |
|
faluco@505
|
169 |
stock Handle:StartMessageOne(String:msgname[], client, flags=0) |
|
faluco@505
|
170 |
{ |
|
faluco@505
|
171 |
new players[1]; |
|
faluco@505
|
172 |
|
|
faluco@505
|
173 |
players[0] = client; |
|
faluco@505
|
174 |
|
|
faluco@505
|
175 |
return StartMessage(msgname, players, 1, flags); |
|
faluco@505
|
176 |
} |