plugins/include/usermessages.inc
author Nicholas Hastings <skamonkey@gmail.com>
Sun Mar 17 11:39:04 2013 -0400 (2013-03-17)
changeset 3833 7563b32966af
parent 3743 a98686a77974
child 3967 ceafb87d38a7
permissions -rw-r--r--
Moved PCRE_STATIC def in Regex ext to extension instead of modifying pcre header (bug 5593).
faluco@505
     1
/**
faluco@505
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
ds@1947
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     5
 * =============================================================================
ds@1330
     6
 *
ds@1330
     7
 * This file is part of the SourceMod/SourcePawn SDK.
faluco@505
     8
 *
ds@1330
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    11
 * Free Software Foundation.
ds@1330
    12
 * 
ds@1330
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    16
 * details.
ds@1330
    17
 *
ds@1330
    18
 * You should have received a copy of the GNU General Public License along with
ds@1330
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1330
    20
 *
ds@1330
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    28
 * or <http://www.sourcemod.net/license.php>.
faluco@505
    29
 *
faluco@505
    30
 * Version: $Id$
faluco@505
    31
 */
faluco@505
    32
 
faluco@505
    33
#if defined _eventsmsgs_included
faluco@505
    34
 #endinput
faluco@505
    35
#endif
faluco@505
    36
#define _eventsmsgs_included
faluco@505
    37
dvander@619
    38
/**
dvander@619
    39
 * UserMsg helper values.
dvander@619
    40
 */
faluco@505
    41
enum UserMsg
faluco@505
    42
{
faluco@505
    43
	INVALID_MESSAGE_ID = -1,
faluco@505
    44
};
faluco@505
    45
faluco@1040
    46
/**
skamonkey@3743
    47
 * UserMsg message serialization formats
skamonkey@3743
    48
 */
skamonkey@3743
    49
enum UserMessageType
skamonkey@3743
    50
{
skamonkey@3743
    51
	UM_BitBuf = 0,
skamonkey@3743
    52
	UM_Protobuf,
skamonkey@3743
    53
};
skamonkey@3743
    54
skamonkey@3743
    55
/**
faluco@1040
    56
 * @section Message Flags.
faluco@1040
    57
 */
dvander@716
    58
#define USERMSG_RELIABLE		(1<<2)		/**< Message will be set on the reliable stream */
faluco@505
    59
#define USERMSG_INITMSG			(1<<3)		/**< Message will be considered to be an initmsg */
ds@1268
    60
#define USERMSG_BLOCKHOOKS		(1<<7)		/**< Prevents the message from triggering SourceMod and Metamod hooks */
ds@1268
    61
faluco@505
    62
/**
faluco@1040
    63
 * @endsection
faluco@1040
    64
 */
faluco@1040
    65
faluco@1040
    66
/**
skamonkey@3743
    67
 * Returns usermessage serialization type used for the current engine
skamonkey@3743
    68
 *
skamonkey@3743
    69
 * @return				The supported usermessage type.
skamonkey@3743
    70
 */
skamonkey@3743
    71
native UserMessageType:GetUserMessageType();
skamonkey@3743
    72
skamonkey@3743
    73
/**
faluco@505
    74
 * Returns the ID of a given message, or -1 on failure.
faluco@505
    75
 *
faluco@505
    76
 * @param msg			String containing message name (case sensitive).
faluco@505
    77
 * @return				A message index, or INVALID_MESSAGE_ID on failure.
faluco@505
    78
 */
faluco@505
    79
native UserMsg:GetUserMessageId(const String:msg[]);
faluco@505
    80
faluco@505
    81
/**
ds@512
    82
 * Retrieves the name of a message by ID.
ds@512
    83
 *
ds@512
    84
 * @param msg_id		Message index.
ds@512
    85
 * @param msg			Buffer to store the name of the message.
ds@512
    86
 * @param maxlength		Maximum length of string buffer.
ds@512
    87
 * @return				True if message index is valid, false otherwise.
ds@512
    88
 */
ds@512
    89
native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
ds@512
    90
ds@512
    91
/**
faluco@505
    92
 * Starts a usermessage (network message).
faluco@505
    93
 * @note Only one message can be active at a time.
dvander@508
    94
 * @note It is illegal to send any message while a non-intercept hook is in progress.
faluco@505
    95
 *
faluco@505
    96
 * @param msgname		Message name to start.
faluco@505
    97
 * @param clients		Array containing player indexes to broadcast to.
faluco@505
    98
 * @param numClients	Number of players in the array.
ds@621
    99
 * @param flags			Optional flags to set.
faluco@505
   100
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   101
 *						INVALID_HANDLE on failure.
ds@2112
   102
 * @error				Invalid message name, unable to start a message, invalid client,
ds@2112
   103
 *						or client not connected.
faluco@505
   104
 */
ds@621
   105
native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
faluco@505
   106
faluco@505
   107
/**
faluco@505
   108
 * Starts a usermessage (network message).
faluco@505
   109
 * @note Only one message can be active at a time.
dvander@508
   110
 * @note It is illegal to send any message while a non-intercept hook is in progress.
faluco@505
   111
 *
faluco@505
   112
 * @param msg			Message index to start.
faluco@505
   113
 * @param clients		Array containing player indexes to broadcast to.
faluco@505
   114
 * @param numClients	Number of players in the array.
ds@621
   115
 * @param flags			Optional flags to set.
faluco@505
   116
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   117
 *						INVALID_HANDLE on failure.
ds@2112
   118
 * @error				Invalid message name, unable to start a message, invalid client,
ds@2112
   119
 *						or client not connected.
faluco@505
   120
 */
