]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/addline.cpp
2ef76a351ce7e8fc2b1da52fffdd658363254619
[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 bool TreeSocket::AddLine(const std::string &prefix, parameterlist &params)
28 {
29         if (params.size() < 6)
30         {
31                 const std::string& servername = MyRoot->GetName();
32                 ServerInstance->SNO->WriteToSnoMask('d', "%s sent me a malformed ADDLINE", servername.c_str());
33                 return true;
34         }
35
36         XLineFactory* xlf = ServerInstance->XLines->GetFactory(params[0]);
37
38         std::string setter = "<unknown>";
39         User* usr = ServerInstance->FindNick(prefix);
40         if (usr)
41                 setter = usr->nick;
42         else
43         {
44                 TreeServer* t = Utils->FindServer(prefix);
45                 if (t)
46                         setter = t->GetName();
47         }
48
49         if (!xlf)
50         {
51                 ServerInstance->SNO->WriteToSnoMask('d',"%s sent me an unknown ADDLINE type (%s).",setter.c_str(),params[0].c_str());
52                 return true;
53         }
54
55         XLine* xl = NULL;
56         try
57         {
58                 xl = xlf->Generate(ServerInstance->Time(), ConvToInt(params[4]), params[2], params[5], params[1]);
59         }
60         catch (ModuleException &e)
61         {
62                 ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason());
63                 return true;
64         }
65         xl->SetCreateTime(ConvToInt(params[3]));
66         if (ServerInstance->XLines->AddLine(xl, NULL))
67         {
68                 if (xl->duration)
69                 {
70                         std::string timestr = ServerInstance->TimeString(xl->expiry);
71                         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" : "",
72                                         params[1].c_str(), timestr.c_str(), params[5].c_str());
73                 }
74                 else
75                 {
76                         ServerInstance->SNO->WriteToSnoMask('X',"%s added permanent %s%s on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "",
77                                         params[1].c_str(),params[5].c_str());
78                 }
79                 params[5] = ":" + params[5];
80
81                 User* u = ServerInstance->FindNick(prefix);
82                 Utils->DoOneToAllButSender(prefix, "ADDLINE", params, u ? u->server : prefix);
83                 TreeServer *remoteserver = Utils->FindServer(u ? u->server : prefix);
84
85                 if (!remoteserver->bursting)
86                 {
87                         ServerInstance->XLines->ApplyLines();
88                 }
89         }
90         else
91                 delete xl;
92
93         return true;
94 }
95