]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/addline.cpp
Fix SpanningTreeProtocolInterface::SendChannelPrivmsg() and SendChannelNotice() sendi...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / addline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21 #include "xline.h"
22
23 #include "treesocket.h"
24 #include "treeserver.h"
25 #include "utils.h"
26
27 /* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
28
29 bool TreeSocket::AddLine(const std::string &prefix, parameterlist &params)
30 {
31         if (params.size() < 6)
32         {
33                 std::string servername = MyRoot->GetName();
34                 ServerInstance->SNO->WriteToSnoMask('d', "%s sent me a malformed ADDLINE", servername.c_str());
35                 return true;
36         }
37
38         XLineFactory* xlf = ServerInstance->XLines->GetFactory(params[0]);
39
40         std::string setter = "<unknown>";
41         User* usr = ServerInstance->FindNick(prefix);
42         if (usr)
43                 setter = usr->nick;
44         else
45         {
46                 TreeServer* t = Utils->FindServer(prefix);
47                 if (t)
48                         setter = t->GetName();
49         }
50
51         if (!xlf)
52         {
53                 ServerInstance->SNO->WriteToSnoMask('d',"%s sent me an unknown ADDLINE type (%s).",setter.c_str(),params[0].c_str());
54                 return true;
55         }
56
57         long created = atol(params[3].c_str()), expires = atol(params[4].c_str());
58         if (created < 0 || expires < 0)
59                 return true;
60
61         XLine* xl = NULL;
62         try
63         {
64                 xl = xlf->Generate(ServerInstance->Time(), expires, params[2], params[5], params[1]);
65         }
66         catch (ModuleException &e)
67         {
68                 ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason());
69                 return true;
70         }
71         xl->SetCreateTime(created);
72         if (ServerInstance->XLines->AddLine(xl, NULL))
73         {
74                 if (xl->duration)
75                 {
76                         std::string timestr = ServerInstance->TimeString(xl->expiry);
77                         ServerInstance->SNO->WriteToSnoMask('X',"%s added %s%s on %s to expire on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "",
78                                         params[1].c_str(), timestr.c_str(), params[5].c_str());
79                 }
80                 else
81                 {
82                         ServerInstance->SNO->WriteToSnoMask('X',"%s added permanent %s%s on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "",
83                                         params[1].c_str(),params[5].c_str());
84                 }
85                 params[5] = ":" + params[5];
86
87                 User* u = ServerInstance->FindNick(prefix);
88                 Utils->DoOneToAllButSender(prefix, "ADDLINE", params, u ? u->server : prefix);
89                 TreeServer *remoteserver = Utils->FindServer(u ? u->server : prefix);
90
91                 if (!remoteserver->bursting)
92                 {
93                         ServerInstance->XLines->ApplyLines();
94                 }
95         }
96         else
97                 delete xl;
98
99         return true;
100 }
101