]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_notice.cpp
More cleanup
[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 using namespace std;
18
19 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "inspircd_io.h"
22 #include <time.h>
23 #include <string>
24 #ifdef GCC3
25 #include <ext/hash_map>
26 #else
27 #include <hash_map>
28 #endif
29 #include <map>
30 #include <sstream>
31 #include <vector>
32 #include <deque>
33 #include "users.h"
34 #include "ctables.h"
35 #include "globals.h"
36 #include "modules.h"
37 #include "dynamic.h"
38 #include "wildcard.h"
39 #include "message.h"
40 #include "commands.h"
41 #include "mode.h"
42 #include "xline.h"
43 #include "inspstring.h"
44 #include "dnsqueue.h"
45 #include "helperfuncs.h"
46 #include "hashcomp.h"
47 #include "socketengine.h"
48 #include "typedefs.h"
49 #include "command_parse.h"
50 #include "cmd_notice.h"
51
52 extern ServerConfig* Config;
53 extern InspIRCd* ServerInstance;
54 extern int MODCOUNT;
55 extern std::vector<Module*> modules;
56 extern std::vector<ircd_module*> factory;
57 extern time_t TIME;
58 extern user_hash clientlist;
59 extern chan_hash chanlist;
60 extern std::vector<userrec*> all_opers;
61 extern std::vector<userrec*> local_users;
62 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
63
64 void cmd_notice::Handle (char **parameters, int pcnt, userrec *user)
65 {
66         userrec *dest;
67         chanrec *chan;
68
69         user->idle_lastmsg = TIME;
70         
71         if (ServerInstance->Parser->LoopCall(this,parameters,pcnt,user,0,pcnt-2,0))
72                 return;
73         if (parameters[0][0] == '$')
74         {
75                 // notice to server mask
76                 char* servermask = parameters[0];
77                 servermask++;
78                 if (match(Config->ServerName,servermask))
79                 {
80                         NoticeAll(user, true, "%s",parameters[1]);
81                 }
82                 return;
83         }
84         char status = 0;
85         if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
86         {
87                 status = *parameters[0];
88                 parameters[0]++;
89         }
90         if (*parameters[0] == '#')
91         {
92                 chan = FindChan(parameters[0]);
93                 if (chan)
94                 {
95                         if (IS_LOCAL(user))
96                         {
97                                 if ((chan->binarymodes & CM_NOEXTERNAL) && (!chan->HasUser(user)))
98                                 {
99                                         WriteServ(user->fd,"404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
100                                         return;
101                                 }
102                                 if ((chan->binarymodes & CM_MODERATED) && (cstatus(user,chan)<STATUS_VOICE))
103                                 {
104                                         WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
105                                         return;
106                                 }
107                         }
108
109                         int MOD_RESULT = 0;
110
111                         std::string temp = parameters[1];
112                         FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status));
113                         if (MOD_RESULT) {
114                                 return;
115                         }
116                         parameters[1] = (char*)temp.c_str();
117
118                         if (temp == "")
119                         {
120                                 WriteServ(user->fd,"412 %s No text to send", user->nick);
121                                 return;
122                         }
123
124                         ChanExceptSender(chan, user, status, "NOTICE %s :%s", chan->name, parameters[1]);
125
126                         FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,parameters[1],status));
127                 }
128                 else
129                 {
130                         /* no such nick/channel */
131                         WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
132                 }
133                 return;
134         }
135         
136         dest = Find(parameters[0]);
137         if (dest)
138         {
139                 int MOD_RESULT = 0;
140                 
141                 std::string temp = parameters[1];
142                 FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0));
143                 if (MOD_RESULT) {
144                         return;
145                 }
146                 parameters[1] = (char*)temp.c_str();
147
148                 if (dest->fd > -1)
149                 {
150                         // direct write, same server
151                         WriteTo(user, dest, "NOTICE %s :%s", dest->nick, parameters[1]);
152                 }
153
154                 FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,parameters[1],0));
155         }
156         else
157         {
158                 /* no such nick/channel */
159                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
160         }
161 }
162
163