]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / modules / m_opermotd.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2018-2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2013, 2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2006 Craig Edwards <brain@inspircd.org>
11  *   Copyright (C) 2005, 2007 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
29 enum
30 {
31         // From UnrealIRCd.
32         ERR_NOOPERMOTD = 425,
33
34         // From ircd-ratbox.
35         RPL_OMOTDSTART = 720,
36         RPL_OMOTD = 721,
37         RPL_ENDOFOMOTD = 722
38 };
39
40 /** Handle /OPERMOTD
41  */
42 class CommandOpermotd : public Command
43 {
44  public:
45         file_cache opermotd;
46
47         CommandOpermotd(Module* Creator) : Command(Creator,"OPERMOTD", 0, 1)
48         {
49                 flags_needed = 'o';
50                 syntax = "[<servername>]";
51         }
52
53         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
54         {
55                 if ((parameters.empty()) || (irc::equals(parameters[0], ServerInstance->Config->ServerName)))
56                         ShowOperMOTD(user, true);
57                 return CMD_SUCCESS;
58         }
59
60         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
61         {
62                 if ((!parameters.empty()) && (parameters[0].find('.') != std::string::npos))
63                         return ROUTE_OPT_UCAST(parameters[0]);
64                 return ROUTE_LOCALONLY;
65         }
66
67         void ShowOperMOTD(User* user, bool show_missing)
68         {
69                 if (opermotd.empty())
70                 {
71                         if (show_missing)
72                                 user->WriteRemoteNumeric(ERR_NOOPERMOTD, "OPERMOTD file is missing.");
73                         return;
74                 }
75
76                 user->WriteRemoteNumeric(RPL_OMOTDSTART, "Server operators message of the day");
77
78                 for (file_cache::const_iterator i = opermotd.begin(); i != opermotd.end(); ++i)
79                 {
80                         user->WriteRemoteNumeric(RPL_OMOTD, InspIRCd::Format(" %s", i->c_str()));
81                 }
82
83                 user->WriteRemoteNumeric(RPL_ENDOFOMOTD, "End of OPERMOTD");
84         }
85 };
86
87
88 class ModuleOpermotd : public Module
89 {
90         CommandOpermotd cmd;
91         bool onoper;
92  public:
93
94         ModuleOpermotd()
95                 : cmd(this)
96         {
97         }
98
99         Version GetVersion() CXX11_OVERRIDE
100         {
101                 return Version("Adds the /OPERMOTD command which adds a special message of the day for server operators.", VF_VENDOR | VF_OPTCOMMON);
102         }
103
104         void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE
105         {
106                 if (onoper && IS_LOCAL(user))
107                         cmd.ShowOperMOTD(user, false);
108         }
109
110         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
111         {
112                 cmd.opermotd.clear();
113                 ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd");
114                 onoper = conf->getBool("onoper", true);
115
116                 try
117                 {
118                         FileReader reader(conf->getString("file", "opermotd", 1));
119                         cmd.opermotd = reader.GetVector();
120                         InspIRCd::ProcessColors(cmd.opermotd);
121                 }
122                 catch (CoreException&)
123                 {
124                         // Nothing happens here as we do the error handling in ShowOperMOTD.
125                 }
126         }
127 };
128
129 MODULE_INIT(ModuleOpermotd)