plugins/include/usermessages.inc
author David Anderson <dvander@alliedmods.net>
Wed Aug 15 16:21:28 2007 +0000 (2007-08-15)
changeset 1334 9db842b7a9fe
parent 1330 ab94316bb52b
child 1394 2885e3f90a88
permissions -rw-r--r--
- removed some debug stuff
- committed msvc8 detection to sm_platform.h
- updated comments to FormatTime()
     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, false blocks 
   133  *						the message from being sent, and true continues.
   134  */
   135 functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
   136 
   137 /**
   138  * Called when a message is finished sending.
   139  *
   140  * @param msg_id		Message index.
   141  */
   142 functag MsgSentNotify public(UserMsg:msg_id);
   143 
   144 /**
   145  * Hooks a user message.
   146  *
   147  * @param msg_id		Message index.
   148  * @param hook			Function to use as a hook.
   149  * @param intercept		If intercept is true, message will be fully intercepted,
   150  * 						allowing the user to block the message.  Otherwise,
   151  *						the hook is normal and ignores the return value.
   152  * @param notify		Notification function.
   153  * @noreturn
   154  * @error				Invalid message index.
   155  */
   156 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1);
   157 
   158 /**
   159  * Removes one usermessage hook.
   160  *
   161  * @param msg_id		Message index.
   162  * @param hook			Function used for the hook.
   163  * @param intercept		Specifies whether the hook was an intercept hook or not.
   164  * @noreturn
   165  * @error				Invalid message index.
   166  */
   167 native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
   168 
   169 /**
   170  * Starts a usermessage (network message) that broadcasts to all clients.
   171  * @note See StartMessage or StartMessageEx().
   172  *
   173  * @param msgname		Message name to start.
   174  * @param flags			Optional flags to set.
   175  * @return				A handle to a bf_write bit packing structure, or
   176  *						INVALID_HANDLE on failure.
   177  */
   178 stock Handle:StartMessageAll(String:msgname[], flags=0)
   179 {
   180 	new maxClients = GetMaxClients();
   181 	new total = 0;
   182 	new clients[maxClients];
   183 	for (new i=1; i<=maxClients; i++)
   184 	{
   185 		if (IsClientConnected(i))
   186 		{
   187 			clients[total++] = i;
   188 		}
   189 	}
   190 	return StartMessage(msgname, clients, total, flags);
   191 }
   192 
   193 /**
   194  * Starts a simpler usermessage (network message) for one client.
   195  * @note See StartMessage or StartMessageEx().
   196  *
   197  * @param msgname		Message name to start.
   198  * @param client		Client to send to.
   199  * @param flags			Optional flags to set.
   200  * @return				A handle to a bf_write bit packing structure, or
   201  *						INVALID_HANDLE on failure.
   202  */
   203 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
   204 {
   205 	new players[1];
   206 	
   207 	players[0] = client;
   208 	
   209 	return StartMessage(msgname, players, 1, flags);
   210 }