]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
Same again
[user/henk/code/inspircd.git] / src / cmd_notice.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "configreader.h"
18 #include "users.h"
19 #include "modules.h"
20 #include "wildcard.h"
21 #include "commands/cmd_notice.h"
22
23
24
25 extern "C" command_t* init_command(InspIRCd* Instance)
26 {
27         return new cmd_notice(Instance);
28 }
29
30 CmdResult cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
31 {
32         userrec *dest;
33         chanrec *chan;
34
35         CUList exempt_list;
36
37         user->idle_lastmsg = ServerInstance->Time();
38         
39         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
40                 return CMD_SUCCESS;
41         if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
42         {
43                 int MOD_RESULT = 0;
44                 std::string temp = parameters[1];
45                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0,exempt_list));
46                 if (MOD_RESULT)
47                         return CMD_FAILURE;
48                 parameters[1] = (char*)temp.c_str();
49                 // notice to server mask
50                 const char* servermask = parameters[0] + 1;
51                 if (match(ServerInstance->Config->ServerName,servermask))
52                 {
53                         user->NoticeAll("%s",parameters[1]);
54                 }
55                 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0,exempt_list));
56                 return CMD_SUCCESS;
57         }
58         char status = 0;
59         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
60         {
61                 status = *parameters[0];
62                 parameters[0]++;
63         }
64         if (*parameters[0] == '#')
65         {
66                 chan = ServerInstance->FindChan(parameters[0]);
67
68                 exempt_list[user] = user;
69
70                 if (chan)
71                 {
72                         if (IS_LOCAL(user))
73                         {
74                                 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
75                                 {
76                                         user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
77                                         return CMD_FAILURE;
78                                 }
79                                 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
80                                 {
81                                         user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
82                                         return CMD_FAILURE;
83                                 }
84                         }
85
86                         int MOD_RESULT = 0;
87
88                         std::string temp = parameters[1];
89                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list));
90                         if (MOD_RESULT) {
91                                 return CMD_FAILURE;
92                         }
93                         parameters[1] = temp.c_str();
94
95                         if (temp == "")
96                         {
97                                 user->WriteServ("412 %s No text to send", user->nick);
98                                 return CMD_FAILURE;
99                         }
100
101                         chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name, parameters[1]);
102
103                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status,exempt_list));
104                 }
105                 else
106                 {
107                         /* no such nick/channel */
108                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
109                         return CMD_FAILURE;
110                 }
111                 return CMD_SUCCESS;
112         }
113         
114         dest = ServerInstance->FindNick(parameters[0]);
115         if (dest)
116         {
117                 int MOD_RESULT = 0;
118                 
119                 std::string temp = parameters[1];
120                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list));
121                 if (MOD_RESULT) {
122                         return CMD_FAILURE;
123                 }
124                 parameters[1] = (char*)temp.c_str();
125
126                 if (IS_LOCAL(dest))
127                 {
128                         // direct write, same server
129                         user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
130                 }
131
132                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0,exempt_list));
133         }
134         else
135         {
136                 /* no such nick/channel */
137                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
138                 return CMD_FAILURE;
139         }
140
141         return CMD_SUCCESS;
142
143 }
144