]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add new event for this with gauranteed delivery of message BEFORE the text is sent out
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 26 Oct 2007 20:48:58 +0000 (20:48 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 26 Oct 2007 20:48:58 +0000 (20:48 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8376 e03df62e-2008-0410-955e-edbf42e46eb7

include/modules.h
src/commands/cmd_notice.cpp
src/commands/cmd_privmsg.cpp
src/modules.cpp
src/modules/m_delayjoin.cpp

index 5327311fba14d869cadbc57b3111730829de50b0..50142e253af8e591b3447b190e7a0c90fcc61d9d 100644 (file)
@@ -380,7 +380,8 @@ enum Implementation {       I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUse
                        I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnOperCompre, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan, I_OnDelBan,
                        I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
                        I_OnOperCompare, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway, I_OnUserList,
-                       I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect, I_OnBufferFlushed };
+                       I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect, I_OnBufferFlushed,
+                       I_OnText };
 
 /** Base class for all InspIRCd modules
  *  This class is the base class for InspIRCd modules. All modules must inherit from this class,
@@ -716,6 +717,20 @@ class CoreExport Module : public Extensible
         */
        virtual void OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list);
 
+       /** Called immediately before any NOTICE or PRIVMSG sent from a user, local or remote.
+        * The dest variable contains a User* if target_type is TYPE_USER and a Channel*
+        * if target_type is TYPE_CHANNEL.
+        * The difference between this event and OnUserPreNotice/OnUserPreMessage is that delivery is gauranteed,
+        * the message has already been vetted. In the case of the other two methods, a later module may stop your
+        * message. This also differs from OnUserMessage which occurs AFTER the message has been sent.
+        * @param user The user sending the message
+        * @param dest The target of the message
+        * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
+        * @param text the text being sent by the user
+        * @param status The status being used, e.g. NOTICE @#chan has status== '@', 0 to send to everyone.
+        */
+       virtual void OnText(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
+
        /** Called after every MODE command sent from a user
         * The dest variable contains a User* if target_type is TYPE_USER and a Channel*
         * if target_type is TYPE_CHANNEL. The text variable contains the remainder of the
index 9cc846dd86f06dccef8cccf9f794b790458f1ac3..1f5b854e6e74902aeab01034928431404eaed85a 100644 (file)
@@ -41,6 +41,7 @@ CmdResult CommandNotice::Handle (const char** parameters, int pcnt, User *user)
                parameters[1] = temp.c_str();
                // notice to server mask
                const char* servermask = parameters[0] + 1;
+               FOREACH_MOD(I_OnText,OnText(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
                if (match(ServerInstance->Config->ServerName,servermask))
                {
                        user->SendAll("NOTICE", "%s", parameters[1]);
@@ -90,6 +91,8 @@ CmdResult CommandNotice::Handle (const char** parameters, int pcnt, User *user)
                                return CMD_FAILURE;
                        }
 
+                       FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,parameters[1],status,except_list));
+
                        if (status)
                        {
                                if (ServerInstance->Config->UndernetMsgPrefix)
@@ -138,6 +141,8 @@ CmdResult CommandNotice::Handle (const char** parameters, int pcnt, User *user)
                }
                parameters[1] = (char*)temp.c_str();
 
+               FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,parameters[1],0,exempt_list));
+
                if (IS_LOCAL(dest))
                {
                        // direct write, same server
index 96aff839246ae6c00a621ea031e0a6401391fec8..474eb4b3d6c4a81e4bb97ab68c46fe15ff69c4f2 100644 (file)
@@ -41,6 +41,7 @@ CmdResult CommandPrivmsg::Handle (const char** parameters, int pcnt, User *user)
                parameters[1] = temp.c_str();
                // notice to server mask
                const char* servermask = parameters[0] + 1;
+               FOREACH_MOD(I_OnText,OnText(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,except_list));
                if (match(ServerInstance->Config->ServerName,servermask))
                {
                        user->SendAll("PRIVMSG", "%s", parameters[1]);
@@ -91,6 +92,8 @@ CmdResult CommandPrivmsg::Handle (const char** parameters, int pcnt, User *user)
                                return CMD_FAILURE;
                        }
 
+                       FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,parameters[1],status,except_list));
+
                        if (status)
                        {
                                if (ServerInstance->Config->UndernetMsgPrefix)
@@ -146,6 +149,8 @@ CmdResult CommandPrivmsg::Handle (const char** parameters, int pcnt, User *user)
                }
                parameters[1] = (char*)temp.c_str();
 
+               FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,parameters[1],0,except_list));
+
                if (IS_LOCAL(dest))
                {
                        // direct write, same server
index e801543fb4df90f49a1b8504a6f0930d7d3a3656..6ef0975d6dbac6e425f1e858b603f469b8e9f54b 100644 (file)
@@ -196,6 +196,7 @@ int         Module::OnWhoisLine(User*, User*, int&, std::string&) { return 0; }
 void           Module::OnBuildExemptList(MessageType, Channel*, User*, char, CUList&, const std::string&) { }
 void           Module::OnGarbageCollect() { }
 void           Module::OnBufferFlushed(User*) { }
+void           Module::OnText(User*, void*, int, std::string&, char, CUList&) { }
 
 
 ModuleManager::ModuleManager(InspIRCd* Ins)
index d968f34a278c703b444b2e563c4d15f3982f6160..9626d978038b1d56a8d8922fcaea82f58afba63f 100644 (file)
@@ -170,15 +170,15 @@ class ModuleDelayJoin : public Module
                }
        }
 
-       int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       void OnText(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
        {
                if (target_type != TYPE_CHANNEL)
-                       return 0;
+                       return;
 
                Channel* channel = (Channel*) dest;
 
                if (!user->GetExt(std::string("delayjoin_")+channel->name))
-                       return 0;
+                       return;
 
                /* Display the join to everyone else (the user who joined got it earlier) */
                channel->WriteAllExcept(user, false, 0, exempt_list, "JOIN %s", channel->name);
@@ -191,16 +191,9 @@ class ModuleDelayJoin : public Module
                 */
                for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
                        if (f->first->IsModeSet('D'))
-                               return 0;
+                               return;
 
                user->Shrink("delayjoin");
-
-               return 0;
-       }
-
-       int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
        }
 };