public/IUserMessages.h

Go to the documentation of this file.
00001 /**
00002  * vim: set ts=4 :
00003  * =============================================================================
00004  * SourceMod
00005  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
00006  * =============================================================================
00007  *
00008  * This program is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License, version 3.0, as published by the
00010  * Free Software Foundation.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  *
00017  * You should have received a copy of the GNU General Public License along with
00018  * this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  * As a special exception, AlliedModders LLC gives you permission to link the
00021  * code of this program (as well as its derivative works) to "Half-Life 2," the
00022  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
00023  * by the Valve Corporation.  You must obey the GNU General Public License in
00024  * all respects for all other code used.  Additionally, AlliedModders LLC grants
00025  * this exception to all derivative works.  AlliedModders LLC defines further
00026  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
00027  * or <http://www.sourcemod.net/license.php>.
00028  *
00029  * Version: $Id: IUserMessages.h 1964 2008-03-27 04:54:56Z damagedsoul $
00030  */
00031 
00032 #ifndef _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
00033 #define _INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_
00034 
00035 #include <IShareSys.h>
00036 #include <sp_vm_api.h>
00037 #include <IForwardSys.h>
00038 #include <bitbuf.h>
00039 #include <irecipientfilter.h>
00040 
00041 /**
00042  * @file IUserMessages.h
00043  * @brief Contains functions for advanced usermessage hooking.
00044  */
00045 
00046 #define SMINTERFACE_USERMSGS_NAME                 "IUserMessages"
00047 #define SMINTERFACE_USERMSGS_VERSION    1
00048 
00049 namespace SourceMod
00050 {
00051           /**
00052            * @brief Listens to user messages sent from the server.
00053            */
00054           class IUserMessageListener
00055           {
00056           public:
00057                     /**
00058                      * @brief Called when a hooked user message is being sent 
00059                      * and all interceptions have finished.
00060                      *
00061                      * @param msg_id              Message Id.
00062                      * @param bf                            bf_write structure containing written bytes.
00063                      * @param pFilter             Recipient filter.
00064                      */
00065                     virtual void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
00066                     {
00067                     }
00068 
00069                     /**
00070                      * @brief Called when a hooked user message is intercepted.
00071                      * 
00072                      * @param msg_id              Message Id.
00073                      * @param bf                            bf_write structure containing written bytes.
00074                      * @param pFilter             Recipient filter.
00075                      * @return                                        Pl_Continue to allow message, Pl_Stop or Pl_Handled to scrap it.
00076                      */
00077                     virtual ResultType InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
00078                     {
00079                               return Pl_Continue;
00080                     }
00081 
00082                     /**
00083                      * @brief Called when a hooked user message is sent, regardless of the hook type.
00084                      * @param msg_id              Message Id.
00085                      */
00086                     virtual void OnUserMessageSent(int msg_id)
00087                     {
00088                     }
00089           };
00090 
00091           #define USERMSG_RELIABLE                          (1<<2)              /**< Message will be set to reliable */
00092           #define USERMSG_INITMSG                                     (1<<3)              /**< Message will be considered to be an initmsg */
00093           #define USERMSG_BLOCKHOOKS                        (1<<7)              /**< Prevents the message from triggering SourceMod and Metamod hooks */
00094 
00095           /**
00096            * @brief Contains functions for hooking user messages.
00097            */
00098           class IUserMessages : public SMInterface
00099           {
00100           public:
00101                     virtual unsigned int GetInterfaceVersion()
00102                     {
00103                               return SMINTERFACE_USERMSGS_VERSION;
00104                     }
00105                     virtual const char *GetInterfaceName()
00106                     {
00107                               return SMINTERFACE_USERMSGS_NAME;
00108                     }
00109           public:
00110                     /**
00111                      * @brief Finds a message id by name.
00112                      *
00113                      * @param msg                 Case-sensitive string containing the message.
00114                      * @return                              A message index, or -1 on failure.
00115                      */
00116                     virtual int GetMessageIndex(const char *msg) =0;
00117 
00118                     /**
00119                      * @brief Sets a hook on a user message.
00120                      *
00121                      * @param msg_id              Message Id.
00122                      * @param pListener           Pointer to an IUserMessageListener.
00123                      * @param intercept           If true, message will be intercepted rather than merely hooked.
00124                      * @return                                        True on success, false otherwise.
00125                      */
00126                     virtual bool HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
00127 
00128                     /**
00129                      * @brief Unhooks a user message.
00130                      *
00131                      * @param msg_id              Message Id.
00132                      * @param pListener           Pointer to an IUserMessageListener.
00133                      * @param intercept           If true, removed message will from interception pool rather than normal hook pool.
00134                      * @return                                        True on success, false otherwise.
00135                      */
00136                     virtual bool UnhookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false) =0;
00137 
00138                     /**
00139                      * @brief Wrapper around UserMessageBegin for more options.
00140                      * 
00141                      * @param msg_id              Message Id.
00142                      * @param players             Array containing player indexes.
00143                      * @param playersNum          Number of players in the array.
00144                      * @param flags                         Flags to use for sending the message.
00145                      * @return                                        bf_write structure to write message with, or NULL on failure.
00146                      */
00147                     virtual bf_write *StartMessage(int msg_id, const cell_t players[], unsigned int playersNum, int flags) =0;
00148 
00149                     /**
00150                      * @brief Wrapper around UserMessageEnd for use with StartMessage().
00151                      * @return                                        True on success, false otherwise.
00152                      */
00153                     virtual bool EndMessage() =0;
00154           };
00155 }
00156 
00157 #endif //_INCLUDE_SOURCEMOD_INTERFACE_USERMESSAGES_H_

Generated on Fri Nov 21 02:10:02 2008 for SourceMod SDK by  doxygen 1.5.1