]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Merge pull request #182 from attilamolnar/insp20+gnutlsfix
[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 static FileReader* opermotd;
28
29 CmdResult ShowOperMOTD(User* user)
30 {
31         if(!opermotd->FileSize())
32         {
33                 user->WriteServ(std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
34                 return CMD_FAILURE;
35         }
36
37         user->WriteServ(std::string("375 ") + user->nick + std::string(" :- IRC Operators Message of the Day"));
38
39         for(int i=0; i != opermotd->FileSize(); i++)
40         {
41                 user->WriteServ(std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i));
42         }
43
44         user->WriteServ(std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
45
46         /* don't route me */
47         return CMD_SUCCESS;
48 }
49
50 /** Handle /OPERMOTD
51  */
52 class CommandOpermotd : public Command
53 {
54  public:
55         CommandOpermotd(Module* Creator) : Command(Creator,"OPERMOTD", 0)
56         {
57                 flags_needed = 'o'; syntax = "[<servername>]";
58         }
59
60         CmdResult Handle (const std::vector<std::string>& parameters, User* user)
61         {
62                 return ShowOperMOTD(user);
63         }
64 };
65
66
67 class ModuleOpermotd : public Module
68 {
69         CommandOpermotd cmd;
70         bool onoper;
71  public:
72
73         void LoadOperMOTD()
74         {
75                 ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd");
76                 opermotd->LoadFile(conf->getString("file","opermotd"));
77                 onoper = conf->getBool("onoper", true);
78         }
79
80         ModuleOpermotd()
81                 : cmd(this)
82         {
83                 opermotd = NULL;
84                 ServerInstance->AddCommand(&cmd);
85                 opermotd = new FileReader;
86                 LoadOperMOTD();
87                 Implementation eventlist[] = { I_OnRehash, I_OnOper };
88                 ServerInstance->Modules->Attach(eventlist, this, 2);
89         }
90
91         virtual ~ModuleOpermotd()
92         {
93                 delete opermotd;
94                 opermotd = NULL;
95         }
96
97         virtual Version GetVersion()
98         {
99                 return Version("Shows a message to opers after oper-up, adds /opermotd", VF_VENDOR);
100         }
101
102         virtual void OnOper(User* user, const std::string &opertype)
103         {
104                 if (onoper)
105                         ShowOperMOTD(user);
106         }
107
108         virtual void OnRehash(User* user)
109         {
110                 LoadOperMOTD();
111         }
112 };
113
114 MODULE_INIT(ModuleOpermotd)