]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
More tweaks
[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 <map>
18 #include <sstream>
19 #include <vector>
20 #include <deque>
21 #include "configreader.h"
22 #include "hash_map.h"
23 #include "users.h"
24 #include "modules.h"
25 #include "wildcard.h"
26 #include "commands.h"
27
28 #include "hashcomp.h"
29 #include "commands/cmd_notice.h"
30
31 void cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
32 {
33         userrec *dest;
34         chanrec *chan;
35
36         user->idle_lastmsg = ServerInstance->Time();
37         
38         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
39                 return;
40         if ((parameters[0][0] == '$') && ((*user->oper) || (ServerInstance->ULine(user->server))))
41         {
42                 int MOD_RESULT = 0;
43                 std::string temp = parameters[1];
44                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,(void*)parameters[0],TYPE_SERVER,temp,0));
45                 if (MOD_RESULT)
46                         return;
47                 parameters[1] = (char*)temp.c_str();
48                 // notice to server mask
49                 const char* servermask = parameters[0] + 1;
50                 if (match(ServerInstance->Config->ServerName,servermask))
51                 {
52                         user->NoticeAll("%s",parameters[1]);
53                 }
54                 FOREACH_MOD(I_OnUserMessage,OnUserNotice(user,(void*)parameters[0],TYPE_SERVER,parameters[1],0));
55                 return;
56         }
57         char status = 0;
58         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
59         {
60                 status = *parameters[0];
61                 parameters[0]++;
62         }
63         if (*parameters[0] == '#')
64         {
65                 chan = ServerInstance->FindChan(parameters[0]);
66                 if (chan)
67                 {
68                         if (IS_LOCAL(user))
69                         {
70                                 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
71                                 {
72                                         user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
73                                         return;
74                                 }
75                                 if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
76                                 {
77                                         user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
78                                         return;
79                                 }
80                         }
81
82                         int MOD_RESULT = 0;
83
84                         std::string temp = parameters[1];
85                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status));
86                         if (MOD_RESULT) {
87                                 return;
88                         }
89                         parameters[1] = (char*)temp.c_str();
90
91                         if (temp == "")
92                         {
93                                 user->WriteServ("412 %s No text to send", user->nick);
94                                 return;
95                         }
96
97                         chan->WriteAllExceptSender(user, status, "NOTICE %s :%s", chan->name, parameters[1]);
98
99                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status));
100                 }
101                 else
102                 {
103                         /* no such nick/channel */
104                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
105                 }
106                 return;
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;
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         }
134 }