1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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);
34 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
37 // This is handled by the OnUserNotice hook to split the LoopCall pieces
38 return ROUTE_LOCALONLY;
40 return ROUTE_MESSAGE(parameters[0]);
45 CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, User *user)
52 user->idle_lastmsg = ServerInstance->Time();
54 if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
56 if (parameters[0][0] == '$')
58 if (!user->HasPrivPermission("users/mass-message"))
62 std::string temp = parameters[1];
63 FIRST_MOD_RESULT(OnUserPreNotice, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list));
64 if (MOD_RESULT == MOD_RES_DENY)
66 const char* text = temp.c_str();
67 const char* servermask = (parameters[0].c_str()) + 1;
69 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
70 if (InspIRCd::Match(ServerInstance->Config->ServerName,servermask, NULL))
72 user->SendAll("NOTICE", "%s", text);
74 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
78 const char* target = parameters[0].c_str();
80 if (ServerInstance->Modes->FindPrefix(*target))
87 chan = ServerInstance->FindChan(target);
89 exempt_list.insert(user);
95 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
97 user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
100 if ((chan->IsModeSet('m')) && (chan->GetPrefixValue(user) < VOICE_VALUE))
102 user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
106 ModResult MOD_RESULT;
108 std::string temp = parameters[1];
109 FIRST_MOD_RESULT(OnUserPreNotice, MOD_RESULT, (user,chan,TYPE_CHANNEL,temp,status, exempt_list));
110 if (MOD_RESULT == MOD_RES_DENY)
113 const char* text = temp.c_str();
117 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
121 FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list));
125 if (ServerInstance->Config->UndernetMsgPrefix)
127 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name.c_str(), status, text);
131 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name.c_str(), text);
136 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text);
139 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,status,exempt_list));
143 /* no such nick/channel */
144 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target);
150 const char* destnick = parameters[0].c_str();
154 const char* targetserver = strchr(destnick, '@');
158 std::string nickonly;
160 nickonly.assign(destnick, 0, targetserver - destnick);
161 dest = ServerInstance->FindNickOnly(nickonly);
162 if (dest && strcasecmp(dest->server.c_str(), targetserver + 1))
164 /* Incorrect server for user */
165 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
170 dest = ServerInstance->FindNickOnly(destnick);
173 dest = ServerInstance->FindNick(destnick);
177 if (parameters[1].empty())
179 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
183 ModResult MOD_RESULT;
184 std::string temp = parameters[1];
185 FIRST_MOD_RESULT(OnUserPreNotice, MOD_RESULT, (user,dest,TYPE_USER,temp,0,exempt_list));
186 if (MOD_RESULT == MOD_RES_DENY) {
189 const char* text = temp.c_str();
191 FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,text,0,exempt_list));
195 // direct write, same server
196 user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text);
199 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,text,0,exempt_list));
203 /* no such nick/channel */
204 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
212 COMMAND_INIT(CommandNotice)