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"
23 void cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
28 user->idle_lastmsg = ServerInstance->Time();
30 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
32 if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
35 std::string temp = parameters[1];
36 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0));
39 parameters[1] = (char*)temp.c_str();
40 // notice to server mask
41 const char* servermask = parameters[0] + 1;
42 if (match(ServerInstance->Config->ServerName,servermask))
44 user->NoticeAll("%s",parameters[1]);
46 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0));
50 if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
52 status = *parameters[0];
55 if (*parameters[0] == '#')
57 chan = ServerInstance->FindChan(parameters[0]);
62 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
64 user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
67 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
69 user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
76 std::string temp = parameters[1];
77 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status));
81 parameters[1] = (char*)temp.c_str();
85 user->WriteServ("412 %s No text to send", user->nick);
89 chan->WriteAllExceptSender(user, status, "NOTICE %s :%s", chan->name, parameters[1]);
91 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status));
95 /* no such nick/channel */
96 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
101 dest = ServerInstance->FindNick(parameters[0]);
106 std::string temp = parameters[1];
107 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0));
111 parameters[1] = (char*)temp.c_str();
115 // direct write, same server
116 user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
119 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0));
123 /* no such nick/channel */
124 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);