ds@621
   121
native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
faluco@505
   122
faluco@505
   123
/**
faluco@505
   124
 * Ends a previously started user message (network message).
faluco@505
   125
 *
faluco@505
   126
 * @noreturn
faluco@505
   127
 */
faluco@505
   128
native EndMessage();
faluco@505
   129
faluco@505
   130
/**
dvander@812
   131
 * Called when a message is hooked
dvander@508
   132
 *
dvander@508
   133
 * @param msg_id		Message index.
skamonkey@3743
   134
 * @param msg			Handle to the input bit buffer or protobuf.
dvander@508
   135
 * @param players		Array containing player indexes.
dvander@508
   136
 * @param playersNum	Number of players in the array.
dvander@508
   137
 * @param reliable		True if message is reliable, false otherwise.
dvander@508
   138
 * @param init			True if message is an initmsg, false otherwise.
dvander@1394
   139
 * @return				Ignored for normal hooks.  For intercept hooks, Plugin_Handled 
dvander@1394
   140
 *						blocks the message from being sent, and Plugin_Continue 
dvander@1394
   141
 *						resumes normal functionality.
dvander@508
   142
 */
skamonkey@3743
   143
functag public Action:MsgHook(UserMsg:msg_id, Handle:msg, const players[], playersNum, bool:reliable, bool:init);
faluco@552
   144
faluco@552
   145
/**
dvander@2636
   146
 * Called when a message hook has completed.
faluco@552
   147
 *
faluco@552
   148
 * @param msg_id		Message index.
dvander@2636
   149
 * @param sent			True if message was sent, false if blocked.
faluco@552
   150
 */
dvander@2636
   151
functag public MsgPostHook(UserMsg:msg_id, bool:sent);
dvander@508
   152
dvander@508
   153
/**
dvander@812
   154
 * Hooks a user message.
dvander@508
   155
 *
dvander@508
   156
 * @param msg_id		Message index.
dvander@508
   157
 * @param hook			Function to use as a hook.
dvander@508
   158
 * @param intercept		If intercept is true, message will be fully intercepted,
dvander@508
   159
 * 						allowing the user to block the message.  Otherwise,
dvander@508
   160
 *						the hook is normal and ignores the return value.
faluco@552
   161
 * @param notify		Notification function.
dvander@508
   162
 * @noreturn
dvander@508
   163
 * @error				Invalid message index.
dvander@508
   164
 */
dvander@2636
   165
native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgPostHook:post=MsgPostHook:-1);
dvander@508
   166
dvander@508
   167
/**
dvander@812
   168
 * Removes one usermessage hook.
dvander@508
   169
 *
dvander@508
   170
 * @param msg_id		Message index.
dvander@508
   171
 * @param hook			Function used for the hook.
dvander@508
   172
 * @param intercept		Specifies whether the hook was an intercept hook or not.
dvander@508
   173
 * @noreturn
dvander@508
   174
 * @error				Invalid message index.
dvander@508
   175
 */
ds@626
   176
native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
dvander@508
   177
dvander@508
   178
/**
faluco@505
   179
 * Starts a usermessage (network message) that broadcasts to all clients.
dvander@508
   180
 * @note See StartMessage or StartMessageEx().
faluco@505
   181
 *
faluco@505
   182
 * @param msgname		Message name to start.
faluco@505
   183
 * @param flags			Optional flags to set.
faluco@505
   184
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   185
 *						INVALID_HANDLE on failure.
faluco@505
   186
 */
faluco@505
   187
stock Handle:StartMessageAll(String:msgname[], flags=0)
faluco@505
   188
{
faluco@505
   189
	new total = 0;
skamonkey@2920
   190
	new clients[MaxClients];
skamonkey@2920
   191
	for (new i=1; i<=MaxClients; i++)
faluco@505
   192
	{
faluco@505
   193
		if (IsClientConnected(i))
faluco@505
   194
		{
faluco@505
   195
			clients[total++] = i;
faluco@505
   196
		}
faluco@505
   197
	}
faluco@505
   198
	return StartMessage(msgname, clients, total, flags);
faluco@505
   199
}
faluco@505
   200
faluco@505
   201
/**
faluco@505
   202
 * Starts a simpler usermessage (network message) for one client.
dvander@508
   203
 * @note See StartMessage or StartMessageEx().
faluco@505
   204
 *
faluco@505
   205
 * @param msgname		Message name to start.
faluco@505
   206
 * @param client		Client to send to.
faluco@505
   207
 * @param flags			Optional flags to set.
faluco@505
   208
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   209
 *						INVALID_HANDLE on failure.
faluco@505
   210
 */
faluco@505
   211
stock Handle:StartMessageOne(String:msgname[], client, flags=0)
faluco@505
   212
{
faluco@505
   213
	new players[1];
faluco@505
   214
	
faluco@505
   215
	players[0] = client;
faluco@505
   216
	
faluco@505
   217
	return StartMessage(msgname, players, 1, flags);
faluco@505
   218
}