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