]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_privmsg.cpp
Change includes, use --libs_r rather than mysql_config --libs, we want re-enterant...
[user/henk/code/inspircd.git] / src / cmd_privmsg.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <string>
18 #include "inspircd_config.h"
19 #include "inspircd.h"
20 #include "configreader.h"
21 #include "users.h"
22 #include "modules.h"
23 #include "message.h"
24 #include "wildcard.h"
25 #include "commands.h"
26 #include "helperfuncs.h"
27 #include "commands/cmd_privmsg.h"
28
29 extern ServerConfig* Config;
30 extern InspIRCd* ServerInstance;
31 extern int MODCOUNT;
32 extern ModuleList modules;
33 extern FactoryList factory;
34 extern time_t TIME;
35
36 void cmd_privmsg::Handle (const char** parameters, int pcnt, userrec *user)
37 {
38         userrec *dest;
39         chanrec *chan;
40
41         user->idle_lastmsg = TIME;
42         
43         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
44                 return;
45
46         if ((parameters[0][0] == '$') && ((*user->oper) || (is_uline(user->server))))
47         {
48                 // notice to server mask
49                 const char* servermask = parameters[0] + 1;
50                 if (match(Config->ServerName,servermask))
51                 {
52                         ServerPrivmsgAll("%s",parameters[1]);
53                 }
54                 return;
55         }
56         char status = 0;
57         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
58         {
59                 status = *parameters[0];
60                 parameters[0]++;
61         }
62         if (parameters[0][0] == '#')
63         {
64                 chan = FindChan(parameters[0]);
65                 if (chan)
66                 {
67                         if (IS_LOCAL(user))
68                         {
69                                 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
70                                 {
71                                         WriteServ(user->fd,"404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
72                                         return;
73                                 }
74                                 if ((chan->modes[CM_MODERATED]) && (cstatus(user,chan)<STATUS_VOICE))
75                                 {
76                                         WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
77                                         return;
78                                 }
79                         }
80                         int MOD_RESULT = 0;
81
82                         std::string temp = parameters[1];
83                         FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,chan,TYPE_CHANNEL,temp,status));
84                         if (MOD_RESULT) {
85                                 return;
86                         }
87                         parameters[1] = (char*)temp.c_str();
88
89                         if (temp == "")
90                         {
91                                 WriteServ(user->fd,"412 %s No text to send", user->nick);
92                                 return;
93                         }
94                         
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));
97                 }
98                 else
99                 {
100                         /* no such nick/channel */
101                         WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
102                 }
103                 return;
104         }
105
106         dest = Find(parameters[0]);
107         if (dest)
108         {
109                 if ((IS_LOCAL(user)) && (*dest->awaymsg))
110                 {
111                         /* auto respond with aweh msg */
112                         WriteServ(user->fd,"301 %s %s :%s",user->nick,dest->nick,dest->awaymsg);
113                 }
114
115                 int MOD_RESULT = 0;
116                 
117                 std::string temp = parameters[1];
118                 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,dest,TYPE_USER,temp,0));
119                 if (MOD_RESULT) {
120                         return;
121                 }
122                 parameters[1] = (char*)temp.c_str();
123
124                 if (dest->fd > -1)
125                 {
126                         // direct write, same server
127                         WriteTo(user, dest, "PRIVMSG %s :%s", dest->nick, parameters[1]);
128                 }
129
130                 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,dest,TYPE_USER,parameters[1],0));
131         }
132         else
133         {
134                 /* no such nick/channel */
135                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
136         }
137 }