public/IUserMessages.h
author Scott Ehlert <ds@alliedmods.net>
Sun Jul 15 08:00:26 2007 +0000 (2007-07-15)
changeset 1116 40cc5e9f0f1b
parent 698 8c68fc683dba
child 1226 478550a4d5ec
permissions -rw-r--r--
Removed strange debugging code
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * All rights reserved.
     6  * ===============================================================
     7  *
     8  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
     9  * used or modified under the Terms and Conditions of its License Agreement, 
    10  * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
    11  * works must be licensed under the GNU General Public License (version 2 or 
    12  * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
    13  * 
    14  * To view the latest information, see: http://www.sourcemod.net/license.php
    15  *
    16  * Version: $Id$
    17  */
    18 
    19 #ifndef _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
    20 #define _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
    21 
    22 #include <IShareSys.h>
    23 #include <sp_vm_api.h>
    24 #include <IForwardSys.h>
    25 #include <bitbuf.h>
    26 #include <irecipientfilter.h>
    27 
    28 /**
    29  * @file IUserMessages.h
    30  * @brief Contains functions for advanced usermessage hooking.
    31  */
    32 
    33 #define SMINTERFACE_USERMSGS_NAME		"IUserMessages"
    34 #define SMINTERFACE_USERMSGS_VERSION	1
    35 
    36 namespace SourceMod
    37 {
    38 	/**
    39 	 * @brief Listens to user messages sent from the server.
    40 	 */
    41 	class IUserMessageListener
    42 	{
    43 	public:
    44 		/**
    45 		 * @brief Called when a hooked user message is being sent 
    46 		 * and all interceptions have finished.
    47 		 *
    48 		 * @param msg_id		Message Id.
    49 		 * @param bf			bf_write structure containing written bytes.
    50 		 * @param pFilter		Recipient filter.
    51 		 */
    52 		virtual void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
    53 		{
    54 		}
    55 
    56 		/**
    57 		 * @brief Called when a hooked user message is intercepted.
    58 		 * 
    59 		 * @param msg_id		Message Id.
    60 		 * @param bf			bf_write structure containing written bytes.
    61 		 * @param pFilter		Recipient filter.
    62 		 * @return				Pl_Continue to allow message, Pl_Stop or Pl_Handled to scrap it.
    63 		 */
    64 		virtual ResultType InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
    65 		{
    66 			return Pl_Continue;
    67 		}
    68 
    69 		/**
    70 		 * @brief Called when a hooked user message is sent, regardless of the hook type.
    71 		 * @param msg_id		Message Id.
    72 		 */
    73 		virtual void OnUserMessageSent(int msg_id)
    74 		{
    75 		}
    76 	};
    77 
    78 	#define USERMSG_PASSTHRU			(1<<0)		/**< Message will pass through other SourceMM plugins */
    79 	#define USERMSG_PASSTHRU_ALL		(1<<1)		/**< Message will pass through other SourceMM plugins AND SourceMod */
    80 	#define USERMSG_RELIABLE			(1<<2)		/**< Message will be set to reliable */
    81 	#define USERMSG_INITMSG				(1<<3)		/**< Message will be considered to be an initmsg */
    82 
    83 	/**
    84 	 * @brief Contains functions for hooking user messages.
    85 	 */
    86 	class IUserMessages : public SMInterface
    87 	{
    88 	public:
    89 		virtual unsigned int GetInterfaceVersion()
    90 		{
    91 			return SMINTERFACE_USERMSGS_VERSION;
    92 		}
    93 		virtual const char *GetInterfaceName()
    94 		{
    95 			return SMINTERFACE_USERMSGS_NAME;
    96 		}
    97 	public:
    98 		/**
    99 		 * @brief Finds a message id by name.
   100 		 *
   101 		 * @param msg		Case-sensitive string containing the message.
   102 		 * @return			A message index, or -1 on failure.
   103 		 */
   104 		virtual int GetMessageIndex(const char *msg) =0;
   105 
   106 		/**
   107 		 * @brief Sets a hook on a user message.
   108 		 *
   109 		 * @param msg_id		Message Id.
   110 		 * @param pListener		Pointer to an IUserMessageListener.
   111 		 * @param intercept		If true, message will be intercepted rather than merely hooked.
   112 		 * @return				True on success, false otherwise.
   113 		 */
   114 		virtual bool HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
   115 
   116 		/**
   117 		 * @brief Unhooks a user message.
   118 		 *
   119 		 * @param msg_id		Message Id.
   120 		 * @param pListener		Pointer to an IUserMessageListener.
   121 		 * @param intercept		If true, removed message will from interception pool rather than normal hook pool.
   122 		 * @return				True on success, false otherwise.
   123 		 */
   124 		virtual bool UnhookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
   125 
   126 		/**
   127 		 * @brief Wrapper around UserMessageBegin for more options.
   128 		 * 
   129 		 * @param msg_id		Message Id.
   130 		 * @param players		Array containing player indexes.
   131 		 * @param playersNum	Number of players in the array.
   132 		 * @param flags			Flags to use for sending the message.
   133 		 * @return				bf_write structure to write message with, or NULL on failure.
   134 		 */
   135 		virtual bf_write *StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags) =0;
   136 
   137 		/**
   138 		 * @brief Wrapper around UserMessageEnd for use with StartMessage().
   139 		 * @return				True on success, false otherwise.
   140 		 */
   141 		virtual bool EndMessage() =0;
   142 	};
   143 }
   144 
   145 #endif //_INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_