1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "commands/cmd_privmsg.h"
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
19 return new CommandPrivmsg(Instance);
22 CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, User *user)
28 user->idle_lastmsg = ServerInstance->Time();
30 if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
33 if (parameters[0][0] == '$')
35 if (!user->HasPrivPermission("users/mass-message"))
39 std::string temp = parameters[1];
40 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, except_list));
44 const char* text = temp.c_str();
45 const char* servermask = (parameters[0].c_str()) + 1;
47 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
48 if (InspIRCd::Match(ServerInstance->Config->ServerName, servermask, NULL))
50 user->SendAll("PRIVMSG", "%s", text);
52 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
56 const char* target = parameters[0].c_str();
58 if (ServerInstance->Modes->FindPrefix(*target))
65 chan = ServerInstance->FindChan(target);
67 except_list[user] = user->nick;
71 if (IS_LOCAL(user) && chan->GetStatus(user) < STATUS_VOICE)
73 if (chan->IsModeSet('n') && !chan->HasUser(user))
75 user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
79 if (chan->IsModeSet('m'))
81 user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
85 if (ServerInstance->Config->RestrictBannedUsers)
87 if (chan->IsBanned(user))
89 user->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", user->nick.c_str(), chan->name.c_str());
96 std::string temp = parameters[1];
97 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,chan,TYPE_CHANNEL,temp,status,except_list));
101 const char* text = temp.c_str();
103 /* Check again, a module may have zapped the input string */
106 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
110 FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,except_list));
114 if (ServerInstance->Config->UndernetMsgPrefix)
116 chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %c%s :%c %s", status, chan->name.c_str(), status, text);
120 chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %c%s :%s", status, chan->name.c_str(), text);
125 chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %s :%s", chan->name.c_str(), text);
128 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,text,status,except_list));
132 /* no such nick/channel */
133 user->WriteNumeric(401, "%s %s :No such nick/channel", user->nick.c_str(), target);
139 const char* destnick = parameters[0].c_str();
143 const char* targetserver = strchr(destnick, '@');
147 std::string nickonly;
149 nickonly.assign(destnick, 0, targetserver - destnick + 1);
150 dest = ServerInstance->FindNickOnly(nickonly);
151 if (dest && strcasecmp(dest->server, targetserver + 1))
153 /* Incorrect server for user */
154 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
159 dest = ServerInstance->FindNickOnly(destnick);
162 dest = ServerInstance->FindNick(destnick);
166 if (parameters[1].empty())
168 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
174 /* auto respond with aweh msg */
175 user->WriteNumeric(301, "%s %s :%s", user->nick.c_str(), dest->nick.c_str(), dest->awaymsg.c_str());
180 std::string temp = parameters[1];
181 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user, dest, TYPE_USER, temp, 0, except_list));
185 const char* text = temp.c_str();
187 FOREACH_MOD(I_OnText,OnText(user, dest, TYPE_USER, text, 0, except_list));
191 // direct write, same server
192 user->WriteTo(dest, "PRIVMSG %s :%s", dest->nick.c_str(), text);
195 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, dest, TYPE_USER, text, 0, except_list));
199 /* no such nick/channel */
200 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());