]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
5c107b6b190fbefd6843423675a043c14e8810c3
[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 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
26
27 /** Handle /OPERMOTD
28  */
29 class CommandOpermotd : public Command
30 {
31  public:
32         FileReader opermotd;
33
34         CommandOpermotd(Module* Creator) : Command(Creator,"OPERMOTD", 0, 1)
35         {
36                 flags_needed = 'o'; syntax = "[<servername>]";
37         }
38
39         CmdResult Handle (const std::vector<std::string>& parameters, User* user)
40         {
41                 if ((parameters.empty()) || (parameters[0] == ServerInstance->Config->ServerName))
42                         ShowOperMOTD(user);
43                 return CMD_SUCCESS;
44         }
45
46         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
47         {
48                 if (!parameters.empty())
49                         return ROUTE_OPT_UCAST(parameters[0]);
50                 return ROUTE_LOCALONLY;
51         }
52
53         void ShowOperMOTD(User* user)
54         {
55                 const std::string& servername = ServerInstance->Config->ServerName;
56                 if (!opermotd.FileSize())
57                 {
58                         user->SendText(":%s 455 %s :OPERMOTD file is missing", servername.c_str(), user->nick.c_str());
59                         return;
60                 }
61
62                 user->SendText(":%s 375 %s :- IRC Operators Message of the Day", servername.c_str(), user->nick.c_str());
63
64                 for (int i=0; i != opermotd.FileSize(); i++)
65                         user->SendText(":%s 372 %s :- %s", servername.c_str(), user->nick.c_str(), opermotd.GetLine(i).c_str());
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         void LoadOperMOTD()
79         {
80                 ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd");
81                 cmd.opermotd.LoadFile(conf->getString("file","opermotd"));
82                 onoper = conf->getBool("onoper", true);
83         }
84
85         ModuleOpermotd()
86                 : cmd(this)
87         {
88                 ServerInstance->AddCommand(&cmd);
89                 LoadOperMOTD();
90                 Implementation eventlist[] = { I_OnRehash, I_OnOper };
91                 ServerInstance->Modules->Attach(eventlist, this, 2);
92         }
93
94         virtual Version GetVersion()
95         {
96                 return Version("Shows a message to opers after oper-up, adds /opermotd", VF_VENDOR | VF_OPTCOMMON);
97         }
98
99         virtual void OnOper(User* user, const std::string &opertype)
100         {
101                 if (onoper && IS_LOCAL(user))
102                         cmd.ShowOperMOTD(user);
103         }
104
105         virtual void OnRehash(User* user)
106         {
107                 LoadOperMOTD();
108         }
109 };
110
111 MODULE_INIT(ModuleOpermotd)