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 LocalUser* localuser = IS_LOCAL(user);
62 localuser->idle_lastmsg = ServerInstance->Time();
64 if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
66 if (parameters[0][0] == '$')
68 if (!user->HasPrivPermission("users/mass-message"))
72 std::string temp = parameters[1];
73 FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list, MSG_NOTICE));
74 if (MOD_RESULT == MOD_RES_DENY)
76 const char* text = temp.c_str();
77 const char* servermask = (parameters[0].c_str()) + 1;
79 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
80 if (InspIRCd::Match(ServerInstance->Config->ServerName,servermask, NULL))
82 user->SendAll("NOTICE", "%s", text);
84 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list, MSG_NOTICE));
88 const char* target = parameters[0].c_str();
90 if (ServerInstance->Modes->FindPrefix(*target))
97 chan = ServerInstance->FindChan(target);
99 exempt_list.insert(user);
105 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
107 user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
110 if ((chan->IsModeSet('m')) && (chan->GetPrefixValue(user) < VOICE_VALUE))
112 user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
116 if (ServerInstance->Config->RestrictBannedUsers)
118 if (chan->IsBanned(user))
120 user->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", user->nick.c_str(), chan->name.c_str());
125 ModResult MOD_RESULT;
127 std::string temp = parameters[1];
128 FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user,chan,TYPE_CHANNEL,temp,status, exempt_list, MSG_NOTICE));
129 if (MOD_RESULT == MOD_RES_DENY)
132 const char* text = temp.c_str();
136 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
140 FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list));
144 if (ServerInstance->Config->UndernetMsgPrefix)
146 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name.c_str(), status, text);
150 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name.c_str(), text);
155 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text);
158 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,text,status,exempt_list,MSG_NOTICE));
162 /* no such nick/channel */
163 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target);
169 const char* destnick = parameters[0].c_str();
173 const char* targetserver = strchr(destnick, '@');
177 std::string nickonly;
179 nickonly.assign(destnick, 0, targetserver - destnick);
180 dest = ServerInstance->FindNickOnly(nickonly);
181 if (dest && strcasecmp(dest->server.c_str(), targetserver + 1))
183 /* Incorrect server for user */
184 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
189 dest = ServerInstance->FindNickOnly(destnick);
192 dest = ServerInstance->FindNick(destnick);
194 if ((dest) && (dest->registered == REG_ALL))
196 if (parameters[1].empty())
198 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
202 ModResult MOD_RESULT;
203 std::string temp = parameters[1];
204 FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, dest, TYPE_USER, temp, 0, exempt_list, MSG_NOTICE));
205 if (MOD_RESULT == MOD_RES_DENY) {
208 const char* text = temp.c_str();
210 FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,text,0,exempt_list));
214 // direct write, same server
215 user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text);
218 FOREACH_MOD(I_OnUserMessage, OnUserMessage(user, dest, TYPE_USER, text, 0, exempt_list, MSG_NOTICE));
222 /* no such nick/channel */
223 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
231 COMMAND_INIT(CommandNotice)