1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 /** Handle /NOTICE. These command handlers can be reloaded by the core,
16 * and handle basic RFC1459 commands. Commands within modules work
17 * the same way, however, they can be fully unloaded, where these
20 class CommandNotice : public Command
23 /** Constructor for notice.
25 CommandNotice ( Module* parent) : Command(parent,"NOTICE",2,2) { syntax = "<target>{,<target>} <message>"; }
27 * @param parameters The parameters to the comamnd
28 * @param pcnt The number of parameters passed to teh command
29 * @param user The user issuing the command
30 * @return A value from CmdResult to indicate command success or failure.
32 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
36 CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, User *user)
43 user->idle_lastmsg = ServerInstance->Time();
45 if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
47 if (parameters[0][0] == '$')
49 if (!user->HasPrivPermission("users/mass-message"))
53 std::string temp = parameters[1];
54 FIRST_MOD_RESULT(ServerInstance, OnUserPreNotice, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list));
55 if (MOD_RESULT == MOD_RES_DENY)
57 const char* text = temp.c_str();
58 const char* servermask = (parameters[0].c_str()) + 1;
60 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
61 if (InspIRCd::Match(ServerInstance->Config->ServerName,servermask, NULL))
63 user->SendAll("NOTICE", "%s", text);
65 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
69 const char* target = parameters[0].c_str();
71 if (ServerInstance->Modes->FindPrefix(*target))
78 chan = ServerInstance->FindChan(target);
80 exempt_list.insert(user);
86 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
88 user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
91 if ((chan->IsModeSet('m')) && (chan->GetPrefixValue(user) < VOICE_VALUE))
93 user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
99 std::string temp = parameters[1];
100 FIRST_MOD_RESULT(ServerInstance, OnUserPreNotice, MOD_RESULT, (user,chan,TYPE_CHANNEL,temp,status, exempt_list));
101 if (MOD_RESULT == MOD_RES_DENY)
104 const char* text = temp.c_str();
108 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
112 FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list));
116 if (ServerInstance->Config->UndernetMsgPrefix)
118 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name.c_str(), status, text);
122 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name.c_str(), text);
127 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text);
130 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,status,exempt_list));
134 /* no such nick/channel */
135 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target);
141 const char* destnick = parameters[0].c_str();
145 const char* targetserver = strchr(destnick, '@');
149 std::string nickonly;
151 nickonly.assign(destnick, 0, targetserver - destnick);
152 dest = ServerInstance->FindNickOnly(nickonly);
153 if (dest && strcasecmp(dest->server, targetserver + 1))
155 /* Incorrect server for user */
156 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
161 dest = ServerInstance->FindNickOnly(destnick);
164 dest = ServerInstance->FindNick(destnick);
168 if (parameters[1].empty())
170 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
174 ModResult MOD_RESULT;
175 std::string temp = parameters[1];
176 FIRST_MOD_RESULT(ServerInstance, OnUserPreNotice, MOD_RESULT, (user,dest,TYPE_USER,temp,0,exempt_list));
177 if (MOD_RESULT == MOD_RES_DENY) {
180 const char* text = temp.c_str();
182 FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,text,0,exempt_list));
186 // direct write, same server
187 user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text);
190 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,text,0,exempt_list));
194 /* no such nick/channel */
195 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
203 COMMAND_INIT(CommandNotice)