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