]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_privmsg.cpp
Use an oper priv instead of a config flag for overriding nonicks.
[user/henk/code/inspircd.git] / src / coremods / core_privmsg.cpp
index 34527027c89e28358be1a4d6d06c9608b7b46b3e..f1461df5f52a363481b5e967424dd50c2dfde2e5 100644 (file)
@@ -54,10 +54,10 @@ class MessageCommandBase : public Command
         */
        CmdResult HandleMessage(const std::vector<std::string>& parameters, User* user, MessageType mt);
 
-       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE
        {
                if (IS_LOCAL(user))
-                       // This is handled by the OnUserMessage hook to split the LoopCall pieces
+                       // This is handled by the OnUserPostMessage hook to split the LoopCall pieces
                        return ROUTE_LOCALONLY;
                else
                        return ROUTE_MESSAGE(parameters[0]);
@@ -79,7 +79,6 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
 {
        User *dest;
        Channel *chan;
-       CUList except_list;
 
        LocalUser* localuser = IS_LOCAL(user);
        if (localuser)
@@ -93,23 +92,24 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                if (!user->HasPrivPermission("users/mass-message"))
                        return CMD_SUCCESS;
 
+               std::string servername(parameters[0], 1);
+               MessageTarget msgtarget(&servername);
+               MessageDetails msgdetails(mt, parameters[1]);
+
                ModResult MOD_RESULT;
-               std::string temp = parameters[1];
-               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, except_list, mt));
+               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, msgtarget, msgdetails));
                if (MOD_RESULT == MOD_RES_DENY)
                        return CMD_FAILURE;
 
-               const char* text = temp.c_str();
-               const char* servermask = (parameters[0].c_str()) + 1;
-
-               FOREACH_MOD(OnText, (user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
-               if (InspIRCd::Match(ServerInstance->Config->ServerName, servermask, NULL))
+               FOREACH_MOD(OnUserMessage, (user, msgtarget, msgdetails));
+               if (InspIRCd::Match(ServerInstance->Config->ServerName, servername, NULL))
                {
-                       SendAll(user, text, mt);
+                       SendAll(user, msgdetails.text, mt);
                }
-               FOREACH_MOD(OnUserMessage, (user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list, mt));
+               FOREACH_MOD(OnUserPostMessage, (user, msgtarget, msgdetails));
                return CMD_SUCCESS;
        }
+
        char status = 0;
        const char* target = parameters[0].c_str();
 
@@ -122,21 +122,19 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
        {
                chan = ServerInstance->FindChan(target);
 
-               except_list.insert(user);
-
                if (chan)
                {
                        if (localuser && chan->GetPrefixValue(user) < VOICE_VALUE)
                        {
                                if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(user))
                                {
-                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Cannot send to channel (no external messages)", chan->name.c_str());
+                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (no external messages)");
                                        return CMD_FAILURE;
                                }
 
                                if (chan->IsModeSet(moderatedmode))
                                {
-                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Cannot send to channel (+m)", chan->name.c_str());
+                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (+m)");
                                        return CMD_FAILURE;
                                }
 
@@ -144,51 +142,45 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                                {
                                        if (chan->IsBanned(user))
                                        {
-                                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Cannot send to channel (you're banned)", chan->name.c_str());
+                                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)");
                                                return CMD_FAILURE;
                                        }
                                }
                        }
-                       ModResult MOD_RESULT;
 
-                       std::string temp = parameters[1];
-                       FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, chan, TYPE_CHANNEL, temp, status, except_list, mt));
+                       MessageTarget msgtarget(chan, status);
+                       MessageDetails msgdetails(mt, parameters[1]);
+                       msgdetails.exemptions.insert(user);
+
+                       ModResult MOD_RESULT;
+                       FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, msgtarget, msgdetails));
                        if (MOD_RESULT == MOD_RES_DENY)
                                return CMD_FAILURE;
 
-                       const char* text = temp.c_str();
-
                        /* Check again, a module may have zapped the input string */
-                       if (temp.empty())
+                       if (msgdetails.text.empty())
                        {
-                               user->WriteNumeric(ERR_NOTEXTTOSEND, ":No text to send");
+                               user->WriteNumeric(ERR_NOTEXTTOSEND, "No text to send");
                                return CMD_FAILURE;
                        }
 
