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