plugins/include/usermessages.inc
author Nicholas Hastings <skamonkey@gmail.com>
Wed Jul 31 22:57:50 2013 -0400 (2013-07-31)
changeset 3966 5d8b87f98355
parent 3743 a98686a77974
child 3967 ceafb87d38a7
permissions -rw-r--r--
Check all possible mapcycle paths on newer orangebox games (bug 5719, r=asherkin).
     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  * UserMsg message serialization formats
    48  */
    49 enum UserMessageType
    50 {
    51 	UM_BitBuf = 0,
    52 	UM_Protobuf,
    53 };
    54 
    55 /**
    56  * @section Message Flags.
    57  */
    58 #define USERMSG_RELIABLE		(1<<2)		/**< Message will be set on the reliable stream */
    59 #define USERMSG_INITMSG			(1<<3)		/**< Message will be considered to be an initmsg */
    60 #define USERMSG_BLOCKHOOKS		(1<<7)		/**< Prevents the message from triggering SourceMod and Metamod hooks */
    61 
    62 /**
    63  * @endsection
    64  */
    65 
    66 /**
    67  * Returns usermessage serialization type used for the current engine
    68  *
    69  * @return				The supported usermessage type.
    70  */
    71 native UserMessageType:GetUserMessageType();
    72 
    73 /**
    74  * Returns the ID of a given message, or -1 on failure.
    75  *
    76  * @param msg			String containing message name (case sensitive).
    77  * @return				A message index, or INVALID_MESSAGE_ID on failure.
    78  */
    79 native UserMsg:GetUserMessageId(const String:msg[]);
    80 
    81 /**
    82  * Retrieves the name of a message by ID.
    83  *
    84  * @param msg_id		Message index.
    85  * @param msg			Buffer to store the name of the message.
    86  * @param maxlength		Maximum length of string buffer.
    87  * @return				True if message index is valid, false otherwise.
    88  */
    89 native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
    90 
    91 /**
    92  * Starts a usermessage (network message).
    93  * @note Only one message can be active at a time.
    94  * @note It is illegal to send any message while a non-intercept hook is in progress.
    95  *
    96  * @param msgname		Message name to start.
    97  * @param clients		Array containing player indexes to broadcast to.
    98  * @param numClients	Number of players in the array.
    99  * @param flags			Optional flags to set.
   100  * @return				A handle to a bf_write bit packing structure, or
   101  *						INVALID_HANDLE on failure.
   102  * @error				Invalid message name, unable to start a message, invalid client,
   103  *						or client not connected.
   104  */
   105 native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
   106 
   107 /**
   108  * Starts a usermessage (network message).
   109  * @note Only one message can be active at a time.
   110  * @note It is illegal to send any message while a non-intercept hook is in progress.
   111  *
   112  * @param msg			Message index to start.
   113  * @param clients		Array containing player indexes to broadcast to.
   114  * @param numClients	Number of players in the array.
   115  * @param flags			Optional flags to set.
   116  * @return				A handle to a bf_write bit packing structure, or
   117  *						INVALID_HANDLE on failure.
   118  * @error				Invalid message name, unable to start a message, invalid client,
   119  *						or client not connected.
   120  */
   121 native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
   122 
   123 /**
   124  * Ends a previously started user message (network message).
   125  *
   126  * @noreturn
   127  */
   128 native EndMessage();
   129 
   130 /**
   131  * Called when a message is hooked
   132  *
   133  * @param msg_id		Message index.
   134  * @param msg			Handle to the input bit buffer or protobuf.
   135  * @param players		Array containing player indexes.
   136  * @param playersNum	Number of players in the array.
   137  * @param reliable		True if message is reliable, false otherwise.
   138  * @param init			True if message is an initmsg, false otherwise.
   139  * @return				Ignored for normal hooks.  For intercept hooks, Plugin_Handled 
   140  *						blocks the message from being sent, and Plugin_Continue 
   141  *						resumes normal functionality.
   142  */
   143 functag public Action:MsgHook(UserMsg:msg_id, Handle:msg, const players[], playersNum, bool:reliable, bool:init);
   144 
   145 /**
   146  * Called when a message hook has completed.
   147  *
   148  * @param msg_id		Message index.
   149  * @param sent			True if message was sent, false if blocked.
   150  */
   151 functag public MsgPostHook(UserMsg:msg_id, bool:sent);
   152 
   153 /**
   154  * Hooks a user message.
   155  *
   156  * @param msg_id		Message index.
   157  * @param hook			Function to use as a hook.
   158  * @param intercept		If intercept is true, message will be fully intercepted,
   159  * 						allowing the user to block the message.  Otherwise,
   160  *						the hook is normal and ignores the return value.
   161  * @param notify		Notification function.
   162  * @noreturn
   163  * @error				Invalid message index.
   164  */
   165 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgPostHook:post=MsgPostHook:-1);
   166 
   167 /**
   168  * Removes one usermessage hook.
   169  *
   170  * @param msg_id		Message index.
   171  * @param hook			Function used for the hook.
   172  * @param intercept		Specifies whether the hook was an intercept hook or not.
   173  * @noreturn
   174  * @error				Invalid message index.
   175  */
   176 native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
   177 
   178 /**
   179  * Starts a usermessage (network message) that broadcasts to all clients.
   180  * @note See StartMessage or StartMessageEx().
   181  *
   182  * @param msgname		Message name to start.
   183  * @param flags			Optional flags to set.
   184  * @return				A handle to a bf_write bit packing structure, or
   185  *						INVALID_HANDLE on failure.
   186  */
   187 stock Handle:StartMessageAll(String:msgname[], flags=0)
   188 {
   189 	new total = 0;
   190 	new clients[MaxClients];
   191 	for (new i=1; i<=MaxClients; i++)
   192 	{
   193 		if (IsClientConnected(i))
   194 		{
   195 			clients[total++] = i;
   196 		}
   197 	}
   198 	return StartMessage(msgname, clients, total, flags);
   199 }
   200 
   201 /**
   202  * Starts a simpler usermessage (network message) for one client.
   203  * @note See StartMessage or StartMessageEx().
   204  *
   205  * @param msgname		Message name to start.
   206  * @param client		Client to send to.
   207  * @param flags			Optional flags to set.
   208  * @return				A handle to a bf_write bit packing structure, or
   209  *						INVALID_HANDLE on failure.
   210  */
   211 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
   212 {
   213 	new players[1];
   214 	
   215 	players[0] = client;
   216 	
   217 	return StartMessage(msgname, players, 1, flags);
   218 }