]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
6abf16b78354b6c9d94016e623373442a12836c8
[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 /** Handle /OPERMOTD
26  */
27 class CommandOpermotd : public Command
28 {
29  public:
30         file_cache opermotd;
31
32         CommandOpermotd(Module* Creator) : Command(Creator,"OPERMOTD", 0, 1)
33         {
34                 flags_needed = 'o'; syntax = "[<servername>]";
35         }
36
37         CmdResult Handle (const std::vector<std::string>& parameters, User* user)
38         {
39                 if ((parameters.empty()) || (parameters[0] == ServerInstance->Config->ServerName))
40                         ShowOperMOTD(user);
41                 return CMD_SUCCESS;
42         }
43
44         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
45         {
46                 if (!parameters.empty())
47                         return ROUTE_OPT_UCAST(parameters[0]);
48                 return ROUTE_LOCALONLY;
49         }
50
51         void ShowOperMOTD(User* user)
52         {
53                 const std::string& servername = ServerInstance->Config->ServerName;
54                 if (opermotd.empty())
55                 {
56                         user->SendText(":%s 455 %s :OPERMOTD file is missing", servername.c_str(), user->nick.c_str());
57                         return;
58                 }
59
60                 user->SendText(":%s 375 %s :- IRC Operators Message of the Day", servername.c_str(), user->nick.c_str());
61
62                 for (file_cache::const_iterator i = opermotd.begin(); i != opermotd.end(); ++i)
63                 {
64                         user->SendText(":%s 372 %s :- %s", servername.c_str(), user->nick.c_str(), i->c_str());
65                 }
66
67                 user->SendText(":%s 376 %s :- End of OPERMOTD", servername.c_str(), user->nick.c_str());
68         }
69 };
70
71
72 class ModuleOpermotd : public Module
73 {
74         CommandOpermotd cmd;
75         bool onoper;
76  public:
77
78         ModuleOpermotd()
79                 : cmd(this)
80         {
81         }
82
83         void init() CXX11_OVERRIDE
84         {
85                 ServerInstance->Modules->AddService(cmd);
86                 OnRehash(NULL);
87                 Implementation eventlist[] = { I_OnRehash, I_OnOper };
88                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
89         }
90
91         Version GetVersion() CXX11_OVERRIDE
92         {
93                 return Version("Shows a message to opers after oper-up, adds /opermotd", VF_VENDOR | VF_OPTCOMMON);
94         }
95
96         void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE
97         {
98                 if (onoper && IS_LOCAL(user))
99                         cmd.ShowOperMOTD(user);
100         }
101
102         void OnRehash(User* user) CXX11_OVERRIDE
103         {
104                 cmd.opermotd.clear();
105                 ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd");
106                 onoper = conf->getBool("onoper", true);
107
108                 try
109                 {
110                         FileReader reader(conf->getString("file", "opermotd"));
111                         cmd.opermotd = reader.GetVector();
112                 }
113                 catch (CoreException&)
114                 {
115                         // Nothing happens here as we do the error handling in ShowOperMOTD.
116                 }
117
118                 if (conf->getBool("processcolors"))
119                         InspIRCd::ProcessColors(cmd.opermotd);
120         }
121 };
122
123 MODULE_INIT(ModuleOpermotd)