plugins/include/usermessages.inc
author Borja Ferrer <faluco@alliedmods.net>
Sat Sep 29 22:26:36 2007 +0000 (2007-09-29)
changeset 1504 312c2e8934b1
parent 1394 2885e3f90a88
child 1937 b1d373d7c127
permissions -rw-r--r--
added amb964, DispatchKeyValue natives
     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.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32  
    33 #if defined _eventsmsgs_included
    34  #endinput
    35 #endif
    36 #define _eventsmsgs_included
    37 
    38 /**
    39  * UserMsg helper values.
    40  */
    41 enum UserMsg
    42 {
    43 	INVALID_MESSAGE_ID = -1,
    44 };
    45 
    46 /**
    47  * @section Message Flags.
    48  */
    49 #define USERMSG_RELIABLE		(1<<2)		/**< Message will be set on the reliable stream */
    50 #define USERMSG_INITMSG			(1<<3)		/**< Message will be considered to be an initmsg */
    51 #define USERMSG_BLOCKHOOKS		(1<<7)		/**< Prevents the message from triggering SourceMod and Metamod hooks */
    52 
    53 #pragma deprecated Constant has no effect
    54 #define USERMSG_PASSTHRU		(1<<0)		/**< (DEPRECATED, NO EFFECT) */
    55 #pragma deprecated Constant has no effect
    56 #define USERMSG_PASSTHRU_ALL	(1<<1)		/**< (DEPRECATED, NO EFFECT) */
    57 #pragma deprecated Constant has no effect
    58 #define USERMSG_BLOCK_MM		(1<<4)		/**< (DEPRECATED, NO EFFECT) */
    59 #pragma deprecated Constant has no effect
    60 #define USERMSG_BLOCK_SM		(1<<5)		/**< (DEPRECATED, NO EFFECT) */
    61 #pragma deprecated Constant has no effect
    62 #define USERMSG_BLOCK_ALL		(1<<6)		/**< (DEPRECATED, NO EFFECT) */
    63 
    64 /**
    65  * @endsection
    66  */
    67 
    68 /**
    69  * Returns the ID of a given message, or -1 on failure.
    70  *
    71  * @param msg			String containing message name (case sensitive).
    72  * @return				A message index, or INVALID_MESSAGE_ID on failure.
    73  */
    74 native UserMsg:GetUserMessageId(const String:msg[]);
    75 
    76 /**
    77  * Retrieves the name of a message by ID.
    78  *
    79  * @param msg_id		Message index.
    80  * @param msg			Buffer to store the name of the message.
    81  * @param maxlength		Maximum length of string buffer.
    82  * @return				True if message index is valid, false otherwise.
    83  */
    84 native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
    85 
    86 /**
    87  * Starts a usermessage (network message).
    88  * @note Only one message can be active at a time.
    89  * @note It is illegal to send any message while a non-intercept hook is in progress.
    90  *
    91  * @param msgname		Message name to start.
    92  * @param clients		Array containing player indexes to broadcast to.
    93  * @param numClients	Number of players in the array.
    94  * @param flags			Optional flags to set.
    95  * @return				A handle to a bf_write bit packing structure, or
    96  *						INVALID_HANDLE on failure.
    97  * @error				Invalid message name or unable to start a message.
    98  */
    99 native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
   100 
   101 /**
   102  * Starts a usermessage (network message).
   103  * @note Only one message can be active at a time.
   104  * @note It is illegal to send any message while a non-intercept hook is in progress.
   105  *
   106  * @param msg			Message index to start.
   107  * @param clients		Array containing player indexes to broadcast to.
   108  * @param numClients	Number of players in the array.
   109  * @param flags			Optional flags to set.
   110  * @return				A handle to a bf_write bit packing structure, or
   111  *						INVALID_HANDLE on failure.
   112  * @error				Invalid message name or unable to start a message.
   113  */
   114 native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
   115 
   116 /**
   117  * Ends a previously started user message (network message).
   118  *
   119  * @noreturn
   120  */
   121 native EndMessage();
   122 
   123 /**
   124  * Called when a message is hooked
   125  *
   126  * @param msg_id		Message index.
   127  * @param bf			Handle to the input bit buffer of the message.
   128  * @param players		Array containing player indexes.
   129  * @param playersNum	Number of players in the array.
   130  * @param reliable		True if message is reliable, false otherwise.
   131  * @param init			True if message is an initmsg, false otherwise.
   132  * @return				Ignored for normal hooks.  For intercept hooks, Plugin_Handled 
   133  *						blocks the message from being sent, and Plugin_Continue 
   134  *						resumes normal functionality.
   135  */
   136 functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
   137 
   138 /**
   139  * Called when a message is finished sending.
   140  *
   141  * @param msg_id		Message index.
   142  */
   143 functag MsgSentNotify public(UserMsg:msg_id);
   144 
   145 /**
   146  * Hooks a user message.
   147  *
   148  * @param msg_id		Message index.
   149  * @param hook			Function to use as a hook.
   150  * @param intercept		If intercept is true, message will be fully intercepted,
   151  * 						allowing the user to block the message.  Otherwise,
   152  *						the hook is normal and ignores the return value.
   153  * @param notify		Notification function.
   154  * @noreturn
   155  * @error				Invalid message index.
   156  */
   157 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1);
   158 
   159 /**
   160  * Removes one usermessage hook.
   161  *
   162  * @param msg_id		Message index.
   163  * @param hook			Function used for the hook.
   164  * @param intercept		Specifies whether the hook was an intercept hook or not.
   165  * @noreturn
   166  * @error				Invalid message index.
   167  */
   168 native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
   169 
   170 /**
   171  * Starts a usermessage (network message) that broadcasts to all clients.
   172  * @note See StartMessage or StartMessageEx().
   173  *
   174  * @param msgname		Message name to start.
   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:StartMessageAll(String:msgname[], flags=0)
   180 {
   181 	new maxClients = GetMaxClients();
   182 	new total = 0;
   183 	new clients[maxClients];
   184 	for (new i=1; i<=maxClients; i++)
   185 	{
   186 		if (IsClientConnected(i))
   187 		{
   188 			clients[total++] = i;
   189 		}
   190 	}
   191 	return StartMessage(msgname, clients, total, flags);
   192 }
   193 
   194 /**
   195  * Starts a simpler usermessage (network message) for one client.
   196  * @note See StartMessage or StartMessageEx().
   197  *
   198  * @param msgname		Message name to start.
   199  * @param client		Client to send to.
   200  * @param flags			Optional flags to set.
   201  * @return				A handle to a bf_write bit packing structure, or
   202  *						INVALID_HANDLE on failure.
   203  */
   204 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
   205 {
   206 	new players[1];
   207 	
   208 	players[0] = client;
   209 	
   210 	return StartMessage(msgname, players, 1, flags);
   211 }