]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
Change /msg $* to have the correct source the same way /notice $* does
[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 "configreader.h"
15 #include "users.h"
16 #include "modules.h"
17 #include "wildcard.h"
18 #include "commands/cmd_notice.h"
19
20
21
22 extern "C" command_t* init_command(InspIRCd* Instance)
23 {
24         return new cmd_notice(Instance);
25 }
26
27 CmdResult cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
28 {
29         userrec *dest;
30         chanrec *chan;
31
32         CUList exempt_list;
33
34         user->idle_lastmsg = ServerInstance->Time();
35         
36         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
37                 return CMD_SUCCESS;
38         if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
39         {
40                 int MOD_RESULT = 0;
41                 std::string temp = parameters[1];
42                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0,exempt_list));
43                 if (MOD_RESULT)
44                         return CMD_FAILURE;
45                 parameters[1] = (char*)temp.c_str();
46                 // notice to server mask
47                 const char* servermask = parameters[0] + 1;
48                 if (match(ServerInstance->Config->ServerName,servermask))
49                 {
50                         user->SendAll("NOTICE", "%s", parameters[1]);
51                 }
52                 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
53                 return CMD_SUCCESS;
54         }
55         char status = 0;
56         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
57         {
58                 status = *parameters[0];
59                 parameters[0]++;
60         }
61         if (*parameters[0] == '#')
62         {
63                 chan = ServerInstance->FindChan(parameters[0]);
64
65                 exempt_list[user] = user;
66
67                 if (chan)
68                 {
69                         if (IS_LOCAL(user))
70                         {
71                                 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
72                                 {
73                                         user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
74                                         return CMD_FAILURE;
75                                 }
76                                 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
77                                 {
78                                         user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
79                                         return CMD_FAILURE;
80                                 }
81                         }
82                         int MOD_RESULT = 0;
83
84                         std::string temp = parameters[1];
85                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
86                         if (MOD_RESULT) {
87                                 return CMD_FAILURE;
88                         }
89                         parameters[1] = temp.c_str();
90
91                         if (temp == "")
92                         {
93                                 user->WriteServ("412 %s No text to send", user->nick);
94                                 return CMD_FAILURE;
95                         }
96
97                         if (status)
98                         {
99                                 if (ServerInstance->Config->UndernetMsgPrefix)
100                                 {
101                                         chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name, status, parameters[1]);
102                                 }
103                                 else
104                                 {
105                                         chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name, parameters[1]);
106                                 }
107                         }
108                         else
109                         {
110                                 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name, parameters[1]);
111                         }
112
113                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status,exempt_list));
114                 }
115                 else
116                 {
117                         /* no such nick/channel */
118                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
119                         return CMD_FAILURE;
120                 }
121                 return CMD_SUCCESS;
122         }
123         
124         dest = ServerInstance->FindNick(parameters[0]);
125         if (dest)
126         {
127                 int MOD_RESULT = 0;
128                 
129                 std::string temp = parameters[1];
130                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
131                 if (MOD_RESULT) {
132                         return CMD_FAILURE;
133                 }
134                 parameters[1] = (char*)temp.c_str();
135
136                 if (IS_LOCAL(dest))
137                 {
138                         // direct write, same server
139                         user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
140                 }
141
142                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
143         }
144         else
145         {
146                 /* no such nick/channel */
147                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
148                 return CMD_FAILURE;
149         }
150
151         return CMD_SUCCESS;
152
153 }
154