]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_notice.cpp
Add new event for this with gauranteed delivery of message BEFORE the text is sent out
[user/henk/code/inspircd.git] / src / commands / cmd_notice.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "wildcard.h"
16 #include "commands/cmd_notice.h"
17
18 extern "C" DllExport Command* init_command(InspIRCd* Instance)
19 {
20         return new CommandNotice(Instance);
21 }
22
23 CmdResult CommandNotice::Handle (const char** parameters, int pcnt, User *user)
24 {
25         User *dest;
26         Channel *chan;
27
28         CUList exempt_list;
29
30         user->idle_lastmsg = ServerInstance->Time();
31         
32         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
33                 return CMD_SUCCESS;
34         if ((parameters[0][0] == '$') && (IS_OPER(user) || ServerInstance->ULine(user->server)))
35         {
36                 int MOD_RESULT = 0;
37                 std::string temp = parameters[1];
38                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0,exempt_list));
39                 if (MOD_RESULT)
40                         return CMD_FAILURE;
41                 parameters[1] = temp.c_str();
42                 // notice to server mask
43                 const char* servermask = parameters[0] + 1;
44                 FOREACH_MOD(I_OnText,OnText(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
45                 if (match(ServerInstance->Config->ServerName,servermask))
46                 {
47                         user->SendAll("NOTICE", "%s", parameters[1]);
48                 }
49                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
50                 return CMD_SUCCESS;
51         }
52         char status = 0;
53         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
54         {
55                 status = *parameters[0];
56                 parameters[0]++;
57         }
58         if (*parameters[0] == '#')
59         {
60                 chan = ServerInstance->FindChan(parameters[0]);
61
62                 exempt_list[user] = user->nick;
63
64                 if (chan)
65                 {
66                         if (IS_LOCAL(user))
67                         {
68                                 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
69                                 {
70                                         user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
71                                         return CMD_FAILURE;
72                                 }
73                                 if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE))
74                                 {
75                                         user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
76                                         return CMD_FAILURE;
77                                 }
78                         }
79                         int MOD_RESULT = 0;
80
81                         std::string temp = parameters[1];
82                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
83                         if (MOD_RESULT) {
84                                 return CMD_FAILURE;
85                         }
86                         parameters[1] = temp.c_str();
87
88                         if (temp.empty())
89                         {
90                                 user->WriteServ("412 %s :No text to send", user->nick);
91                                 return CMD_FAILURE;
92                         }
93
94                         FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,parameters[1],status,except_list));
95
96                         if (status)
97                         {
98                                 if (ServerInstance->Config->UndernetMsgPrefix)
99                                 {
100                                         chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name, status, parameters[1]);
101                                 }
102                                 else
103                                 {
104                                         chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name, parameters[1]);
105                                 }
106                         }
107                         else
108                         {
109                                 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name, parameters[1]);
110                         }
111
112                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status,exempt_list));
113                 }
114                 else
115                 {
116                         /* no such nick/channel */
117                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
118                         return CMD_FAILURE;
119                 }
120                 return CMD_SUCCESS;
121         }
122         
123         if (IS_LOCAL(user))
124                 dest = ServerInstance->FindNickOnly(parameters[0]);
125         else
126                 dest = ServerInstance->FindNick(parameters[0]);
127
128         if (dest)
129         {
130                 if (!*parameters[1])
131                 {
132                         user->WriteServ("412 %s :No text to send", user->nick);
133                         return CMD_FAILURE;
134                 }
135
136                 int MOD_RESULT = 0;
137                 std::string temp = parameters[1];
138                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
139                 if (MOD_RESULT) {
140                         return CMD_FAILURE;
141                 }
142                 parameters[1] = (char*)temp.c_str();
143
144                 FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,parameters[1],0,exempt_list));
145
146                 if (IS_LOCAL(dest))
147                 {
148                         // direct write, same server
149                         user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
150                 }
151
152                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
153         }
154         else
155         {
156                 /* no such nick/channel */
157                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
158                 return CMD_FAILURE;
159         }
160
161         return CMD_SUCCESS;
162
163 }
164