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