initial import of usermessage interface
authorDavid Anderson <dvander@alliedmods.net>
Fri Feb 16 19:12:27 2007 +0000 (2007-02-16)
changeset 50713597d9560b6
parent 506 cdf58fb76280
child 508 5ce8b28b29c4
initial import of usermessage interface
public/IUserMessages.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/public/IUserMessages.h	Fri Feb 16 19:12:27 2007 +0000
     1.3 @@ -0,0 +1,131 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * ===============================================================
     1.7 + * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     1.8 + * All rights reserved.
     1.9 + * ===============================================================
    1.10 + *
    1.11 + *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
    1.12 + * used or modified under the Terms and Conditions of its License Agreement, 
    1.13 + * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
    1.14 + * works must be licensed under the GNU General Public License (version 2 or 
    1.15 + * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
    1.16 + * 
    1.17 + * To view the latest information, see: http://www.sourcemod.net/license.php
    1.18 + *
    1.19 + * Version: $Id$
    1.20 + */
    1.21 +
    1.22 +#ifndef _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
    1.23 +#define _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
    1.24 +
    1.25 +#include <sp_vm_api.h>
    1.26 +#include <bitbuf.h>
    1.27 +#include <irecipientfilter.h>
    1.28 +
    1.29 +/**
    1.30 + * @file IUserMessages.h
    1.31 + * @brief Contains functions for advanced usermessage hooking.
    1.32 + */
    1.33 +
    1.34 +#define SMINTERFACE_USERMSGS_NAME		"IUserMessages"
    1.35 +#define SMINTERFACE_USERMSGS_VERSION	1
    1.36 +
    1.37 +namespace SourceMod
    1.38 +{
    1.39 +	/**
    1.40 +	 * @brief Listens to user messages sent from the server.
    1.41 +	 */
    1.42 +	class IUserMessageListener
    1.43 +	{
    1.44 +	public:
    1.45 +		/**
    1.46 +		 * @brief Called when a hooked user message is being sent 
    1.47 +		 * and all interceptions have finished.
    1.48 +		 *
    1.49 +		 * @param msg_id		Message Id.
    1.50 +		 * @param bf			bf_write structure containing written bytes.
    1.51 +		 * @param pFilter		Recipient filter.
    1.52 +		 */
    1.53 +		virtual void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
    1.54 +		{
    1.55 +		}
    1.56 +
    1.57 +		/**
    1.58 +		 * @brief Called when a hooked user message is intercepted.
    1.59 +		 * 
    1.60 +		 * @param msg_id		Message Id.
    1.61 +		 * @param bf			bf_write structure containing written bytes.
    1.62 +		 * @param pFtiler		Recipient filter.
    1.63 +		 * @return				True to allow message, false to scrap it.
    1.64 +		 */
    1.65 +		virtual bool InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
    1.66 +		{
    1.67 +			return true;
    1.68 +		}
    1.69 +
    1.70 +		/**
    1.71 +		 * @brief Called when a hooked user message is sent, regardless of the hook type.
    1.72 +		 * @param mgs_id		Message Id.
    1.73 +		 */
    1.74 +		virtual void OnUserMessageSent(int msg_id)
    1.75 +		{
    1.76 +		}
    1.77 +	};
    1.78 +
    1.79 +	/**
    1.80 +	 * @brief Contains functions for hooking user messages.
    1.81 +	 */
    1.82 +	class IUserMessages : public SMInterface
    1.83 +	{
    1.84 +	public:
    1.85 +		virtual unsigned int GetInterfaceVersion()
    1.86 +		{
    1.87 +			return SMINTERFACE_USERMSGS_VERSION;
    1.88 +		}
    1.89 +		virtual const char *GetInterfaceName()
    1.90 +		{
    1.91 +			return SMINTERFACE_USERMSGS_NAME;
    1.92 +		}
    1.93 +	public:
    1.94 +		/**
    1.95 +		 * @brief Finds a message id by name.
    1.96 +		 * 
    1.97 +		 * Note: due to a bug in Valve's earlier SDK versions, this
    1.98 +		 * may cause crashes alongside IServerGameDLL003 if the message is
    1.99 +		 * not found.
   1.100 +		 *
   1.101 +		 * @param msg		Case-sensitive string containing the message.
   1.102 +		 * @return			A message index, or -1 on failure.
   1.103 +		 */
   1.104 +		virtual int GetMessageIndex(const char *msg) =0;
   1.105 +
   1.106 +		/**
   1.107 +		 * @brief Sets a hook on a user message.
   1.108 +		 *
   1.109 +		 * @param msg_id		Message Id.
   1.110 +		 * @param pListener		Pointer to an IUserMessageListener.
   1.111 +		 * @param intercept		If true, message will be intercepted rather than merely hooked.
   1.112 +		 * @return				True on success, false otherwise.
   1.113 +		 */
   1.114 +		virtual bool HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
   1.115 +
   1.116 +		/**
   1.117 +		 * @brief Wrapper around UserMessageBegin for more options.
   1.118 +		 * 
   1.119 +		 * @param mgs_id		Message Id.
   1.120 +		 * @param players		Array containing player indexes.
   1.121 +		 * @param playersNum	Number of players in the array.
   1.122 +		 * @param flags			Flags to use for sending the message.
   1.123 +		 * @return				bf_write structure to write message with.
   1.124 +		 */
   1.125 +		virtual bf_write *StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags) =0;
   1.126 +
   1.127 +		/**
   1.128 +		 * @brief Wrapper around UserMessageEnd for use with StartMessage().
   1.129 +		 */
   1.130 +		virtual void EndMessage() =0;
   1.131 +	};
   1.132 +}
   1.133 +
   1.134 +#endif //_INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_