1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
18 #include "inspircd_config.h"
20 #include "configreader.h"
26 #include "helperfuncs.h"
27 #include "commands/cmd_privmsg.h"
29 extern ServerConfig* Config;
30 extern InspIRCd* ServerInstance;
32 extern ModuleList modules;
33 extern FactoryList factory;
36 void cmd_privmsg::Handle (const char** parameters, int pcnt, userrec *user)
41 user->idle_lastmsg = TIME;
43 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
46 if ((parameters[0][0] == '$') && ((*user->oper) || (is_uline(user->server))))
48 // notice to server mask
49 const char* servermask = parameters[0] + 1;
50 if (match(Config->ServerName,servermask))
52 ServerPrivmsgAll("%s",parameters[1]);
57 if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
59 status = *parameters[0];
62 if (parameters[0][0] == '#')
64 chan = FindChan(parameters[0]);
69 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
71 WriteServ(user->fd,"404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
74 if ((chan->modes[CM_MODERATED]) && (cstatus(user,chan)<STATUS_VOICE))
76 WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
82 std::string temp = parameters[1];
83 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,chan,TYPE_CHANNEL,temp,status));
87 parameters[1] = (char*)temp.c_str();
91 WriteServ(user->fd,"412 %s No text to send", user->nick);
95 ChanExceptSender(chan, user, status, "PRIVMSG %s :%s", chan->name, parameters[1]);
96 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,parameters[1],status));
100 /* no such nick/channel */
101 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
106 dest = Find(parameters[0]);
109 if ((IS_LOCAL(user)) && (*dest->awaymsg))
111 /* auto respond with aweh msg */
112 WriteServ(user->fd,"301 %s %s :%s",user->nick,dest->nick,dest->awaymsg);
117 std::string temp = parameters[1];
118 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,dest,TYPE_USER,temp,0));
122 parameters[1] = (char*)temp.c_str();
126 // direct write, same server
127 WriteTo(user, dest, "PRIVMSG %s :%s", dest->nick, parameters[1]);
130 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,dest,TYPE_USER,parameters[1],0));
134 /* no such nick/channel */
135 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);