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