]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_callerid.cpp
m_filter Rename exemptfromfilter field to exemptedchans, use std::set::count()
[user/henk/code/inspircd.git] / src / modules / m_callerid.cpp
index 7d8247530592c8f8cc32351479efe8e9a83e33d7..6f2c6730085560a8715ffc53fdfa09993c76970f 100644 (file)
@@ -158,13 +158,18 @@ class CommandAccept : public Command
         */
        typedef std::pair<User*, bool> ACCEPTAction;
 
-       ACCEPTAction GetTargetAndAction(std::string& tok)
+       static ACCEPTAction GetTargetAndAction(std::string& tok, User* cmdfrom = NULL)
        {
                bool remove = (tok[0] == '-');
                if ((remove) || (tok[0] == '+'))
                        tok.erase(tok.begin());
 
-               User* target = ServerInstance->FindNick(tok);
+               User* target;
+               if (!cmdfrom || !IS_LOCAL(cmdfrom))
+                       target = ServerInstance->FindNick(tok);
+               else
+                       target = ServerInstance->FindNickOnly(tok);
+
                if ((!target) || (target->registered != REG_ALL) || (target->quitting) || (IS_SERVER(target)))
                        target = NULL;
 
@@ -216,7 +221,7 @@ public:
                }
 
                std::string tok = parameters[0];
-               ACCEPTAction action = GetTargetAndAction(tok);
+               ACCEPTAction action = GetTargetAndAction(tok, user);
                if (!action.first)
                {
                        user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", tok.c_str());
@@ -248,7 +253,7 @@ public:
 
                // Find the target
                std::string targetstring = parameters[0];
-               ACCEPTAction action = GetTargetAndAction(targetstring);
+               ACCEPTAction action = GetTargetAndAction(targetstring, user);
                if (!action.first)
                        // Target is a "*" or source is local and the target is a list of nicks
                        return ROUTE_LOCALONLY;
@@ -383,8 +388,12 @@ public:
                tokens["CALLERID"] = "g";
        }
 
-       ModResult PreText(User* user, User* dest, std::string& text)
+       ModResult OnUserPreMessage(User* user, void* voiddest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
+               if (!IS_LOCAL(user) || target_type != TYPE_USER)
+                       return MOD_RES_PASSTHRU;
+
+               User* dest = static_cast<User*>(voiddest);
                if (!dest->IsModeSet(myumode) || (user == dest))
                        return MOD_RES_PASSTHRU;
 
@@ -402,8 +411,8 @@ public:
                        if (now > (dat->lastnotify + (time_t)notify_cooldown))
                        {
                                user->WriteNumeric(RPL_TARGNOTIFY, "%s :has been informed that you messaged them.", dest->nick.c_str());
-                               dest->WriteNumeric(RPL_UMODEGMSG, "%s %s@%s :is messaging you, and you have umode +g. Use /ACCEPT +%s to allow.",
-                                               user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), user->nick.c_str());
+                               dest->SendText(":%s %03d %s %s %s@%s :is messaging you, and you have umode +g. Use /ACCEPT +%s to allow.",
+                                               ServerInstance->Config->ServerName.c_str(), RPL_UMODEGMSG, dest->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), user->nick.c_str());
                                dat->lastnotify = now;
                        }
                        return MOD_RES_DENY;
@@ -411,14 +420,6 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
-       {
-               if (IS_LOCAL(user) && target_type == TYPE_USER)
-                       return PreText(user, (User*)dest, text);
-
-               return MOD_RES_PASSTHRU;
-       }
-
        void OnUserPostNick(User* user, const std::string& oldnick) CXX11_OVERRIDE
        {
                if (!tracknick)