plugins/include/usermessages.inc
author David Anderson <dvander@alliedmods.net>
Wed Aug 08 02:27:10 2007 +0000 (2007-08-08)
changeset 1269 27397584df9c
parent 1268 9360f5ea2289
child 1330 ab94316bb52b
permissions -rw-r--r--
- massive overhaul of the voting subsystem
- NOTE: menu API compatibility was COMPLETELY broken for C++!
- cleaned up various aspects of the menu API
- implemented new extended vote results callback
- extended the debug reporter a tiny bit
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
dvander@619
    21
/**
dvander@619
    22
 * UserMsg helper values.
dvander@619
    23
 */
faluco@505
    24
enum UserMsg
faluco@505
    25
{
faluco@505
    26
	INVALID_MESSAGE_ID = -1,
faluco@505
    27
};
faluco@505
    28
faluco@1040
    29
/**
faluco@1040
    30
 * @section Message Flags.
faluco@1040
    31
 */
dvander@716
    32
#define USERMSG_RELIABLE		(1<<2)		/**< Message will be set on the reliable stream */
faluco@505
    33
#define USERMSG_INITMSG			(1<<3)		/**< Message will be considered to be an initmsg */
ds@1268
    34
#define USERMSG_BLOCKHOOKS		(1<<7)		/**< Prevents the message from triggering SourceMod and Metamod hooks */
ds@1268
    35
ds@1268
    36
#pragma deprecated Constant has no effect
ds@1268
    37
#define USERMSG_PASSTHRU		(1<<0)		/**< (DEPRECATED, NO EFFECT) */
ds@1268
    38
#pragma deprecated Constant has no effect
ds@1268
    39
#define USERMSG_PASSTHRU_ALL	(1<<1)		/**< (DEPRECATED, NO EFFECT) */
ds@1268
    40
#pragma deprecated Constant has no effect
faluco@1250
    41
#define USERMSG_BLOCK_MM		(1<<4)		/**< (DEPRECATED, NO EFFECT) */
ds@1268
    42
#pragma deprecated Constant has no effect
faluco@1250
    43
#define USERMSG_BLOCK_SM		(1<<5)		/**< (DEPRECATED, NO EFFECT) */
ds@1268
    44
#pragma deprecated Constant has no effect
faluco@1250
    45
#define USERMSG_BLOCK_ALL		(1<<6)		/**< (DEPRECATED, NO EFFECT) */
faluco@505
    46
faluco@505
    47
/**
faluco@1040
    48
 * @endsection
faluco@1040
    49
 */
faluco@1040
    50
faluco@1040
    51
/**
faluco@505
    52
 * Returns the ID of a given message, or -1 on failure.
faluco@505
    53
 *
faluco@505
    54
 * @param msg			String containing message name (case sensitive).
faluco@505
    55
 * @return				A message index, or INVALID_MESSAGE_ID on failure.
faluco@505
    56
 */
faluco@505
    57
native UserMsg:GetUserMessageId(const String:msg[]);
faluco@505
    58
faluco@505
    59
/**
ds@512
    60
 * Retrieves the name of a message by ID.
ds@512
    61
 *
ds@512
    62
 * @param msg_id		Message index.
ds@512
    63
 * @param msg			Buffer to store the name of the message.
ds@512
    64
 * @param maxlength		Maximum length of string buffer.
ds@512
    65
 * @return				True if message index is valid, false otherwise.
ds@512
    66
 */
ds@512
    67
native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
ds@512
    68
ds@512
    69
/**
faluco@505
    70
 * Starts a usermessage (network message).
faluco@505
    71
 * @note Only one message can be active at a time.
dvander@508
    72
 * @note It is illegal to send any message while a non-intercept hook is in progress.
faluco@505
    73
 *
faluco@505
    74
 * @param msgname		Message name to start.
faluco@505
    75
 * @param clients		Array containing player indexes to broadcast to.
faluco@505
    76
 * @param numClients	Number of players in the array.
ds@621
    77
 * @param flags			Optional flags to set.
faluco@505
    78
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
    79
 *						INVALID_HANDLE on failure.
dvander@508
    80
 * @error				Invalid message name or unable to start a message.
faluco@505
    81
 */
ds@621
    82
native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
faluco@505
    83
faluco@505
    84
/**
faluco@505
    85
 * Starts a usermessage (network message).
faluco@505
    86
 * @note Only one message can be active at a time.
dvander@508
    87
 * @note It is illegal to send any message while a non-intercept hook is in progress.
faluco@505
    88
 *
faluco@505
    89
 * @param msg			Message index to start.
faluco@505
    90
 * @param clients		Array containing player indexes to broadcast to.
faluco@505
    91
 * @param numClients	Number of players in the array.
ds@621
    92
 * @param flags			Optional flags to set.
faluco@505
    93
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
    94
 *						INVALID_HANDLE on failure.
dvander@508
    95
 * @error				Invalid message name or unable to start a message.
faluco@505
    96
 */
