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 * ---------------------------------------------------
16 #include "commands/cmd_notice.h"
18 extern "C" DllExport Command* init_command(InspIRCd* Instance)
20 return new cmd_notice(Instance);
23 CmdResult cmd_notice::Handle (const char** parameters, int pcnt, User *user)
30 user->idle_lastmsg = ServerInstance->Time();
32 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
34 if ((parameters[0][0] == '$') && (IS_OPER(user) || ServerInstance->ULine(user->server)))
37 std::string temp = parameters[1];
38 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0,exempt_list));
41 parameters[1] = temp.c_str();
42 // notice to server mask
43 const char* servermask = parameters[0] + 1;
44 if (match(ServerInstance->Config->ServerName,servermask))
46 user->SendAll("NOTICE", "%s", parameters[1]);
48 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
52 if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
54 status = *parameters[0];
57 if (*parameters[0] == '#')
59 chan = ServerInstance->FindChan(parameters[0]);
61 exempt_list[user] = user->nick;
67 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
69 user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
72 if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE))
74 user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
80 std::string temp = parameters[1];
81 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
85 parameters[1] = temp.c_str();
89 user->WriteServ("412 %s :No text to send", user->nick);
95 if (ServerInstance->Config->UndernetMsgPrefix)
97 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name, status, parameters[1]);
101 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name, parameters[1]);
106 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name, parameters[1]);
109 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status,exempt_list));
113 /* no such nick/channel */
114 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
121 dest = ServerInstance->FindNickOnly(parameters[0]);
123 dest = ServerInstance->FindNick(parameters[0]);
129 user->WriteServ("412 %s :No text to send", user->nick);
134 std::string temp = parameters[1];
135 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
139 parameters[1] = (char*)temp.c_str();
143 // direct write, same server
144 user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
147 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
151 /* no such nick/channel */
152 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);