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 * ---------------------------------------------------
17 #include "configreader.h"
21 #include "commands/cmd_notice.h"
25 extern "C" command_t* init_command(InspIRCd* Instance)
27 return new cmd_notice(Instance);
30 CmdResult cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
35 user->idle_lastmsg = ServerInstance->Time();
37 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
39 if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
42 std::string temp = parameters[1];
43 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0));
46 parameters[1] = (char*)temp.c_str();
47 // notice to server mask
48 const char* servermask = parameters[0] + 1;
49 if (match(ServerInstance->Config->ServerName,servermask))
51 user->NoticeAll("%s",parameters[1]);
53 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0));
57 if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
59 status = *parameters[0];
62 if (*parameters[0] == '#')
64 chan = ServerInstance->FindChan(parameters[0]);
69 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
71 user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
74 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
76 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));
88 parameters[1] = temp.c_str();
92 user->WriteServ("412 %s No text to send", user->nick);
96 chan->WriteAllExceptSender(user, false, status, "NOTICE %s :%s", chan->name, parameters[1]);
98 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status));
102 /* no such nick/channel */
103 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]);