]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
Fix for parameters which contain a colon (which is not the first char in the string)
[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 void cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
24 {
25         userrec *dest;
26         chanrec *chan;
27
28         user->idle_lastmsg = ServerInstance->Time();
29         
30         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
31                 return;
32         if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
33         {
34                 int MOD_RESULT = 0;
35                 std::string temp = parameters[1];
36                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0));
37                 if (MOD_RESULT)
38                         return;
39                 parameters[1] = (char*)temp.c_str();
40                 // notice to server mask
41                 const char* servermask = parameters[0] + 1;
42                 if (match(ServerInstance->Config->ServerName,servermask))
43                 {
44                         user->NoticeAll("%s",parameters[1]);
45                 }
46                 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0));
47                 return;
48         }
49         char status = 0;
50         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
51         {
52                 status = *parameters[0];
53                 parameters[0]++;
54         }
55         if (*parameters[0] == '#')
56         {
57                 chan = ServerInstance->FindChan(parameters[0]);
58                 if (chan)
59                 {
60                         if (IS_LOCAL(user))
61                         {
62                                 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
63                                 {
64                                         user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
65                                         return;
66                                 }
67                                 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
68                                 {
69                                         user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
70                                         return;
71                                 }
72                         }
73
74                         int MOD_RESULT = 0;
75
76                         std::string temp = parameters[1];
77                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status));
78                         if (MOD_RESULT) {
79                                 return;
80                         }
81                         parameters[1] = (char*)temp.c_str();
82
83                         if (temp == "")
84                         {
85                                 user->WriteServ("412 %s No text to send", user->nick);
86                                 return;
87                         }
88
89                         chan->WriteAllExceptSender(user, status, "NOTICE %s :%s", chan->name, parameters[1]);
90
91                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status));
92                 }
93                 else
94                 {
95                         /* no such nick/channel */
96                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
97                 }
98                 return;
99         }
100         
101         dest = ServerInstance->FindNick(parameters[0]);
102         if (dest)
103         {
104                 int MOD_RESULT = 0;
105                 
106                 std::string temp = parameters[1];
107                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0));
108                 if (MOD_RESULT) {
109                         return;
110                 }
111                 parameters[1] = (char*)temp.c_str();
112
113                 if (IS_LOCAL(dest))
114                 {
115                         // direct write, same server
116                         user->WriteTo(dest, "NOTICE %s :%s", dest->nick, parameters[1]);
117                 }
118
119                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0));
120         }
121         else
122         {
123                 /* no such nick/channel */
124                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
125         }
126 }