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