]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_privmsg.cpp
Wahhhhhhhhhhhh bwahahaha. Mass commit to tidy up tons of messy include lists
[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 "inspircd.h"
18 #include "configreader.h"
19 #include "users.h"
20 #include "modules.h"
21 #include "wildcard.h"
22 #include "commands/cmd_privmsg.h"
23
24 void cmd_privmsg::Handle (const char** parameters, int pcnt, userrec *user)
25 {
26         userrec *dest;
27         chanrec *chan;
28
29         user->idle_lastmsg = ServerInstance->Time();
30         
31         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
32                 return;
33
34         if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
35         {
36                 int MOD_RESULT = 0;
37                 std::string temp = parameters[1];
38                 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,(void*)parameters[0],TYPE_SERVER,temp,0));
39                 if (MOD_RESULT)
40                         return;
41                 parameters[1] = (char*)temp.c_str();
42                 // notice to server mask
43                 const char* servermask = parameters[0] + 1;
44                 if (match(ServerInstance->Config->ServerName,servermask))
45                 {
46                         ServerInstance->ServerPrivmsgAll("%s",parameters[1]);
47                 }
48                 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0));
49                 return;
50         }
51         char status = 0;
52         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
53         {
54                 status = *parameters[0];
55                 parameters[0]++;
56         }
57         if (parameters[0][0] == '#')
58         {
59                 chan = ServerInstance->FindChan(parameters[0]);
60                 if (chan)
61                 {
62                         if (IS_LOCAL(user))
63                         {
64                                 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
65                                 {
66                                         user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
67                                         return;
68                                 }
69                                 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
70                                 {
71                                         user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
72                                         return;
73                                 }
74                         }
75                         int MOD_RESULT = 0;
76
77                         std::string temp = parameters[1];
78                         FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,chan,TYPE_CHANNEL,temp,status));
79                         if (MOD_RESULT) {
80                                 return;
81                         }
82                         parameters[1] = (char*)temp.c_str();
83
84                         if (temp == "")
85                         {
86                                 user->WriteServ("412 %s No text to send", user->nick);
87                                 return;
88                         }
89                         
90                         chan->WriteAllExceptSender(user, status, "PRIVMSG %s :%s", chan->name, parameters[1]);
91                         FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,parameters[1],status));
92                 }
93                 else
94                 {
95                         /* no such nick/channel */
96                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
97                 }
98                 return;
99         }
100
101         dest = ServerInstance->FindNick(parameters[0]);
102         if (dest)
103         {
104                 if ((IS_LOCAL(user)) && (*dest->awaymsg))
105                 {
106                         /* auto respond with aweh msg */
107                         user->WriteServ("301 %s %s :%s",user->nick,dest->nick,dest->awaymsg);
108                 }
109
110                 int MOD_RESULT = 0;
111                 
112                 std::string temp = parameters[1];
113                 FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,dest,TYPE_USER,temp,0));
114                 if (MOD_RESULT) {
115                         return;
116                 }
117                 parameters[1] = (char*)temp.c_str();
118
119                 if (IS_LOCAL(dest))
120                 {
121                         // direct write, same server
122                         user->WriteTo(dest, "PRIVMSG %s :%s", dest->nick, parameters[1]);
123                 }
124
125                 FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,dest,TYPE_USER,parameters[1],0));
126         }
127         else
128         {
129                 /* no such nick/channel */
130                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
131         }
132 }