]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
Make irc::spacify take 'const char*' instead of 'char*'
[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->NoticeAll("%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
83                         int MOD_RESULT = 0;
84
85                         std::string temp = parameters[1];
86                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
87                         if (MOD_RESULT) {
88                                 return CMD_FAILURE;
89                         }
90                         parameters[1] = temp.c_str();
91
92                         if (temp == "")
93                         {
94                                 user->WriteServ("412 %s No text to send", user->nick);
95                                 return CMD_FAILURE;
96                         }
97
98                         if (status)
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 %s :%s", chan->name, parameters[1]);
105                         }
106
107                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status,exempt_list));
108                 }
109                 else
110                 {
111                         /* no such nick/channel */
112                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
113                         return CMD_FAILURE;
114                 }
115                 return CMD_SUCCESS;
116         }
117         
118         dest = ServerInstance->FindNick(parameters[0]);
119         if (dest)
120         {
121                 int MOD_RESULT = 0;
122                 
123                 std::string temp = parameters[1];
124                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
125                 if (MOD_RESULT) {
126                         return CMD_FAILURE;
127                 }
128                 parameters[1] = (char*)temp.c_str();
129
130                 if (IS_LOCAL(dest))
131                 {
132                         // direct write, same server
133                         user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
134                 }
135
136                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
137         }
138         else
139         {
140                 /* no such nick/channel */
141                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
142                 return CMD_FAILURE;
143         }
144
145         return CMD_SUCCESS;
146
147 }
148