plugins/include/usermessages.inc
author David Anderson <dvander@alliedmods.net>
Fri Feb 16 20:07:40 2007 +0000 (2007-02-16)
changeset 508 5ce8b28b29c4
parent 505 9fb8a1ccd4ec
child 512 44bc3fc6404c
permissions -rw-r--r--
spec'd out more of the message hooking stuff
faluco@505
     1
/**
faluco@505
     2
 * vim: set ts=4 :
faluco@505
     3
 * ===============================================================
faluco@505
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
faluco@505
     5
 * ===============================================================
faluco@505
     6
 *
faluco@505
     7
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
faluco@505
     8
 * or modified under the Terms and Conditions of its License Agreement, which is found 
faluco@505
     9
 * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
faluco@505
    10
 * may change at any time.  To view the latest information, see:
faluco@505
    11
 *   http://www.sourcemod.net/license.php
faluco@505
    12
 *
faluco@505
    13
 * Version: $Id$
faluco@505
    14
 */
faluco@505
    15
 
faluco@505
    16
#if defined _eventsmsgs_included
faluco@505
    17
 #endinput
faluco@505
    18
#endif
faluco@505
    19
#define _eventsmsgs_included
faluco@505
    20
faluco@505
    21
enum UserMsg
faluco@505
    22
{
faluco@505
    23
	INVALID_MESSAGE_ID = -1,
faluco@505
    24
};
faluco@505
    25
faluco@505
    26
#define USERMSG_PASSTHRU		(1<<0)		/**< Message will pass through other SourceMM plugins */
faluco@505
    27
#define USERMSG_PASSTHRU_ALL	(1<<1)		/**< Message will pass through other SourceMM plugins AND SourceMod */
faluco@505
    28
#define USERMSG_RELIABLE		(1<<2)		/**< Message will be set to reliable */
faluco@505
    29
#define USERMSG_INITMSG			(1<<3)		/**< Message will be considered to be an initmsg */
faluco@505
    30
faluco@505
    31
/**
faluco@505
    32
 * Returns the ID of a given message, or -1 on failure.
faluco@505
    33
 *
faluco@505
    34
 * @param msg			String containing message name (case sensitive).
faluco@505
    35
 * @return				A message index, or INVALID_MESSAGE_ID on failure.
faluco@505
    36
 */
faluco@505
    37
native UserMsg:GetUserMessageId(const String:msg[]);
faluco@505
    38
faluco@505
    39
/**
faluco@505
    40
 * Starts a usermessage (network message).
faluco@505
    41
 * @note Only one message can be active at a time.
dvander@508
    42
 * @note It is illegal to send any message while a non-intercept hook is in progress.
faluco@505
    43
 *
faluco@505
    44
 * @param msgname		Message name to start.
faluco@505
    45
 * @param clients		Array containing player indexes to broadcast to.
faluco@505
    46
 * @param numClients	Number of players in the array.
faluco@505
    47
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
    48
 *						INVALID_HANDLE on failure.
dvander@508
    49
 * @error				Invalid message name or unable to start a message.
faluco@505
    50
 */
faluco@505
    51
native Handle:StartMessage(String:msgname[], clients[], numClients, flags);
faluco@505
    52
faluco@505
    53
/**
faluco@505
    54
 * Starts a usermessage (network message).
faluco@505
    55
 * @note Only one message can be active at a time.
dvander@508
    56
 * @note It is illegal to send any message while a non-intercept hook is in progress.
faluco@505
    57
 *
faluco@505
    58
 * @param msg			Message index to start.
faluco@505
    59
 * @param clients		Array containing player indexes to broadcast to.
faluco@505
    60
 * @param numClients	Number of players in the array.
faluco@505
    61
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
    62
 *						INVALID_HANDLE on failure.
dvander@508
    63
 * @error				Invalid message name or unable to start a message.
faluco@505
    64
 */
faluco@505
    65
native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags);
faluco@505
    66
faluco@505
    67
/**
faluco@505
    68
 * Ends a previously started user message (network message).
faluco@505
    69
 *
faluco@505
    70
 * @noreturn
faluco@505
    71
 */
faluco@505
    72
native EndMessage();
faluco@505
    73
faluco@505
    74
/**
dvander@508
    75
 * @brief Called when a message is hooked
dvander@508
    76
 *
dvander@508
    77
 * @param msg_id		Message index.
dvander@508
    78
 * @param players		Array containing player indexes.
dvander@508
    79
 * @param playersNum	Number of players in the array.
dvander@508
    80
 * @param reliable		True if message is reliable, false otherwise.
dvander@508
    81
 * @param init			True if message is an initmsg, false otherwise.
dvander@508
    82
 * @return				Ignored for normal hooks.  For intercept hooks, false blocks 
dvander@508
    83
 *						the message from being sent, and true continues.
dvander@508
    84
 */
