plugins/include/usermessages.inc
author Nicholas Hastings <skamonkey@gmail.com>
Fri May 28 13:28:04 2010 -0400 (2010-05-28)
changeset 3024 eb551a6b1c4a
parent 2920 1d5645ab7ae0
child 3743 a98686a77974
permissions -rw-r--r--
Updated/fixed SourceForts gamedata (bug 4429, r=fyren)
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.
ds@2112
    86
 * @error				Invalid message name, unable to start a message, invalid client,
ds@2112
    87
 *						or client not connected.
faluco@505
    88
 */
ds@621
    89
native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
faluco@505
    90
faluco@505
    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 msg			Message index 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:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
faluco@505
   106
faluco@505
   107
/**
faluco@505
   108
 * Ends a previously started user message (network message).
faluco@505
   109
 *
faluco@505
   110
 * @noreturn
faluco@505
   111
 */
faluco@505
   112
native EndMessage();
faluco@505
   113
faluco@505
   114
/**
dvander@812
   115
 * Called when a message is hooked
dvander@508
   116
 *
dvander@508
   117
 * @param msg_id		Message index.
faluco@552
   118
 * @param bf			Handle to the input bit buffer of the message.
dvander@508
   119
 * @param players		Array containing player indexes.
dvander@508
   120
 * @param playersNum	Number of players in the array.
dvander@508
   121
 * @param reliable		True if message is reliable, false otherwise.
dvander@508
   122
 * @param init			True if message is an initmsg, false otherwise.
dvander@1394
   123
 * @return				Ignored for normal hooks.  For intercept hooks, Plugin_Handled 
dvander@1394
   124
 *						blocks the message from being sent, and Plugin_Continue 
dvander@1394
   125
 *						resumes normal functionality.
dvander@508
   126
 */
dvander@2317
   127
functag public Action:MsgHook(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
faluco@552
   128
faluco@552
   129
/**
dvander@2636
   130
 * Called when a message hook has completed.
faluco@552
   131
 *
faluco@552
   132
 * @param msg_id		Message index.
dvander@2636
   133
 * @param sent			True if message was sent, false if blocked.
faluco@552
   134
 */
dvander@2636
   135
functag public MsgPostHook(UserMsg:msg_id, bool:sent);
dvander@508
   136
dvander@508
   137
/**
dvander@812
   138
 * Hooks a user message.
dvander@508
   139
 *
dvander@508
   140
 * @param msg_id		Message index.
dvander@508
   141
 * @param hook			Function to use as a hook.
dvander@508
   142
 * @param intercept		If intercept is true, message will be fully intercepted,
dvander@508
   143
 * 						allowing the user to block the message.  Otherwise,
dvander@508
   144
 *						the hook is normal and ignores the return value.
faluco@552
   145
 * @param notify		Notification function.
dvander@508
   146
 * @noreturn
dvander@508
   147
 * @error				Invalid message index.
dvander@508
   148
 */
dvander@2636
   149
native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgPostHook:post=MsgPostHook:-1);
dvander@508
   150
dvander@508
   151
/**
dvander@812
   152
 * Removes one usermessage hook.
dvander@508
   153
 *
dvander@508
   154
 * @param msg_id		Message index.
dvander@508
   155
 * @param hook			Function used for the hook.
dvander@508
   156
 * @param intercept		Specifies whether the hook was an intercept hook or not.
dvander@508
   157
 * @noreturn
dvander@508
   158
 * @error				Invalid message index.
dvander@508
   159
 */
ds@626
   160
native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
dvander@508
   161
dvander@508
   162
/**
faluco@505
   163
 * Starts a usermessage (network message) that broadcasts to all clients.
dvander@508
   164
 * @note See StartMessage or StartMessageEx().
faluco@505
   165
 *
faluco@505
   166
 * @param msgname		Message name to start.
faluco@505
   167
 * @param flags			Optional flags to set.
faluco@505
   168
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   169
 *						INVALID_HANDLE on failure.
faluco@505
   170
 */
faluco@505
   171
stock Handle:StartMessageAll(String:msgname[], flags=0)
faluco@505
   172
{
faluco@505
   173
	new total = 0;
skamonkey@2920
   174
	new clients[MaxClients];
skamonkey@2920
   175
	for (new i=1; i<=MaxClients; i++)
faluco@505
   176
	{
faluco@505
   177
		if (IsClientConnected(i))
faluco@505
   178
		{
faluco@505
   179
			clients[total++] = i;
faluco@505
   180
		}
faluco@505
   181
	}
faluco@505
   182
	return StartMessage(msgname, clients, total, flags);
faluco@505
   183
}
faluco@505
   184
faluco@505
   185
/**
faluco@505
   186
 * Starts a simpler usermessage (network message) for one client.
dvander@508
   187
 * @note See StartMessage or StartMessageEx().
faluco@505
   188
 *
faluco@505
   189
 * @param msgname		Message name to start.
faluco@505
   190
 * @param client		Client to send to.
faluco@505
   191
 * @param flags			Optional flags to set.
faluco@505
   192
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   193
 *						INVALID_HANDLE on failure.
faluco@505
   194
 */
faluco@505
   195
stock Handle:StartMessageOne(String:msgname[], client, flags=0)
faluco@505
   196
{
faluco@505
   197
	new players[1];
faluco@505
   198
	
faluco@505
   199
	players[0] = client;
faluco@505
   200
	
faluco@505
   201
	return StartMessage(msgname, players, 1, flags);
faluco@505
   202
}