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 * ---------------------------------------------------
15 #include "configreader.h"
19 #include "commands/cmd_notice.h"
21 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
23 return new cmd_notice(Instance);
26 CmdResult cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
33 user->idle_lastmsg = ServerInstance->Time();
35 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
37 if ((parameters[0][0] == '$') && (IS_OPER(user) || ServerInstance->ULine(user->server)))
40 std::string temp = parameters[1];
41 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0,exempt_list));
44 parameters[1] = temp.c_str();
45 // notice to server mask
46 const char* servermask = parameters[0] + 1;
47 if (match(ServerInstance->Config->ServerName,servermask))
49 user->SendAll("NOTICE", "%s", parameters[1]);
51 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
55 if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
57 status = *parameters[0];
60 if (*parameters[0] == '#')
62 chan = ServerInstance->FindChan(parameters[0]);
64 exempt_list[user] = user->nick;
70 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
72 user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
75 if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE))
77 user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
83 std::string temp = parameters[1];
84 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
88 parameters[1] = temp.c_str();
92 user->WriteServ("412 %s :No text to send", user->nick);
98 if (ServerInstance->Config->UndernetMsgPrefix)
100 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name, status, parameters[1]);
104 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name, parameters[1]);
109 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name, parameters[1]);
112 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status,exempt_list));
116 /* no such nick/channel */
117 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
123 dest = ServerInstance->FindNick(parameters[0]);
128 user->WriteServ("412 %s :No text to send", user->nick);
133 std::string temp = parameters[1];
134 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
138 parameters[1] = (char*)temp.c_str();
142 // direct write, same server
143 user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
146 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
150 /* no such nick/channel */
151 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);