dvander@508
    85
functag MsgHook bool:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
dvander@508
    86
dvander@508
    87
/**
dvander@508
    88
 * @brief Hooks a user message.
dvander@508
    89
 *
dvander@508
    90
 * @param msg_id		Message index.
dvander@508
    91
 * @param hook			Function to use as a hook.
dvander@508
    92
 * @param intercept		If intercept is true, message will be fully intercepted,
dvander@508
    93
 * 						allowing the user to block the message.  Otherwise,
dvander@508
    94
 *						the hook is normal and ignores the return value.
dvander@508
    95
 * @noreturn
dvander@508
    96
 * @error				Invalid message index.
dvander@508
    97
 */
dvander@508
    98
native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
dvander@508
    99
dvander@508
   100
/**
dvander@508
   101
 * @brief Removes one usermessage hook.
dvander@508
   102
 *
dvander@508
   103
 * @param msg_id		Message index.
dvander@508
   104
 * @param hook			Function used for the hook.
dvander@508
   105
 * @param intercept		Specifies whether the hook was an intercept hook or not.
dvander@508
   106
 * @noreturn
dvander@508
   107
 * @error				Invalid message index.
dvander@508
   108
 */
dvander@508
   109
native UnHookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
dvander@508
   110
dvander@508
   111
/**
dvander@508
   112
 * @brief Called when a message is finished sending.
dvander@508
   113
 *
dvander@508
   114
 * @param msg_id		Message index.
dvander@508
   115
 */
dvander@508
   116
functag MsgSentNotify public(UserMsg:msg_id);
dvander@508
   117
dvander@508
   118
/**
dvander@508
   119
 * @brief Notifies when a message has finished sending.
dvander@508
   120
 *
dvander@508
   121
 * @param msg_id		Message index.
dvander@508
   122
 * @param notify		Notification function.
dvander@508
   123
 * @noreturn
dvander@508
   124
 * @error				Invalid message index.
dvander@508
   125
 */
dvander@508
   126
native NotifyUserMessage(UserMsg:msg_id, MsgSentNotify:notify);
dvander@508
   127
dvander@508
   128
/**
dvander@508
   129
 * @brief Removes a user message notification.
dvander@508
   130
 *
dvander@508
   131
 * @param msg_id		Message index.
dvander@508
   132
 * @param notify		Notification function.
dvander@508
   133
 * @noreturn
dvander@508
   134
 * @error				Invalid message index.
dvander@508
   135
 */
dvander@508
   136
native RemoveNotifyUserMessage(UserMsg:msg_id, MsgSentNotify:notify);
dvander@508
   137
dvander@508
   138
/**
faluco@505
   139
 * Starts a usermessage (network message) that broadcasts to all clients.
dvander@508
   140
 * @note See StartMessage or StartMessageEx().
faluco@505
   141
 *
faluco@505
   142
 * @param msgname		Message name to start.
faluco@505
   143
 * @param flags			Optional flags to set.
faluco@505
   144
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   145
 *						INVALID_HANDLE on failure.
faluco@505
   146
 */
faluco@505
   147
stock Handle:StartMessageAll(String:msgname[], flags=0)
faluco@505
   148
{
faluco@505
   149
	new maxClients = GetMaxClients();
faluco@505
   150
	new total = 0;
faluco@505
   151
	new clients[maxClients];
faluco@505
   152
	for (new i=1; i<=maxClients; i++)
faluco@505
   153
	{
faluco@505
   154
		if (IsClientConnected(i))
faluco@505
   155
		{
faluco@505
   156
			clients[total++] = i;
faluco@505
   157
		}
faluco@505
   158
	}
faluco@505
   159
	return StartMessage(msgname, clients, total, flags);
faluco@505
   160
}
faluco@505
   161
faluco@505
   162
/**
faluco@505
   163
 * Starts a simpler usermessage (network message) for one client.
dvander@508
   164
 * @note See StartMessage or StartMessageEx().
faluco@505
   165
 *
faluco@505
   166
 * @param msgname		Message name to start.
faluco@505
   167
 * @param client		Client to send to.
faluco@505
   168
 * @param flags			Optional flags to set.
faluco@505
   169
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   170
 *						INVALID_HANDLE on failure.
faluco@505
   171
 */
faluco@505
   172
stock Handle:StartMessageOne(String:msgname[], client, flags=0)
faluco@505
   173
{
faluco@505
   174
	new players[1];
faluco@505
   175
	
faluco@505
   176
	players[0] = client;
faluco@505
   177
	
faluco@505
   178
	return StartMessage(msgname, players, 1, flags);
faluco@505
   179
}