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