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