plugins/include/usermessages.inc
author Scott Ehlert <ds@alliedmods.net>
Thu Apr 17 09:28:46 2008 +0000 (2008-04-17)
changeset 2013 5cf82fea0177
parent 1952 b7aa2b626807
child 2112 2a83a521287c
permissions -rw-r--r--
Gah, finalized the revised ILibrarySys::GetFileExtension() code
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 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 /**
    54  * @endsection
    55  */
    56 
    57 /**
    58  * Returns the ID of a given message, or -1 on failure.
    59  *
    60  * @param msg			String containing message name (case sensitive).
    61  * @return				A message index, or INVALID_MESSAGE_ID on failure.
    62  */
    63 native UserMsg:GetUserMessageId(const String:msg[]);
    64 
    65 /**
    66  * Retrieves the name of a message by ID.
    67  *
    68  * @param msg_id		Message index.
    69  * @param msg			Buffer to store the name of the message.
    70  * @param maxlength		Maximum length of string buffer.
    71  * @return				True if message index is valid, false otherwise.
    72  */
    73 native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
    74 
    75 /**
    76  * Starts a usermessage (network message).
    77  * @note Only one message can be active at a time.
    78  * @note It is illegal to send any message while a non-intercept hook is in progress.
    79  *
    80  * @param msgname		Message name to start.
    81  * @param clients		Array containing player indexes to broadcast to.
    82  * @param numClients	Number of players in the array.
    83  * @param flags			Optional flags to set.
    84  * @return				A handle to a bf_write bit packing structure, or
    85  *						INVALID_HANDLE on failure.
    86  * @error				Invalid message name or unable to start a message.
    87  */
    88 native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
    89 
    90 /**
    91  * Starts a usermessage (network message).
    92  * @note Only one message can be active at a time.
    93  * @note It is illegal to send any message while a non-intercept hook is in progress.
    94  *
    95  * @param msg			Message index to start.
    96  * @param clients		Array containing player indexes to broadcast to.
    97  * @param numClients	Number of players in the array.
    98  * @param flags			Optional flags to set.
    99  * @return				A handle to a bf_write bit packing structure, or
   100  *						INVALID_HANDLE on failure.
   101  * @error				Invalid message name or unable to start a message.
   102  */
   103 native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
   104 
   105 /**
   106  * Ends a previously started user message (network message).
   107  *
   108  * @noreturn
   109  */
   110 native EndMessage();
   111 
   112 /**
   113  * Called when a message is hooked
   114  *
   115  * @param msg_id		Message index.
   116  * @param bf			Handle to the input bit buffer of the message.
   117  * @param players		Array containing player indexes.
   118  * @param playersNum	Number of players in the array.
   119  * @param reliable		True if message is reliable, false otherwise.
   120  * @param init			True if message is an initmsg, false otherwise.
   121  * @return				Ignored for normal hooks.  For intercept hooks, Plugin_Handled 
   122  *						blocks the message from being sent, and Plugin_Continue 
   123  *						resumes normal functionality.
   124  */
   125 functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
   126 
   127 /**
   128  * Called when a message is finished sending.
   129  *
   130  * @param msg_id		Message index.
   131  */
   132 functag MsgSentNotify public(UserMsg:msg_id);
   133 
   134 /**
   135  * Hooks a user message.
   136  *
   137  * @param msg_id		Message index.
   138  * @param hook			Function to use as a hook.
   139  * @param intercept		If intercept is true, message will be fully intercepted,
   140  * 						allowing the user to block the message.  Otherwise,
   141  *						the hook is normal and ignores the return value.
   142  * @param notify		Notification function.
   143  * @noreturn
   144  * @error				Invalid message index.
   145  */
   146 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1);
   147 
   148 /**
   149  * Removes one usermessage hook.
   150  *
   151  * @param msg_id		Message index.
   152  * @param hook			Function used for the hook.
   153  * @param intercept		Specifies whether the hook was an intercept hook or not.
   154  * @noreturn
   155  * @error				Invalid message index.
   156  */
   157 native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
   158 
   159 /**
   160  * Starts a usermessage (network message) that broadcasts to all clients.
   161  * @note See StartMessage or StartMessageEx().
   162  *
   163  * @param msgname		Message name to start.
   164  * @param flags			Optional flags to set.
   165  * @return				A handle to a bf_write bit packing structure, or
   166  *						INVALID_HANDLE on failure.
   167  */
   168 stock Handle:StartMessageAll(String:msgname[], flags=0)
   169 {
   170 	new maxClients = GetMaxClients();
   171 	new total = 0;
   172 	new clients[maxClients];
   173 	for (new i=1; i<=maxClients; i++)
   174 	{
   175 		if (IsClientConnected(i))
   176 		{
   177 			clients[total++] = i;
   178 		}
   179 	}
   180 	return StartMessage(msgname, clients, total, flags);
   181 }
   182 
   183 /**
   184  * Starts a simpler usermessage (network message) for one client.
   185  * @note See StartMessage or StartMessageEx().
   186  *
   187  * @param msgname		Message name to start.
   188  * @param client		Client to send to.
   189  * @param flags			Optional flags to set.
   190  * @return				A handle to a bf_write bit packing structure, or
   191  *						INVALID_HANDLE on failure.
   192  */
   193 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
   194 {
   195 	new players[1];
   196 	
   197 	players[0] = client;
   198 	
   199 	return StartMessage(msgname, players, 1, flags);
   200 }