1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
5  *   Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2013-2014 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2008, 2010 Craig Edwards <brain@inspircd.org>
11  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 
27 #include "inspircd.h"
28 #include "xline.h"
29 
30 #include "treeserver.h"
31 #include "utils.h"
32 #include "commands.h"
33 
Handle(User * usr,Params & params)34 CmdResult CommandAddLine::Handle(User* usr, Params& params)
35 {
36 	XLineFactory* xlf = ServerInstance->XLines->GetFactory(params[0]);
37 	const std::string& setter = usr->nick;
38 
39 	if (!xlf)
40 	{
41 		ServerInstance->SNO->WriteToSnoMask('x', "%s sent me an unknown ADDLINE type (%s).", setter.c_str(), params[0].c_str());
42 		return CMD_FAILURE;
43 	}
44 
45 	XLine* xl = NULL;
46 	try
47 	{
48 		xl = xlf->Generate(ServerInstance->Time(), ConvToNum<unsigned long>(params[4]), params[2], params[5], params[1]);
49 	}
50 	catch (ModuleException &e)
51 	{
52 		ServerInstance->SNO->WriteToSnoMask('x', "Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason().c_str());
53 		return CMD_FAILURE;
54 	}
55 	xl->SetCreateTime(ConvToNum<time_t>(params[3]));
56 	if (ServerInstance->XLines->AddLine(xl, NULL))
57 	{
58 		if (xl->duration)
59 		{
60 			ServerInstance->SNO->WriteToSnoMask('X', "%s added timed %s%s for %s, expires in %s (on %s): %s",
61 				setter.c_str(), params[0].c_str(), params[0].length() == 1 ? "-line" : "",
62 				params[1].c_str(), InspIRCd::DurationString(xl->duration).c_str(),
63 				InspIRCd::TimeString(xl->expiry).c_str(), params[5].c_str());
64 		}
65 		else
66 		{
67 			ServerInstance->SNO->WriteToSnoMask('X', "%s added permanent %s%s on %s: %s",
68 				setter.c_str(), params[0].c_str(), params[0].length() == 1 ? "-line" : "",
69 				params[1].c_str(), params[5].c_str());
70 		}
71 
72 		TreeServer* remoteserver = TreeServer::Get(usr);
73 
74 		if (!remoteserver->IsBursting())
75 		{
76 			ServerInstance->XLines->ApplyLines();
77 		}
78 		return CMD_SUCCESS;
79 	}
80 	else
81 	{
82 		delete xl;
83 		return CMD_FAILURE;
84 	}
85 }
86 
Builder(XLine * xline,User * user)87 CommandAddLine::Builder::Builder(XLine* xline, User* user)
88 	: CmdBuilder(user, "ADDLINE")
89 {
90 	push(xline->type);
91 	push(xline->Displayable());
92 	push(xline->source);
93 	push_int(xline->set_time);
94 	push_int(xline->duration);
95 	push_last(xline->reason);
96 }
97