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