]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/addline.cpp
f4485030ae6aa5688c1a0e790f06f90ff76e6c67
[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 "treeserver.h"
24 #include "utils.h"
25 #include "commands.h"
26
27 CmdResult CommandAddLine::Handle(User* usr, std::vector<std::string>& params)
28 {
29         XLineFactory* xlf = ServerInstance->XLines->GetFactory(params[0]);
30         const std::string& setter = usr->nick;
31
32         if (!xlf)
33         {
34                 ServerInstance->SNO->WriteToSnoMask('d',"%s sent me an unknown ADDLINE type (%s).",setter.c_str(),params[0].c_str());
35                 return CMD_FAILURE;
36         }
37
38         XLine* xl = NULL;
39         try
40         {
41                 xl = xlf->Generate(ServerInstance->Time(), ConvToInt(params[4]), params[2], params[5], params[1]);
42         }
43         catch (ModuleException &e)
44         {
45                 ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason());
46                 return CMD_FAILURE;
47         }
48         xl->SetCreateTime(ConvToInt(params[3]));
49         if (ServerInstance->XLines->AddLine(xl, NULL))
50         {
51                 if (xl->duration)
52                 {
53                         std::string timestr = InspIRCd::TimeString(xl->expiry);
54                         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" : "",
55                                         params[1].c_str(), timestr.c_str(), params[5].c_str());
56                 }
57                 else
58                 {
59                         ServerInstance->SNO->WriteToSnoMask('X',"%s added permanent %s%s on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "",
60                                         params[1].c_str(),params[5].c_str());
61                 }
62
63                 TreeServer* remoteserver = Utils->FindServer(usr->server);
64
65                 if (!remoteserver->bursting)
66                 {
67                         ServerInstance->XLines->ApplyLines();
68                 }
69                 return CMD_SUCCESS;
70         }
71         else
72         {
73                 delete xl;
74                 return CMD_FAILURE;
75         }
76 }
77
78 CommandAddLine::Builder::Builder(XLine* xline, User* user)
79         : CmdBuilder(user, "ADDLINE")
80 {
81         push(xline->type);
82         push(xline->Displayable());
83         push(xline->source);
84         push_int(xline->set_time);
85         push_int(xline->duration);
86         push_last(xline->reason);
87 }