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