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)
37 user->idle_lastmsg = ServerInstance->Time();
39 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
41 if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
44 std::string temp = parameters[1];
45 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0,exempt_list));
48 parameters[1] = (char*)temp.c_str();
49 // notice to server mask
50 const char* servermask = parameters[0] + 1;
51 if (match(ServerInstance->Config->ServerName,servermask))
53 user->NoticeAll("%s",parameters[1]);
55 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
59 if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
61 status = *parameters[0];
64 if (*parameters[0] == '#')
66 chan = ServerInstance->FindChan(parameters[0]);
68 exempt_list[user] = user;
74 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
76 user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
79 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
81 user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
88 std::string temp = parameters[1];
89 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
93 parameters[1] = temp.c_str();
97 user->WriteServ("412 %s No text to send", user->nick);
103 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name, status, parameters[1]);
107 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name, parameters[1]);
110 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status,exempt_list));
114 /* no such nick/channel */
115 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
121 dest = ServerInstance->FindNick(parameters[0]);
126 std::string temp = parameters[1];
127 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
131 parameters[1] = (char*)temp.c_str();
135 // direct write, same server
136 user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
139 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
143 /* no such nick/channel */
144 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);