]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands/cmd_privmsg.cpp
Add a Flash Policy Daemon module
[user/henk/code/inspircd.git] / src / commands / cmd_privmsg.cpp
index eb9468bb96186c4618b08b3872ab2b9f7fb8f139..79437432ff816471e0934dfb514304af2784075b 100644 (file)
@@ -28,9 +28,14 @@ namespace
 
 class MessageCommandBase : public Command
 {
+       ChanModeReference moderatedmode;
+       ChanModeReference noextmsgmode;
+
  public:
        MessageCommandBase(Module* parent, MessageType mt)
                : Command(parent, MessageTypeString[mt], 2, 2)
+               , moderatedmode(parent, "moderated")
+               , noextmsgmode(parent, "noextmsg")
        {
                syntax = "<target>{,<target>} <message>";
        }
@@ -62,7 +67,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
        if (localuser)
                localuser->idle_lastmsg = ServerInstance->Time();
 
-       if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
+       if (CommandParser::LoopCall(user, this, parameters, 0))
                return CMD_SUCCESS;
 
        if (parameters[0][0] == '$')
@@ -79,12 +84,12 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                const char* text = temp.c_str();
                const char* servermask = (parameters[0].c_str()) + 1;
 
-               FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
+               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);
                }
-               FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list, mt));
+               FOREACH_MOD(OnUserMessage, (user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list, mt));
                return CMD_SUCCESS;
        }
        char status = 0;
@@ -105,15 +110,15 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                {
                        if (localuser && chan->GetPrefixValue(user) < VOICE_VALUE)
                        {
-                               if (chan->IsModeSet('n') && !chan->HasUser(user))
+                               if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(user))
                                {
-                                       user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
+                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Cannot send to channel (no external messages)", chan->name.c_str());
                                        return CMD_FAILURE;
                                }
 
-                               if (chan->IsModeSet('m'))
+                               if (chan->IsModeSet(moderatedmode))
                                {
-                                       user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
+                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Cannot send to channel (+m)", chan->name.c_str());
                                        return CMD_FAILURE;
                                }
 
@@ -121,7 +126,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                                {
                                        if (chan->IsBanned(user))
                                        {
-                                               user->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", user->nick.c_str(), chan->name.c_str());
+                                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Cannot send to channel (you're banned)", chan->name.c_str());
                                                return CMD_FAILURE;
                                        }
                                }
@@ -138,11 +143,11 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                        /* Check again, a module may have zapped the input string */
                        if (temp.empty())
                        {
-                               user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
+                               user->WriteNumeric(ERR_NOTEXTTOSEND, ":No text to send");
                                return CMD_FAILURE;
                        }
 
-                       FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,except_list));
+                       FOREACH_MOD(OnText, (user,chan,TYPE_CHANNEL,text,status,except_list));
 
                        if (status)
                        {
@@ -160,12 +165,12 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                                chan->WriteAllExcept(user, false, status, except_list, "%s %s :%s", MessageTypeString[mt], chan->name.c_str(), text);
                        }
 
-                       FOREACH_MOD(I_OnUserMessage, OnUserMessage(user,chan, TYPE_CHANNEL, text, status, except_list, mt));
+                       FOREACH_MOD(OnUserMessage, (user,chan, TYPE_CHANNEL, text, status, except_list, mt));
                }
                else
                {
                        /* no such nick/channel */
-                       user->WriteNumeric(401, "%s %s :No such nick/channel", user->nick.c_str(), target);
+                       user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", target);
                        return CMD_FAILURE;
                }
                return CMD_SUCCESS;
@@ -186,7 +191,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                        if (dest && strcasecmp(dest->server.c_str(), targetserver + 1))
                        {
                                /* Incorrect server for user */
-                               user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
+                               user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
                                return CMD_FAILURE;
                        }
                }
@@ -200,14 +205,14 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
        {
                if (parameters[1].empty())
                {
-                       user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
+                       user->WriteNumeric(ERR_NOTEXTTOSEND, ":No text to send");
                        return CMD_FAILURE;
                }
 
                if ((dest->IsAway()) && (mt == MSG_PRIVMSG))
                {
                        /* auto respond with aweh msg */
-                       user->WriteNumeric(301, "%s %s :%s", user->nick.c_str(), dest->nick.c_str(), dest->awaymsg.c_str());
+                       user->WriteNumeric(RPL_AWAY, "%s :%s", dest->nick.c_str(), dest->awaymsg.c_str());
                }
 
                ModResult MOD_RESULT;
@@ -219,7 +224,7 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
 
                const char* text = temp.c_str();
 
-               FOREACH_MOD(I_OnText,OnText(user, dest, TYPE_USER, text, 0, except_list));
+               FOREACH_MOD(OnText, (user, dest, TYPE_USER, text, 0, except_list));
 
                if (IS_LOCAL(dest))
                {
@@ -227,12 +232,12 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para
                        user->WriteTo(dest, "%s %s :%s", MessageTypeString[mt], dest->nick.c_str(), text);
                }
 
-               FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, dest, TYPE_USER, text, 0, except_list, mt));
+               FOREACH_MOD(OnUserMessage, (user, dest, TYPE_USER, text, 0, except_list, mt));
        }
        else
        {
                /* no such nick/channel */
-               user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
+               user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
                return CMD_FAILURE;
        }
        return CMD_SUCCESS;
@@ -264,12 +269,6 @@ class ModuleCoreMessage : public Module
        {
        }
 
-       void init()
-       {
-               ServerInstance->Modules->AddService(CommandPrivmsg);
-               ServerInstance->Modules->AddService(CommandNotice);
-       }
-
        Version GetVersion()
        {
                return Version("PRIVMSG, NOTICE", VF_CORE|VF_VENDOR);