]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
Add skeleton functions for UID stuff.
[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 "configreader.h"
16 #include "users.h"
17 #include "modules.h"
18 #include "wildcard.h"
19 #include "commands/cmd_notice.h"
20
21 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
22 {
23         return new cmd_notice(Instance);
24 }
25
26 CmdResult cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
27 {
28         userrec *dest;
29         chanrec *chan;
30
31         CUList exempt_list;
32
33         user->idle_lastmsg = ServerInstance->Time();
34         
35         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
36                 return CMD_SUCCESS;
37         if ((parameters[0][0] == '$') && (IS_OPER(user) || ServerInstance->ULine(user->server)))
38         {
39                 int MOD_RESULT = 0;
40                 std::string temp = parameters[1];
41                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0,exempt_list));
42                 if (MOD_RESULT)
43                         return CMD_FAILURE;
44                 parameters[1] = temp.c_str();
45                 // notice to server mask
46                 const char* servermask = parameters[0] + 1;
47                 if (match(ServerInstance->Config->ServerName,servermask))
48                 {
49                         user->SendAll("NOTICE", "%s", parameters[1]);
50                 }
51                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
52                 return CMD_SUCCESS;
53         }
54         char status = 0;
55         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
56         {
57                 status = *parameters[0];
58                 parameters[0]++;
59         }
60         if (*parameters[0] == '#')
61         {
62                 chan = ServerInstance->FindChan(parameters[0]);
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->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
73                                         return CMD_FAILURE;
74                                 }
75                                 if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE))
76                                 {
77                                         user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
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                         parameters[1] = temp.c_str();
89
90                         if (temp.empty())
91                         {
92                                 user->WriteServ("412 %s :No text to send", user->nick);
93                                 return CMD_FAILURE;
94                         }
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         dest = ServerInstance->FindNick(parameters[0]);
124         if (dest)
125         {
126                 if (!*parameters[1])
127                 {
128                         user->WriteServ("412 %s :No text to send", user->nick);
129                         return CMD_FAILURE;
130                 }
131
132                 int MOD_RESULT = 0;
133                 std::string temp = parameters[1];
134                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
135                 if (MOD_RESULT) {
136                         return CMD_FAILURE;
137                 }
138                 parameters[1] = (char*)temp.c_str();
139
140                 if (IS_LOCAL(dest))
141                 {
142                         // direct write, same server
143                         user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
144                 }
145
146                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
147         }
148         else
149         {
150                 /* no such nick/channel */
151                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
152                 return CMD_FAILURE;
153         }
154
155         return CMD_SUCCESS;
156
157 }
158