]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/privmsg.cpp
c7acf393c1f784eba74fe006eb7a3f8985e8f53a
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / privmsg.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "xline.h"
16
17 #include "treesocket.h"
18 #include "treeserver.h"
19 #include "utils.h"
20
21 /** remote server PRIVMSG/NOTICE */
22 bool TreeSocket::ServerMessage(const std::string &messagetype, const std::string &prefix, parameterlist &params, const std::string &sourceserv)
23 {
24         if (params.size() >= 2)
25         {
26                 CUList except_list;
27                 char status = '\0';
28                 const char* target = params[0].c_str();
29                 std::string text = params[1].c_str();
30
31                 if (ServerInstance->Modes->FindPrefix(*target))
32                 {
33                         status = *target;
34                         target++;
35                 }
36
37                 Channel* channel = ServerInstance->FindChan(target);
38
39                 if (channel)
40                 {
41                         if (messagetype == "PRIVMSG")
42                         {
43                                 FOREACH_MOD_I(ServerInstance, I_OnUserMessage, OnUserMessage(Utils->ServerUser, channel, TYPE_CHANNEL, text, status, except_list));
44                         }
45                         else
46                         {
47                                 FOREACH_MOD_I(ServerInstance, I_OnUserNotice, OnUserNotice(Utils->ServerUser, channel, TYPE_CHANNEL, text, status, except_list));
48                         }
49                         TreeServer* s = Utils->FindServer(prefix);
50                         if (s)
51                         {
52                                 FOREACH_MOD_I(ServerInstance, I_OnText, OnText(Utils->ServerUser, channel, TYPE_CHANNEL, text, status, except_list));
53                                 channel->WriteChannelWithServ(s->GetName().c_str(), "%s %s :%s", messagetype.c_str(), channel->name.c_str(), text.c_str());
54                         }
55                 }
56                 else
57                 {
58                         User* user = ServerInstance->FindNick(target);
59
60                         if (user)
61                         {
62                                 if (messagetype == "PRIVMSG")
63                                 {
64                                         FOREACH_MOD_I(ServerInstance, I_OnUserMessage, OnUserMessage(Utils->ServerUser, user, TYPE_USER, text, 0, except_list));
65                                 }
66                                 else
67                                 {
68                                         FOREACH_MOD_I(ServerInstance, I_OnUserNotice, OnUserNotice(Utils->ServerUser, user, TYPE_USER, text, 0, except_list));
69                                 }
70                                 TreeServer* s = Utils->FindServer(prefix);
71                                 if (s)
72                                 {
73                                         FOREACH_MOD_I(ServerInstance, I_OnText, OnText(Utils->ServerUser, user, TYPE_USER, text, status, except_list));
74                                         user->Write(":%s %s %s :%s", s->GetName().c_str(), messagetype.c_str(), user->nick.c_str(), text.c_str());
75                                 }
76
77                         }
78                 }
79
80                 /* Propogate as channel privmsg */
81                 return Utils->DoOneToAllButSenderRaw(":" + prefix + " " + messagetype + " " + target + " :" + text, sourceserv, prefix, assign(messagetype), params);
82         }
83         return true;
84 }
85