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