1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
21 #include "configreader.h"
29 #include "commands/cmd_notice.h"
31 void cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
36 user->idle_lastmsg = ServerInstance->Time();
38 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
40 if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
43 std::string temp = parameters[1];
44 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0));
47 parameters[1] = (char*)temp.c_str();
48 // notice to server mask
49 const char* servermask = parameters[0] + 1;
50 if (match(ServerInstance->Config->ServerName,servermask))
52 user->NoticeAll("%s",parameters[1]);
54 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0));
58 if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
60 status = *parameters[0];
63 if (*parameters[0] == '#')
65 chan = ServerInstance->FindChan(parameters[0]);
70 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
72 user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
75 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
77 user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
84 std::string temp = parameters[1];
85 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status));
89 parameters[1] = (char*)temp.c_str();
93 user->WriteServ("412 %s No text to send", user->nick);
97 chan->WriteAllExceptSender(user, status, "NOTICE %s :%s", chan->name, parameters[1]);
99 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status));
103 /* no such nick/channel */
104 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
109 dest = ServerInstance->FindNick(parameters[0]);
114 std::string temp = parameters[1];
115 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0));
119 parameters[1] = (char*)temp.c_str();
123 // direct write, same server
124 user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
127 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0));
131 /* no such nick/channel */
132 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);