]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_privmsg.cpp
Add RPL_WHOREPLY to the list of numerics
[user/henk/code/inspircd.git] / src / coremods / core_privmsg.cpp
index 0cca5677159f33f324a1daaf3f4202cd8d558d3c..cccba0850501f1ac6c7ba7138c570327d8237fd9 100644 (file)
@@ -31,6 +31,13 @@ class MessageCommandBase : public Command
        ChanModeReference moderatedmode;
        ChanModeReference noextmsgmode;
 
+       /** Send a PRIVMSG or NOTICE message to all local users from the given user
+        * @param user User sending the message
+        * @param msg The message to send
+        * @param mt Type of the message (MSG_PRIVMSG or MSG_NOTICE)
+        */
+       static void SendAll(User* user, const std::string& msg, MessageType mt);
+
  public:
        MessageCommandBase(Module* parent, MessageType mt)
                : Command(parent, MessageTypeString[mt], 2, 2)
@@ -57,6 +64,17 @@ class MessageCommandBase : public Command
        }
 };
 
+void MessageCommandBase::SendAll(User* user, const std::string& msg, MessageType mt)
+{
+       const std::string message = ":" + user->GetFullHost() + " " + MessageTypeString[mt] + " $* :" + msg;
+       const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
+       for (UserManager::LocalList::const_iterator i = list.begin(); i != list.end(); ++i)
+       {
+               if ((*i)->registered == REG_ALL)
+                       (*i)->Write(message);
+       }
+}
+
 CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& parameters, User* user, MessageType mt)
 {
        User *dest;
@@ -87,7 +105,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                FOREACH_MOD(OnText, (user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
                if (InspIRCd::Match(ServerInstance->Config->ServerName, servermask, NULL))
                {
-                       user->SendAll(MessageTypeString[mt], "%s", text);
+                       SendAll(user, text, mt);
                }
                FOREACH_MOD(OnUserMessage, (user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list, mt));
                return CMD_SUCCESS;
@@ -112,13 +130,13 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                        {
                                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;
                                }
 
@@ -126,7 +144,7 @@ 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;
                                        }
                                }
@@ -143,7 +161,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                        /* Check again, a module may have zapped the input string */
                        if (temp.empty())
                        {
-                               user->WriteNumeric(ERR_NOTEXTTOSEND, ":No text to send");
+                               user->WriteNumeric(ERR_NOTEXTTOSEND, "No text to send");
                                return CMD_FAILURE;
                        }
 
@@ -151,14 +169,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
 
                        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, except_list, "%s %c%s :%s", MessageTypeString[mt], status, chan->name.c_str(), text);
                        }
                        else
                        {
@@ -170,7 +181,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                else
                {
                        /* no such nick/channel */
-                       user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", target);
+                       user->WriteNumeric(Numerics::NoSuchNick(target));
                        return CMD_FAILURE;
                }
                return CMD_SUCCESS;
@@ -191,7 +202,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;
                        }
                }
@@ -205,14 +216,14 @@ 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;
@@ -229,7 +240,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                if (IS_LOCAL(dest))
                {
                        // direct write, same server
-                       user->WriteTo(dest, "%s %s :%s", MessageTypeString[mt], dest->nick.c_str(), text);
+                       dest->WriteFrom(user, "%s %s :%s", MessageTypeString[mt], dest->nick.c_str(), text);
                }
 
                FOREACH_MOD(OnUserMessage, (user, dest, TYPE_USER, text, 0, except_list, mt));
@@ -237,7 +248,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
        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;