1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
16 #include "commands/cmd_notice.h"
18 extern "C" DllExport Command* init_command(InspIRCd* Instance)
20 return new CommandNotice(Instance);
23 CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, User *user)
30 user->idle_lastmsg = ServerInstance->Time();
32 if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
34 if ((parameters[0][0] == '$') && (IS_OPER(user) || ServerInstance->ULine(user->server)))
37 std::string temp = parameters[1];
38 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list));
41 const char* text = temp.c_str();
42 const char* servermask = (parameters[0].c_str()) + 1;
44 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
45 if (match(ServerInstance->Config->ServerName,servermask))
47 user->SendAll("NOTICE", "%s", text);
49 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
53 const char* target = parameters[0].c_str();
55 if (ServerInstance->Modes->FindPrefix(*target))
62 chan = ServerInstance->FindChan(target);
64 exempt_list[user] = user->nick;
70 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
72 user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
75 if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE))
77 user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
83 std::string temp = parameters[1];
84 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
88 const char* text = temp.c_str();
92 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
96 FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list));
100 if (ServerInstance->Config->UndernetMsgPrefix)
102 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name.c_str(), status, text);
106 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name.c_str(), text);
111 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text);
114 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,status,exempt_list));
118 /* no such nick/channel */
119 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target);
125 const char* destnick = parameters[0].c_str();
129 const char* targetserver = strchr(destnick, '@');
133 char nickonly[NICKMAX+1];
134 strlcpy(nickonly, destnick, targetserver - destnick + 1);
135 dest = ServerInstance->FindNickOnly(nickonly);
136 if (dest && strcasecmp(dest->server, targetserver + 1))
138 /* Incorrect server for user */
139 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
144 dest = ServerInstance->FindNickOnly(destnick);
147 dest = ServerInstance->FindNick(destnick);
151 if (parameters[1].empty())
153 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
158 std::string temp = parameters[1];
159 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
163 const char* text = temp.c_str();
165 FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,text,0,exempt_list));
169 // direct write, same server
170 user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text);
173 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,text,0,exempt_list));
177 /* no such nick/channel */
178 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());