]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
Fix test client error cheecking on result types
[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                 // notice to server mask
51                 const char* servermask = parameters[0] + 1;
52                 if (match(Config->ServerName,servermask))
53                 {
54                         NoticeAll(user, true, "%s",parameters[1]);
55                 }
56                 return;
57         }
58         char status = 0;
59         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
60         {
61                 status = *parameters[0];
62                 parameters[0]++;
63         }
64         if (*parameters[0] == '#')
65         {
66                 chan = FindChan(parameters[0]);
67                 if (chan)
68                 {
69                         if (IS_LOCAL(user))
70                         {
71                                 if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
72                                 {
73                                         WriteServ(user->fd,"404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
74                                         return;
75                                 }
76                                 if ((chan->modes[CM_MODERATED]) && (cstatus(user,chan)<STATUS_VOICE))
77                                 {
78                                         WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
79                                         return;
80                                 }
81                         }
82
83                         int MOD_RESULT = 0;
84
85                         std::string temp = parameters[1];
86                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status));
87                         if (MOD_RESULT) {
88                                 return;
89                         }
90                         parameters[1] = (char*)temp.c_str();
91
92                         if (temp == "")
93                         {
94                                 WriteServ(user->fd,"412 %s No text to send", user->nick);
95                                 return;
96                         }
97
98                         ChanExceptSender(chan, user, status, "NOTICE %s :%s", chan->name, parameters[1]);
99
100                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status));
101                 }
102                 else
103                 {
104                         /* no such nick/channel */
105                         WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
106                 }
107                 return;
108         }
109         
110         dest = Find(parameters[0]);
111         if (dest)
112         {
113                 int MOD_RESULT = 0;
114                 
115                 std::string temp = parameters[1];
116                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0));
117                 if (MOD_RESULT) {
118                         return;
119                 }
120                 parameters[1] = (char*)temp.c_str();
121
122                 if (dest->fd > -1)
123                 {
124                         // direct write, same server
125                         WriteTo(user, dest, "NOTICE %s :%s", dest->nick, parameters[1]);
126                 }
127
128                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0));
129         }
130         else
131         {
132                 /* no such nick/channel */
133                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
134         }
135 }