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 /** Handle /PRIVMSG. These command handlers can be reloaded by the core,
17 * and handle basic RFC1459 commands. Commands within modules work
18 * the same way, however, they can be fully unloaded, where these
21 class CommandPrivmsg : public Command
24 /** Constructor for privmsg.
26 CommandPrivmsg ( Module* parent) : Command(parent,"PRIVMSG",2,2) { syntax = "<target>{,<target>} <message>"; }
28 * @param parameters The parameters to the comamnd
29 * @param pcnt The number of parameters passed to teh command
30 * @param user The user issuing the command
31 * @return A value from CmdResult to indicate command success or failure.
33 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
36 CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, User *user)
42 user->idle_lastmsg = ServerInstance->Time();
44 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(OnUserPreMessage, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, except_list));
55 if (MOD_RESULT == MOD_RES_DENY)
58 const char* text = temp.c_str();
59 const char* servermask = (parameters[0].c_str()) + 1;
61 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
62 if (InspIRCd::Match(ServerInstance->Config->ServerName, servermask, NULL))
64 user->SendAll("PRIVMSG", "%s", text);
66 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
70 const char* target = parameters[0].c_str();
72 if (ServerInstance->Modes->FindPrefix(*target))
79 chan = ServerInstance->FindChan(target);
81 except_list.insert(user);
85 if (IS_LOCAL(user) && chan->GetPrefixValue(user) < VOICE_VALUE)
87 if (chan->IsModeSet('n') && !chan->HasUser(user))
89 user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
93 if (chan->IsModeSet('m'))
95 user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
99 if (ServerInstance->Config->RestrictBannedUsers)
101 if (chan->IsBanned(user))
103 user->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", user->nick.c_str(), chan->name.c_str());
108 ModResult MOD_RESULT;
110 std::string temp = parameters[1];
111 FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user,chan,TYPE_CHANNEL,temp,status,except_list));
112 if (MOD_RESULT == MOD_RES_DENY)
115 const char* text = temp.c_str();
117 /* Check again, a module may have zapped the input string */
120 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
124 FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,except_list));
128 if (ServerInstance->Config->UndernetMsgPrefix)
130 chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %c%s :%c %s", status, chan->name.c_str(), status, text);
134 chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %c%s :%s", status, chan->name.c_str(), text);
139 chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %s :%s", chan->name.c_str(), text);
142 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,text,status,except_list));
146 /* no such nick/channel */
147 user->WriteNumeric(401, "%s %s :No such nick/channel", user->nick.c_str(), target);
153 const char* destnick = parameters[0].c_str();
157 const char* targetserver = strchr(destnick, '@');
161 std::string nickonly;
163 nickonly.assign(destnick, 0, targetserver - destnick);
164 dest = ServerInstance->FindNickOnly(nickonly);
165 if (dest && strcasecmp(dest->server, targetserver + 1))
167 /* Incorrect server for user */
168 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
173 dest = ServerInstance->FindNickOnly(destnick);
176 dest = ServerInstance->FindNick(destnick);
180 if (parameters[1].empty())
182 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
188 /* auto respond with aweh msg */
189 user->WriteNumeric(301, "%s %s :%s", user->nick.c_str(), dest->nick.c_str(), dest->awaymsg.c_str());
192 ModResult MOD_RESULT;
194 std::string temp = parameters[1];
195 FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, dest, TYPE_USER, temp, 0, except_list));
196 if (MOD_RESULT == MOD_RES_DENY)
199 const char* text = temp.c_str();
201 FOREACH_MOD(I_OnText,OnText(user, dest, TYPE_USER, text, 0, except_list));
205 // direct write, same server
206 user->WriteTo(dest, "PRIVMSG %s :%s", dest->nick.c_str(), text);
209 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, dest, TYPE_USER, text, 0, except_list));
213 /* no such nick/channel */
214 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
220 COMMAND_INIT(CommandPrivmsg)