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 * ---------------------------------------------------
15 #include "commands/cmd_notice.h"
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
19 return new CommandNotice(Instance);
22 CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, User *user)
29 user->idle_lastmsg = ServerInstance->Time();
31 if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
33 if (parameters[0][0] == '$')
35 if (!user->HasPrivPermission("users/mass-message"))
39 std::string temp = parameters[1];
40 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list));
43 const char* text = temp.c_str();
44 const char* servermask = (parameters[0].c_str()) + 1;
46 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
47 if (InspIRCd::Match(ServerInstance->Config->ServerName,servermask, NULL))
49 user->SendAll("NOTICE", "%s", text);
51 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
55 const char* target = parameters[0].c_str();
57 if (ServerInstance->Modes->FindPrefix(*target))
64 chan = ServerInstance->FindChan(target);
66 exempt_list[user] = user->nick;
72 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
74 user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
77 if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE))
79 user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
85 std::string temp = parameters[1];
86 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
90 const char* text = temp.c_str();
94 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
98 FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list));
102 if (ServerInstance->Config->UndernetMsgPrefix)
104 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name.c_str(), status, text);
108 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name.c_str(), text);
113 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text);
116 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,status,exempt_list));
120 /* no such nick/channel */
121 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target);
127 const char* destnick = parameters[0].c_str();
131 const char* targetserver = strchr(destnick, '@');
135 std::string nickonly;
137 nickonly.assign(destnick, 0, targetserver - destnick + 1);
138 dest = ServerInstance->FindNickOnly(nickonly);
139 if (dest && strcasecmp(dest->server, targetserver + 1))
141 /* Incorrect server for user */
142 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
147 dest = ServerInstance->FindNickOnly(destnick);
150 dest = ServerInstance->FindNick(destnick);
154 if (parameters[1].empty())
156 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
161 std::string temp = parameters[1];
162 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
166 const char* text = temp.c_str();
168 FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,text,0,exempt_list));
172 // direct write, same server
173 user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text);
176 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,text,0,exempt_list));
180 /* no such nick/channel */
181 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());