2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /** Handle /NOTICE. These command handlers can be reloaded by the core,
24 * and handle basic RFC1459 commands. Commands within modules work
25 * the same way, however, they can be fully unloaded, where these
28 class CommandNotice : public Command
31 /** Constructor for notice.
33 CommandNotice ( Module* parent) : Command(parent,"NOTICE",2,2) { syntax = "<target>{,<target>} <message>"; }
35 * @param parameters The parameters to the comamnd
36 * @param pcnt The number of parameters passed to teh command
37 * @param user The user issuing the command
38 * @return A value from CmdResult to indicate command success or failure.
40 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
42 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
45 // This is handled by the OnUserNotice hook to split the LoopCall pieces
46 return ROUTE_LOCALONLY;
48 return ROUTE_MESSAGE(parameters[0]);
53 CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, User *user)
60 user->idle_lastmsg = ServerInstance->Time();
62 if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
64 if (parameters[0][0] == '$')
66 if (!user->HasPrivPermission("users/mass-message"))
70 std::string temp = parameters[1];
71 FIRST_MOD_RESULT(OnUserPreNotice, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list));
72 if (MOD_RESULT == MOD_RES_DENY)
74 const char* text = temp.c_str();
75 const char* servermask = (parameters[0].c_str()) + 1;
77 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
78 if (InspIRCd::Match(ServerInstance->Config->ServerName,servermask, NULL))
80 user->SendAll("NOTICE", "%s", text);
82 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
86 const char* target = parameters[0].c_str();
88 if (ServerInstance->Modes->FindPrefix(*target))
95 chan = ServerInstance->FindChan(target);
97 exempt_list.insert(user);
103 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
105 user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
108 if ((chan->IsModeSet('m')) && (chan->GetPrefixValue(user) < VOICE_VALUE))
110 user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
114 if (ServerInstance->Config->RestrictBannedUsers)
116 if (chan->IsBanned(user))
118 user->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", user->nick.c_str(), chan->name.c_str());
123 ModResult MOD_RESULT;
125 std::string temp = parameters[1];
126 FIRST_MOD_RESULT(OnUserPreNotice, MOD_RESULT, (user,chan,TYPE_CHANNEL,temp,status, exempt_list));
127 if (MOD_RESULT == MOD_RES_DENY)
130 const char* text = temp.c_str();
134 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
138 FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list));
142 if (ServerInstance->Config->UndernetMsgPrefix)
144 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name.c_str(), status, text);
148 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name.c_str(), text);
153 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text);
156 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,status,exempt_list));
160 /* no such nick/channel */
161 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target);
167 const char* destnick = parameters[0].c_str();
171 const char* targetserver = strchr(destnick, '@');
175 std::string nickonly;
177 nickonly.assign(destnick, 0, targetserver - destnick);
178 dest = ServerInstance->FindNickOnly(nickonly);
179 if (dest && strcasecmp(dest->server.c_str(), targetserver + 1))
181 /* Incorrect server for user */
182 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
187 dest = ServerInstance->FindNickOnly(destnick);
190 dest = ServerInstance->FindNick(destnick);
192 if ((dest) && (dest->registered == REG_ALL))
194 if (parameters[1].empty())
196 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
200 ModResult MOD_RESULT;
201 std::string temp = parameters[1];
202 FIRST_MOD_RESULT(OnUserPreNotice, MOD_RESULT, (user,dest,TYPE_USER,temp,0,exempt_list));
203 if (MOD_RESULT == MOD_RES_DENY) {
206 const char* text = temp.c_str();
208 FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,text,0,exempt_list));
212 // direct write, same server
213 user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text);
216 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,text,0,exempt_list));
220 /* no such nick/channel */
221 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
229 COMMAND_INIT(CommandNotice)