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 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include "inspircd_io.h"
25 #include <ext/hash_map>
43 #include "inspstring.h"
45 #include "helperfuncs.h"
47 #include "socketengine.h"
49 #include "command_parse.h"
50 #include "cmd_notice.h"
52 extern ServerConfig* Config;
53 extern InspIRCd* ServerInstance;
55 extern std::vector<Module*> modules;
56 extern std::vector<ircd_module*> factory;
58 extern user_hash clientlist;
59 extern chan_hash chanlist;
60 extern whowas_hash whowas;
61 extern std::vector<userrec*> all_opers;
62 extern std::vector<userrec*> local_users;
63 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
65 void cmd_notice::Handle (char **parameters, int pcnt, userrec *user)
70 user->idle_lastmsg = TIME;
72 if (ServerInstance->Parser->LoopCall(this,parameters,pcnt,user,0,pcnt-2,0))
74 if (parameters[0][0] == '$')
76 // notice to server mask
77 char* servermask = parameters[0];
79 if (match(Config->ServerName,servermask))
81 NoticeAll(user, true, "%s",parameters[1]);
85 else if (parameters[0][0] == '#')
87 chan = FindChan(parameters[0]);
92 if ((chan->binarymodes & CM_NOEXTERNAL) && (!has_channel(user,chan)))
94 WriteServ(user->fd,"404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
97 if ((chan->binarymodes & CM_MODERATED) && (cstatus(user,chan)<STATUS_VOICE))
99 WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
106 std::string temp = parameters[1];
107 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp));
111 parameters[1] = (char*)temp.c_str();
115 WriteServ(user->fd,"412 %s No text to send", user->nick);
119 ChanExceptSender(chan, user, "NOTICE %s :%s", chan->name, parameters[1]);
121 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1]));
125 /* no such nick/channel */
126 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
131 dest = Find(parameters[0]);
136 std::string temp = parameters[1];
137 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp));
141 parameters[1] = (char*)temp.c_str();
145 // direct write, same server
146 WriteTo(user, dest, "NOTICE %s :%s", dest->nick, parameters[1]);
149 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1]));
153 /* no such nick/channel */
154 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);