plugins/include/usermessages.inc
author David Anderson <dvander@alliedmods.net>
Tue Jan 22 16:47:10 2008 +0000 (2008-01-22)
changeset 1853 b046cf080755
parent 1394 2885e3f90a88
child 1937 b1d373d7c127
permissions -rw-r--r--
fire requires timebomb
faluco@505
     1
/**
faluco@505
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
faluco@505
     4
 * SourceMod (C)2004-2007 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
/**
faluco@1040
    47
 * @section Message Flags.
faluco@1040
    48
 */
dvander@716
    49
#define USERMSG_RELIABLE		(1<<2)		/**< Message will be set on the reliable stream */
faluco@505
    50
#define USERMSG_INITMSG			(1<<3)		/**< Message will be considered to be an initmsg */
ds@1268
    51
#define USERMSG_BLOCKHOOKS		(1<<7)		/**< Prevents the message from triggering SourceMod and Metamod hooks */
ds@1268
    52
ds@1268
    53
#pragma deprecated Constant has no effect
ds@1268
    54
#define USERMSG_PASSTHRU		(1<<0)		/**< (DEPRECATED, NO EFFECT) */
ds@1268
    55
#pragma deprecated Constant has no effect
ds@1268
    56
#define USERMSG_PASSTHRU_ALL	(1<<1)		/**< (DEPRECATED, NO EFFECT) */
ds@1268
    57
#pragma deprecated Constant has no effect
faluco@1250
    58
#define USERMSG_BLOCK_MM		(1<<4)		/**< (DEPRECATED, NO EFFECT) */
ds@1268
    59
#pragma deprecated Constant has no effect
faluco@1250
    60
#define USERMSG_BLOCK_SM		(1<<5)		/**< (DEPRECATED, NO EFFECT) */
ds@1268
    61
#pragma deprecated Constant has no effect
faluco@1250
    62
#define USERMSG_BLOCK_ALL		(1<<6)		/**< (DEPRECATED, NO EFFECT) */
faluco@505
    63
faluco@505
    64
/**
faluco@1040
    65
 * @endsection
faluco@1040
    66
 */
faluco@1040
    67
faluco@1040
    68
/**
faluco@505
    69
 * Returns the ID of a given message, or -1 on failure.
faluco@505
    70
 *
faluco@505
    71
 * @param msg			String containing message name (case sensitive).
faluco@505
    72
 * @return				A message index, or INVALID_MESSAGE_ID on failure.
faluco@505
    73
 */
faluco@505
    74
native UserMsg:GetUserMessageId(const String:msg[]);
faluco@505
    75
faluco@505
    76
/**
ds@512
    77
 * Retrieves the name of a message by ID.
ds@512
    78
 *
ds@512
    79
 * @param msg_id		Message index.
ds@512
    80
 * @param msg			Buffer to store the name of the message.
ds@512
    81
 * @param maxlength		Maximum length of string buffer.
ds@512
    82
 * @return				True if message index is valid, false otherwise.
ds@512
    83
 */
ds@512
    84
native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
ds@512
    85
ds@512
    86
/**
faluco@505
    87
 * Starts a usermessage (network message).
faluco@505
    88
 * @note Only one message can be active at a time.
dvander@508
    89
 * @note It is illegal to send any message while a non-intercept hook is in progress.
faluco@505
    90
 *
faluco@505
    91
 * @param msgname		Message name to start.
faluco@505
    92
 * @param clients		Array containing player indexes to broadcast to.
faluco@505
    93
 * @param numClients	Number of players in the array.
ds@621
    94
 * @param flags			Optional flags to set.
faluco@505
    95
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
    96
 *						INVALID_HANDLE on failure.
dvander@508
    97
 * @error				Invalid message name or unable to start a message.
faluco@505
    98
 */
ds@621
    99
native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
faluco@505
   100
faluco@505
   101
/**
faluco@505
   102
 * Starts a usermessage (network message).
faluco@505
   103
 * @note Only one message can be active at a time.
dvander@508
   104
 * @note It is illegal to send any message while a non-intercept hook is in progress.
faluco@505
   105
 *
faluco@505
   106
 * @param msg			Message index to start.
faluco@505
   107
 * @param clients		Array containing player indexes to broadcast to.
faluco@505
   108
 * @param numClients	Number of players in the array.
ds@621
   109
 * @param flags			Optional flags to set.
faluco@505
   110
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   111
 *						INVALID_HANDLE on failure.
dvander@508
   112
 * @error				Invalid message name or unable to start a message.
faluco@505
   113
 */
ds@621
   114
native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
faluco@505
   115
faluco@505
   116
