]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_notice.cpp
Fix total mess of makefile dependency macros (all depending on stuff they dont NEED...
[user/henk/code/inspircd.git] / src / commands / cmd_notice.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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 std::vector<std::string>& parameters, 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, 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].c_str(), TYPE_SERVER, temp, 0, exempt_list));
39                 if (MOD_RESULT)
40                         return CMD_FAILURE;
41                 const char* text = temp.c_str();
42                 const char* servermask = (parameters[0].c_str()) + 1;
43
44                 FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
45                 if (match(ServerInstance->Config->ServerName,servermask))
46                 {
47                         user->SendAll("NOTICE", "%s", text);
48                 }
49                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
50                 return CMD_SUCCESS;
51         }
52         char status = 0;
53         const char* target = parameters[0].c_str();
54
55         if (ServerInstance->Modes->FindPrefix(*target))
56         {
57                 status = *target;
58                 target++;
59         }
60         if (*target == '#')
61         {
62                 chan = ServerInstance->FindChan(target);
63
64                 exempt_list[user] = user->nick;
65
66                 if (chan)
67                 {
68                         if (IS_LOCAL(user))
69                         {
70                                 if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
71                                 {
72                                         user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str());
73                                         return CMD_FAILURE;
74                                 }
75                                 if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE))
76                                 {
77                                         user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str());
78                                         return CMD_FAILURE;
79                                 }
80                         }
81                         int MOD_RESULT = 0;
82
83                         std::string temp = parameters[1];
84                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
85                         if (MOD_RESULT) {
86                                 return CMD_FAILURE;
87                         }
88                         const char* text = temp.c_str();
89
90                         if (temp.empty())
91                         {
92                                 user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
93                                 return CMD_FAILURE;
94                         }
95
96                         FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list));
97
98                         if (status)
99                         {
100                                 if (ServerInstance->Config->UndernetMsgPrefix)
101                                 {
102                                         chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name.c_str(), status, text);
103                                 }
104                                 else
105                                 {
106                                         chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name.c_str(), text);
107                                 }
108                         }
109                         else
110                         {
111                                 chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text);
112                         }
113
114                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,status,exempt_list));
115                 }
116                 else
117                 {
118                         /* no such nick/channel */
119                         user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target);
120                         return CMD_FAILURE;
121                 }
122                 return CMD_SUCCESS;
123         }
124         
125         const char* destnick = parameters[0].c_str();
126
127         if (IS_LOCAL(user))
128         {
129                 const char* targetserver = strchr(destnick, '@');
130
131                 if (targetserver)
132                 {
133                         std::string nickonly;
134
135                         nickonly.assign(destnick, 0, targetserver - destnick + 1);
136                         dest = ServerInstance->FindNickOnly(nickonly);
137                         if (dest && strcasecmp(dest->server, targetserver + 1))
138                         {
139                                 /* Incorrect server for user */
140                                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
141                                 return CMD_FAILURE;
142                         }
143                 }
144                 else
145                         dest = ServerInstance->FindNickOnly(destnick);
146         }
147         else
148                 dest = ServerInstance->FindNick(destnick);
149
150         if (dest)
151         {
152                 if (parameters[1].empty())
153                 {
154                         user->WriteNumeric(412, "%s :No text to send", user->nick.c_str());
155                         return CMD_FAILURE;
156                 }
157
158                 int MOD_RESULT = 0;
159                 std::string temp = parameters[1];
160                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
161                 if (MOD_RESULT) {
162                         return CMD_FAILURE;
163                 }
164                 const char* text = temp.c_str();
165
166                 FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,text,0,exempt_list));
167
168                 if (IS_LOCAL(dest))
169                 {
170                         // direct write, same server
171                         user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text);
172                 }
173
174                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,text,0,exempt_list));
175         }
176         else
177         {
178                 /* no such nick/channel */
179                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
180                 return CMD_FAILURE;
181         }
182
183         return CMD_SUCCESS;
184
185 }
186