1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #include "configreader.h"
18 #include "commands/cmd_notice.h"
22 extern "C" command_t* init_command(InspIRCd* Instance)
24 return new cmd_notice(Instance);
27 CmdResult cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
34 user->idle_lastmsg = ServerInstance->Time();
36 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
38 if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
41 std::string temp = parameters[1];
42 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0,exempt_list));
45 parameters[1] = (char*)temp.c_str();
46 // notice to server mask
47 const char* servermask = parameters[0] + 1;
48 if (match(ServerInstance->Config->ServerName,servermask))
50 user->NoticeAll("%s",parameters[1]);
52 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
56 if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
58 status = *parameters[0];
61 if (*parameters[0] == '#')
63 chan = ServerInstance->FindChan(parameters[0]);
65 exempt_list[user] = user;
71 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
73 user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
76 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
78 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, exempt_list));
89 parameters[1] = temp.c_str();
93 user->WriteServ("412 %s No text to send", user->nick);
99 if (ServerInstance->Config->UndernetMsgPrefix)
101 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name, status, parameters[1]);
105 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name, parameters[1]);
110 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name, parameters[1]);
113 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status,exempt_list));
117 /* no such nick/channel */
118 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
124 dest = ServerInstance->FindNick(parameters[0]);
129 std::string temp = parameters[1];
130 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
134 parameters[1] = (char*)temp.c_str();
138 // direct write, same server
139 user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
142 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
146 /* no such nick/channel */
147 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);