]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
f6634184638d3c9c596254c33ddec2e1946c9d10
[user/henk/code/inspircd.git] / src / 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_t* init_command(InspIRCd* Instance)
19 {
20         return new cmd_notice(Instance);
21 }
22
23 CmdResult cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
24 {
25         userrec *dest;
26         chanrec *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                 if (match(ServerInstance->Config->ServerName,servermask))
45                 {
46                         user->SendAll("NOTICE", "%s", parameters[1]);
47                 }
48                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
49                 return CMD_SUCCESS;
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] == '#')
58         {
59                 chan = ServerInstance->FindChan(parameters[0]);
60
61                 exempt_list[user] = user->nick;
62
63                 if (chan)
64                 {
65                         if (IS_LOCAL(user))
66                         {
67                                 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
68                                 {
69                                         user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
70                                         return CMD_FAILURE;
71                                 }
72                                 if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE))
73                                 {
74                                         user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
75                                         return CMD_FAILURE;
76                                 }
77                         }
78                         int MOD_RESULT = 0;
79
80                         std::string temp = parameters[1];
81                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
82                         if (MOD_RESULT) {
83                                 return CMD_FAILURE;
84                         }
85                         parameters[1] = temp.c_str();
86
87                         if (temp.empty())
88                         {
89                                 user->WriteServ("412 %s :No text to send", user->nick);
90                                 return CMD_FAILURE;
91                         }
92
93                         if (status)
94                         {
95                                 if (ServerInstance->Config->UndernetMsgPrefix)
96                                 {
97                                         chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name, status, parameters[1]);
98                                 }
99                                 else
100                                 {
101                                         chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name, parameters[1]);
102                                 }
103                         }
104                         else
105                         {
106                                 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name, parameters[1]);
107                         }
108
109                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status,exempt_list));
110                 }
111                 else
112                 {
113                         /* no such nick/channel */
114                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
115                         return CMD_FAILURE;
116                 }
117                 return CMD_SUCCESS;
118         }
119         
120         if (IS_LOCAL(user))
121                 dest = ServerInstance->FindNickOnly(parameters[0]);
122         else
123                 dest = ServerInstance->FindNick(parameters[0]);
124
125         if (dest)
126         {
127                 if (!*parameters[1])
128                 {
129                         user->WriteServ("412 %s :No text to send", user->nick);
130                         return CMD_FAILURE;
131                 }
132
133                 int MOD_RESULT = 0;
134                 std::string temp = parameters[1];
135                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
136                 if (MOD_RESULT) {
137                         return CMD_FAILURE;
138                 }
139                 parameters[1] = (char*)temp.c_str();
140
141                 if (IS_LOCAL(dest))
142                 {
143                         // direct write, same server
144                         user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
145                 }
146
147                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
148         }
149         else
150         {
151                 /* no such nick/channel */
152                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
153                 return CMD_FAILURE;
154         }
155
156         return CMD_SUCCESS;
157
158 }
159