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 * ---------------------------------------------------
16 #ifndef __CMD_NOTICE_H__
17 #define __CMD_NOTICE_H__
19 // include the common header files
24 /** Handle /NOTICE. These command handlers can be reloaded by the core,
25 * and handle basic RFC1459 commands. Commands within modules work
26 * the same way, however, they can be fully unloaded, where these
29 class CommandNotice : public Command
32 /** Constructor for notice.
34 CommandNotice (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"NOTICE",0,2) { syntax = "<target>{,<target>} <message>"; }
36 * @param parameters The parameters to the comamnd
37 * @param pcnt The number of parameters passed to teh command
38 * @param user The user issuing the command
39 * @return A value from CmdResult to indicate command success or failure.
41 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
47 CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, User *user)
54 user->idle_lastmsg = ServerInstance->Time();
56 if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
58 if (parameters[0][0] == '$')
60 if (!user->HasPrivPermission("users/mass-message"))
64 std::string temp = parameters[1];
65 FIRST_MOD_RESULT(ServerInstance, OnUserPreNotice, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list));
66 if (MOD_RESULT == MOD_RES_DENY)
68 const char* text = temp.c_str();
69 const char* servermask = (parameters[0].c_str()) + 1;
71 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
72 if (InspIRCd::Match(ServerInstance->Config->ServerName,servermask, NULL))
74 user->SendAll("NOTICE", "%s", text);
76 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
80 const char* target = parameters[0].c_str();
82 if (ServerInstance->Modes->FindPrefix(*target))
89 chan = ServerInstance->FindChan(target);
91 exempt_list[user] = user->nick;
97 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
99 user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
102 if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE))
104 user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
108 ModResult MOD_RESULT;
110 std::string temp = parameters[1];
111 FIRST_MOD_RESULT(ServerInstance, OnUserPreNotice, MOD_RESULT, (user,chan,TYPE_CHANNEL,temp,status, exempt_list));
112 if (MOD_RESULT == MOD_RES_DENY)
115 const char* text = temp.c_str();
119 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
123 FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list));
127 if (ServerInstance->Config->UndernetMsgPrefix)
129 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name.c_str(), status, text);
133 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name.c_str(), text);
138 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text);
141 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,status,exempt_list));
145 /* no such nick/channel */
146 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target);
152 const char* destnick = parameters[0].c_str();
156 const char* targetserver = strchr(destnick, '@');
160 std::string nickonly;
162 nickonly.assign(destnick, 0, targetserver - destnick);
163 dest = ServerInstance->FindNickOnly(nickonly);
164 if (dest && strcasecmp(dest->server, targetserver + 1))
166 /* Incorrect server for user */
167 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
172 dest = ServerInstance->FindNickOnly(destnick);
175 dest = ServerInstance->FindNick(destnick);
179 if (parameters[1].empty())
181 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
185 ModResult MOD_RESULT;
186 std::string temp = parameters[1];
187 FIRST_MOD_RESULT(ServerInstance, OnUserPreNotice, MOD_RESULT, (user,dest,TYPE_USER,temp,0,exempt_list));
188 if (MOD_RESULT == MOD_RES_DENY) {
191 const char* text = temp.c_str();
193 FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,text,0,exempt_list));
197 // direct write, same server
198 user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text);
201 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,text,0,exempt_list));
205 /* no such nick/channel */
206 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
214 COMMAND_INIT(CommandNotice)