ds@621
    97
native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
faluco@505
    98
faluco@505
    99
/**
faluco@505
   100
 * Ends a previously started user message (network message).
faluco@505
   101
 *
faluco@505
   102
 * @noreturn
faluco@505
   103
 */
faluco@505
   104
native EndMessage();
faluco@505
   105
faluco@505
   106
/**
dvander@812
   107
 * Called when a message is hooked
dvander@508
   108
 *
dvander@508
   109
 * @param msg_id		Message index.
faluco@552
   110
 * @param bf			Handle to the input bit buffer of the message.
dvander@508
   111
 * @param players		Array containing player indexes.
dvander@508
   112
 * @param playersNum	Number of players in the array.
dvander@508
   113
 * @param reliable		True if message is reliable, false otherwise.
dvander@508
   114
 * @param init			True if message is an initmsg, false otherwise.
dvander@508
   115
 * @return				Ignored for normal hooks.  For intercept hooks, false blocks 
dvander@508
   116
 *						the message from being sent, and true continues.
dvander@508
   117
 */
faluco@552
   118
functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
faluco@552
   119
faluco@552
   120
/**
dvander@812
   121
 * Called when a message is finished sending.
faluco@552
   122
 *
faluco@552
   123
 * @param msg_id		Message index.
faluco@552
   124
 */
faluco@552
   125
functag MsgSentNotify public(UserMsg:msg_id);
dvander@508
   126
dvander@508
   127
/**
dvander@812
   128
 * Hooks a user message.
dvander@508
   129
 *
dvander@508
   130
 * @param msg_id		Message index.
dvander@508
   131
 * @param hook			Function to use as a hook.
dvander@508
   132
 * @param intercept		If intercept is true, message will be fully intercepted,
dvander@508
   133
 * 						allowing the user to block the message.  Otherwise,
dvander@508
   134
 *						the hook is normal and ignores the return value.
faluco@552
   135
 * @param notify		Notification function.
dvander@508
   136
 * @noreturn
dvander@508
   137
 * @error				Invalid message index.
dvander@508
   138
 */
faluco@552
   139
native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1);
dvander@508
   140
dvander@508
   141
/**
dvander@812
   142
 * Removes one usermessage hook.
dvander@508
   143
 *
dvander@508
   144
 * @param msg_id		Message index.
dvander@508
   145
 * @param hook			Function used for the hook.
dvander@508
   146
 * @param intercept		Specifies whether the hook was an intercept hook or not.
dvander@508
   147
 * @noreturn
dvander@508
   148
 * @error				Invalid message index.
dvander@508
   149
 */
ds@626
   150
native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
dvander@508
   151
dvander@508
   152
/**
faluco@505
   153
 * Starts a usermessage (network message) that broadcasts to all clients.
dvander@508
   154
 * @note See StartMessage or StartMessageEx().
faluco@505
   155
 *
faluco@505
   156
 * @param msgname		Message name to start.
faluco@505
   157
 * @param flags			Optional flags to set.
faluco@505
   158
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   159
 *						INVALID_HANDLE on failure.
faluco@505
   160
 */
faluco@505
   161
stock Handle:StartMessageAll(String:msgname[], flags=0)
faluco@505
   162
{
faluco@505
   163
	new maxClients = GetMaxClients();
faluco@505
   164
	new total = 0;
faluco@505
   165
	new clients[maxClients];
faluco@505
   166
	for (new i=1; i<=maxClients; i++)
faluco@505
   167
	{
faluco@505
   168
		if (IsClientConnected(i))
faluco@505
   169
		{
faluco@505
   170
			clients[total++] = i;
faluco@505
   171
		}
faluco@505
   172
	}
faluco@505
   173
	return StartMessage(msgname, clients, total, flags);
faluco@505
   174
}
faluco@505
   175
faluco@505
   176
/**
faluco@505
   177
 * Starts a simpler usermessage (network message) for one client.
dvander@508
   178
 * @note See StartMessage or StartMessageEx().
faluco@505
   179
 *
faluco@505
   180
 * @param msgname		Message name to start.
faluco@505
   181
 * @param client		Client to send to.
faluco@505
   182
 * @param flags			Optional flags to set.
faluco@505
   183
 * @return				A handle to a bf_write bit packing structure, or
faluco@505
   184
 *						INVALID_HANDLE on failure.
faluco@505
   185
 */
faluco@505
   186
stock Handle:StartMessageOne(String:msgname[], client, flags=0)
faluco@505
   187
{
faluco@505
   188
	new players[1];
faluco@505
   189
	
faluco@505
   190
	players[0] = client;
faluco@505
   191
	
faluco@505
   192
	return StartMessage(msgname, players, 1, flags);
faluco@505
   193
}