1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 "configreader.h"
19 #include "commands/cmd_privmsg.h"
21 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
23 return new cmd_privmsg(Instance);
26 CmdResult cmd_privmsg::Handle (const char** parameters, int pcnt, userrec *user)
32 user->idle_lastmsg = ServerInstance->Time();
34 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
37 if ((parameters[0][0] == '$') && (IS_OPER(user) || ServerInstance->ULine(user->server)))
40 std::string temp = parameters[1];
41 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,(void*)parameters[0],TYPE_SERVER,temp,0,except_list));
44 parameters[1] = temp.c_str();
45 // notice to server mask
46 const char* servermask = parameters[0] + 1;
47 if (match(ServerInstance->Config->ServerName,servermask))
49 user->SendAll("PRIVMSG", "%s", parameters[1]);
51 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,except_list));
55 if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
57 status = *parameters[0];
60 if (parameters[0][0] == '#')
62 chan = ServerInstance->FindChan(parameters[0]);
64 except_list[user] = user->nick;
70 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
72 user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
75 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
77 user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
83 std::string temp = parameters[1];
84 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,chan,TYPE_CHANNEL,temp,status,except_list));
88 parameters[1] = temp.c_str();
90 /* Check again, a module may have zapped the input string */
93 user->WriteServ("412 %s :No text to send", user->nick);
99 if (ServerInstance->Config->UndernetMsgPrefix)
101 chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %c%s :%c %s", status, chan->name, status, parameters[1]);
105 chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %c%s :%s", status, chan->name, parameters[1]);
110 chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %s :%s", chan->name, parameters[1]);
113 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,parameters[1],status,except_list));
117 /* no such nick/channel */
118 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
124 dest = ServerInstance->FindNick(parameters[0]);
129 user->WriteServ("412 %s :No text to send", user->nick);
135 /* auto respond with aweh msg */
136 user->WriteServ("301 %s %s :%s",user->nick,dest->nick,dest->awaymsg);
141 std::string temp = parameters[1];
142 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,dest,TYPE_USER,temp,0,except_list));
146 parameters[1] = (char*)temp.c_str();
150 // direct write, same server
151 user->WriteTo(dest, "PRIVMSG %s :%s", dest->nick, parameters[1]);
154 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,dest,TYPE_USER,parameters[1],0,except_list));
158 /* no such nick/channel */
159 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);