1 /*
2 * InspIRCd -- Internet Relay Chat Daemon
3 *
4 * Copyright (C) 2014, 2018-2020 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
9 * Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
10 *
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24
25 #include "inspircd.h"
26 #include "core_info.h"
27
CommandMotd(Module * parent)28 CommandMotd::CommandMotd(Module* parent)
29 : ServerTargetCommand(parent, "MOTD")
30 {
31 syntax = "[<servername>]";
32 }
33
34 /** Handle /MOTD
35 */
Handle(User * user,const Params & parameters)36 CmdResult CommandMotd::Handle(User* user, const Params& parameters)
37 {
38 if (parameters.size() > 0 && !irc::equals(parameters[0], ServerInstance->Config->ServerName))
39 {
40 // Give extra penalty if a non-oper queries the /MOTD of a remote server
41 LocalUser* localuser = IS_LOCAL(user);
42 if ((localuser) && (!user->IsOper()))
43 localuser->CommandFloodPenalty += 2000;
44 return CMD_SUCCESS;
45 }
46
47 ConfigTag* tag = ServerInstance->Config->EmptyTag;
48 LocalUser* localuser = IS_LOCAL(user);
49 if (localuser)
50 tag = localuser->GetClass()->config;
51
52 const std::string motd_name = tag->getString("motd", "motd", 1);
53 ConfigFileCache::iterator motd = motds.find(motd_name);
54 if (motd == motds.end())
55 {
56 user->WriteRemoteNumeric(ERR_NOMOTD, "Message of the day file is missing.");
57 return CMD_SUCCESS;
58 }
59
60 user->WriteRemoteNumeric(RPL_MOTDSTART, InspIRCd::Format("%s message of the day", ServerInstance->Config->GetServerName().c_str()));
61
62 for (file_cache::iterator i = motd->second.begin(); i != motd->second.end(); i++)
63 user->WriteRemoteNumeric(RPL_MOTD, InspIRCd::Format(" %s", i->c_str()));
64
65 user->WriteRemoteNumeric(RPL_ENDOFMOTD, "End of message of the day.");
66
67 return CMD_SUCCESS;
68 }
69