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