-                       FOREACH_MOD(OnText, (user,chan,TYPE_CHANNEL,text,status,except_list));
+                       FOREACH_MOD(OnUserMessage, (user, msgtarget, msgdetails));
 
                        if (status)
                        {
-                               if (ServerInstance->Config->UndernetMsgPrefix)
-                               {
-                                       chan->WriteAllExcept(user, false, status, except_list, "%s %c%s :%c %s", MessageTypeString[mt], status, chan->name.c_str(), status, text);
-                               }
-                               else
-                               {
-                                       chan->WriteAllExcept(user, false, status, except_list, "%s %c%s :%s", MessageTypeString[mt], status, chan->name.c_str(), text);
-                               }
+                               chan->WriteAllExcept(user, false, status, msgdetails.exemptions, "%s %c%s :%s", MessageTypeString[mt], status, chan->name.c_str(), msgdetails.text.c_str());
                        }
                        else
                        {
-                               chan->WriteAllExcept(user, false, status, except_list, "%s %s :%s", MessageTypeString[mt], chan->name.c_str(), text);
+                               chan->WriteAllExcept(user, false, status, msgdetails.exemptions, "%s %s :%s", MessageTypeString[mt], chan->name.c_str(), msgdetails.text.c_str());
                        }
 
-                       FOREACH_MOD(OnUserMessage, (user,chan, TYPE_CHANNEL, text, status, except_list, mt));
+                       FOREACH_MOD(OnUserPostMessage, (user, msgtarget, msgdetails));
                }
                else
                {
-                       /* no such nick/channel */
-                       user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", target);
+                       /* channel does not exist */
+                       user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
                        return CMD_FAILURE;
                }
                return CMD_SUCCESS;
@@ -209,7 +201,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                        if (dest && strcasecmp(dest->server->GetName().c_str(), targetserver + 1))
                        {
                                /* Incorrect server for user */
-                               user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
+                               user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
                                return CMD_FAILURE;
                        }
                }
@@ -223,39 +215,38 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
        {
                if (parameters[1].empty())
                {
-                       user->WriteNumeric(ERR_NOTEXTTOSEND, ":No text to send");
+                       user->WriteNumeric(ERR_NOTEXTTOSEND, "No text to send");
                        return CMD_FAILURE;
                }
 
                if ((dest->IsAway()) && (mt == MSG_PRIVMSG))
                {
                        /* auto respond with aweh msg */
-                       user->WriteNumeric(RPL_AWAY, "%s :%s", dest->nick.c_str(), dest->awaymsg.c_str());
+                       user->WriteNumeric(RPL_AWAY, dest->nick, dest->awaymsg);
                }
 
-               ModResult MOD_RESULT;
+               MessageTarget msgtarget(dest);
+               MessageDetails msgdetails(mt, parameters[1]);
 
-               std::string temp = parameters[1];
-               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, dest, TYPE_USER, temp, 0, except_list, mt));
+               ModResult MOD_RESULT;
+               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, msgtarget, msgdetails));
                if (MOD_RESULT == MOD_RES_DENY)
                        return CMD_FAILURE;
 
-               const char* text = temp.c_str();
-
-               FOREACH_MOD(OnText, (user, dest, TYPE_USER, text, 0, except_list));
+               FOREACH_MOD(OnUserMessage, (user, msgtarget, msgdetails));
 
                if (IS_LOCAL(dest))
                {
                        // direct write, same server
-                       dest->WriteFrom(user, "%s %s :%s", MessageTypeString[mt], dest->nick.c_str(), text);
+                       dest->WriteFrom(user, "%s %s :%s", MessageTypeString[mt], dest->nick.c_str(), msgdetails.text.c_str());
                }
 
-               FOREACH_MOD(OnUserMessage, (user, dest, TYPE_USER, text, 0, except_list, mt));
+               FOREACH_MOD(OnUserPostMessage, (user, msgtarget, msgdetails));
        }
        else
        {
                /* no such nick/channel */
-               user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
+               user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
                return CMD_FAILURE;
        }
        return CMD_SUCCESS;
@@ -270,7 +261,7 @@ class CommandMessage : public MessageCommandBase
        {
        }
 
-       CmdResult Handle(const std::vector<std::string>& parameters, User* user)
+       CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
        {
                return HandleMessage(parameters, user, MT);
        }
@@ -287,7 +278,7 @@ class ModuleCoreMessage : public Module
        {
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("PRIVMSG, NOTICE", VF_CORE|VF_VENDOR);
        }