]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
Made SANICK not collide the user (theres no need to in the new 1.1 now we have return...
[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         user->idle_lastmsg = ServerInstance->Time();
36         
37         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
38                 return CMD_SUCCESS;
39         if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
40         {
41                 int MOD_RESULT = 0;
42                 std::string temp = parameters[1];
43                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0));
44                 if (MOD_RESULT)
45                         return CMD_FAILURE;
46                 parameters[1] = (char*)temp.c_str();
47                 // notice to server mask
48                 const char* servermask = parameters[0] + 1;
49                 if (match(ServerInstance->Config->ServerName,servermask))
50                 {
51                         user->NoticeAll("%s",parameters[1]);
52                 }
53                 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0));
54                 return CMD_SUCCESS;
55         }
56         char status = 0;
57         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
58         {
59                 status = *parameters[0];
60                 parameters[0]++;
61         }
62         if (*parameters[0] == '#')
63         {
64                 chan = ServerInstance->FindChan(parameters[0]);
65                 if (chan)
66                 {
67                         if (IS_LOCAL(user))
68                         {
69                                 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
70                                 {
71                                         user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
72                                         return CMD_FAILURE;
73                                 }
74                                 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
75                                 {
76                                         user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
77                                         return CMD_FAILURE;
78                                 }
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));
85                         if (MOD_RESULT) {
86                                 return CMD_FAILURE;
87                         }
88                         parameters[1] = (char*)temp.c_str();
89
90                         if (temp == "")
91                         {
92                                 user->WriteServ("412 %s No text to send", user->nick);
93                                 return CMD_FAILURE;
94                         }
95
96                         chan->WriteAllExceptSender(user, status, "NOTICE %s :%s", chan->name, parameters[1]);
97
98                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status));
99                 }
100                 else
101                 {
102                         /* no such nick/channel */
103                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
104                         return CMD_FAILURE;
105                 }
106                 return CMD_SUCCESS;
107         }
108         
109         dest = ServerInstance->FindNick(parameters[0]);
110         if (dest)
111         {
112                 int MOD_RESULT = 0;
113                 
114                 std::string temp = parameters[1];
115                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0));
116                 if (MOD_RESULT) {
117                         return CMD_FAILURE;
118                 }
119                 parameters[1] = (char*)temp.c_str();
120
121                 if (IS_LOCAL(dest))
122                 {
123                         // direct write, same server
124                         user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
125                 }
126
127                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0));
128         }
129         else
130         {
131                 /* no such nick/channel */
132                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
133                 return CMD_FAILURE;
134         }
135
136         return CMD_SUCCESS;
137
138 }
139