]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Don't kill cloaking users when hash/md5 is missing.
[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 Uli Schlachter <psychon@inspircd.org>
8  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2006 Craig Edwards <brain@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27
28 enum
29 {
30         // From UnrealIRCd.
31         ERR_NOOPERMOTD = 425,
32
33         // From ircd-ratbox.
34         RPL_OMOTDSTART = 720,
35         RPL_OMOTD = 721,
36         RPL_ENDOFOMOTD = 722
37 };
38
39 /** Handle /OPERMOTD
40  */
41 class CommandOpermotd : public Command
42 {
43  public:
44         file_cache opermotd;
45
46         CommandOpermotd(Module* Creator) : Command(Creator,"OPERMOTD", 0, 1)
47         {
48                 flags_needed = 'o';
49                 syntax = "[<servername>]";
50         }
51
52         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
53         {
54                 if ((parameters.empty()) || (irc::equals(parameters[0], ServerInstance->Config->ServerName)))
55                         ShowOperMOTD(user, true);
56                 return CMD_SUCCESS;
57         }
58
59         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
60         {
61                 if ((!parameters.empty()) && (parameters[0].find('.') != std::string::npos))
62                         return ROUTE_OPT_UCAST(parameters[0]);
63                 return ROUTE_LOCALONLY;
64         }
65
66         void ShowOperMOTD(User* user, bool show_missing)
67         {
68                 if (opermotd.empty())
69                 {
70                         if (show_missing)
71                                 user->WriteRemoteNumeric(ERR_NOOPERMOTD, "OPERMOTD file is missing.");
72                         return;
73                 }
74
75                 user->WriteRemoteNumeric(RPL_OMOTDSTART, "Server operators message of the day");
76
77                 for (file_cache::const_iterator i = opermotd.begin(); i != opermotd.end(); ++i)
78                 {
79                         user->WriteRemoteNumeric(RPL_OMOTD, InspIRCd::Format(" %s", i->c_str()));
80                 }
81
82                 user->WriteRemoteNumeric(RPL_ENDOFOMOTD, "End of OPERMOTD");
83         }
84 };
85
86
87 class ModuleOpermotd : public Module
88 {
89         CommandOpermotd cmd;
90         bool onoper;
91  public:
92
93         ModuleOpermotd()
94                 : cmd(this)
95         {
96         }
97
98         Version GetVersion() CXX11_OVERRIDE
99         {
100                 return Version("Adds the /OPERMOTD command which adds a special message of the day for server operators.", VF_VENDOR | VF_OPTCOMMON);
101         }
102
103         void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE
104         {
105                 if (onoper && IS_LOCAL(user))
106                         cmd.ShowOperMOTD(user, false);
107         }
108
109         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
110         {
111                 cmd.opermotd.clear();
112                 ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd");
113                 onoper = conf->getBool("onoper", true);
114
115                 try
116                 {
117                         FileReader reader(conf->getString("file", "opermotd", 1));
118                         cmd.opermotd = reader.GetVector();
119                         InspIRCd::ProcessColors(cmd.opermotd);
120                 }
121                 catch (CoreException&)
122                 {
123                         // Nothing happens here as we do the error handling in ShowOperMOTD.
124                 }
125         }
126 };
127
128 MODULE_INIT(ModuleOpermotd)