/**
faluco@505
   117
 * Ends a previously started user message (network message).
faluco@505
   118
 *
faluco@505
   119
 * @noreturn
faluco@505
   120
 */
faluco@505
   121
native EndMessage();
faluco@505
   122
faluco@505
   123
/**
dvander@812
   124
 * Called when a message is hooked
dvander@508
   125
 *
dvander@508
   126
 * @param msg_id		Message index.
faluco@552
   127
 * @param bf			Handle to the input bit buffer of the message.
dvander@508
   128
 * @param players		Array containing player indexes.
dvander@508
   129
 * @param playersNum	Number of players in the array.
dvander@508
   130
 * @param reliable		True if message is reliable, false otherwise.
dvander@508
   131
 * @param init			True if message is an initmsg, false otherwise.
dvander@1394
   132
 * @return				Ignored for normal hooks.  For intercept hooks, Plugin_Handled 
dvander@1394
   133
 *						blocks the message from being sent, and Plugin_Continue 
dvander@1394
   134
 *						resumes normal functionality.
dvander@508
   135
 */
faluco@552
   136
functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
faluco@552
   137
faluco@552
   138
/**
dvander@812
   139
 * Called when a message is finished sending.
faluco@552
   140
 *
faluco@552
   141
 * @param msg_id		Message index.
faluco@552
   142
 */
faluco@552
   143
functag MsgSentNotify public(UserMsg:msg_id);
dvander@508
   144
dvander@508
   145
/**
dvander@812
   146
 * Hooks a user message.
dvander@508
   147
 *
dvander@508
   148
 * @param msg_id		Message index.
dvander@508
   149
 * @param hook			Function to use as a hook.
dvander@508
   150
 * @param intercept		If intercept is true, message will be fully intercepted,
dvander@508
   151
 * 						allowing the user to block the message.  Otherwise,
dvander@508
   152
 *						the hook is normal and ignores the return value.
faluco@552
   153
 * @param notify		Notification function.
dvander@508
   154
 * @noreturn
dvander@508
   155
 * @error				Invalid message index.
dvander@508
   156
 */
faluco@552
   157
native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1);
dvander@508
   158
dvander@508
   159
/**
dvander@812
   160
 * Removes one usermessage hook.
dvander@508
   161
 *
dvander@508
   162
 * @param msg_id		Message index.
dvander@508
   163
 * @param hook			Function used for the hook.
dvander@508
   164
 * @param intercept		Specifies whether the hook was an intercept hook or not.
dvander@508
   165
 * @noreturn
dvander@508
   166
 * @error				Invalid message index.
dvander@508
   167
 */
ds@626
   168
native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
dvander@508
   169
dvander@508
   170
/**
faluco@505
   171
 * Starts a usermessage (network message) that broadcasts to all clients.
dvander@508
   172
 * @note See StartMessage or StartMessageEx().
faluco@505
   173
 *
faluco@505
   174
 * @param msgname		Message name to start.
faluco@505
   175
 * @param flags			Optional flags to set.
faluco@505
   176
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   177
 *						INVALID_HANDLE on failure.
faluco@505
   178
 */
faluco@505
   179
stock Handle:StartMessageAll(String:msgname[], flags=0)
faluco@505
   180
{
faluco@505
   181
	new maxClients = GetMaxClients();
faluco@505
   182
	new total = 0;
faluco@505
   183
	new clients[maxClients];
faluco@505
   184
	for (new i=1; i<=maxClients; i++)
faluco@505
   185
	{
faluco@505
   186
		if (IsClientConnected(i))
faluco@505
   187
		{
faluco@505
   188
			clients[total++] = i;
faluco@505
   189
		}
faluco@505
   190
	}
faluco@505
   191
	return StartMessage(msgname, clients, total, flags);
faluco@505
   192
}
faluco@505
   193
faluco@505
   194
/**
faluco@505
   195
 * Starts a simpler usermessage (network message) for one client.
dvander@508
   196
 * @note See StartMessage or StartMessageEx().
faluco@505
   197
 *
faluco@505
   198
 * @param msgname		Message name to start.
faluco@505
   199
 * @param client		Client to send to.
faluco@505
   200
 * @param flags			Optional flags to set.
faluco@505
   201
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   202
 *						INVALID_HANDLE on failure.
faluco@505
   203
 */
faluco@505
   204
stock Handle:StartMessageOne(String:msgname[], client, flags=0)
faluco@505
   205
{
faluco@505
   206
	new players[1];
faluco@505
   207
	
faluco@505
   208
	players[0] = client;
faluco@505
   209
	
faluco@505
   210
	return StartMessage(msgname, players, 1, flags);
faluco@505
   211
}