]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
7b4584db9c52fdd0a0c05553f49a875809f94017
[user/henk/code/inspircd.git] / src / modules / m_opermotd.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
17
18 static FileReader* opermotd;
19
20 CmdResult ShowOperMOTD(User* user)
21 {
22         if(!opermotd->FileSize())
23         {
24                 user->WriteServ(std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
25                 return CMD_FAILURE;
26         }
27
28         user->WriteServ(std::string("375 ") + user->nick + std::string(" :- IRC Operators Message of the Day"));
29
30         for(int i=0; i != opermotd->FileSize(); i++)
31         {
32                 user->WriteServ(std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i));
33         }
34
35         user->WriteServ(std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
36
37         /* don't route me */
38         return CMD_SUCCESS;
39 }
40
41 /** Handle /OPERMOTD
42  */
43 class CommandOpermotd : public Command
44 {
45  public:
46         CommandOpermotd(Module* Creator) : Command(Creator,"OPERMOTD", 0)
47         {
48                 flags_needed = 'o'; syntax = "[<servername>]";
49         }
50
51         CmdResult Handle (const std::vector<std::string>& parameters, User* user)
52         {
53                 return ShowOperMOTD(user);
54         }
55 };
56
57
58 class ModuleOpermotd : public Module
59 {
60         CommandOpermotd cmd;
61         bool onoper;
62  public:
63
64         void LoadOperMOTD()
65         {
66                 ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd");
67                 opermotd->LoadFile(conf->getString("file","opermotd"));
68                 onoper = conf->getBool("onoper", true);
69         }
70
71         ModuleOpermotd()
72                 : cmd(this)
73         {
74                 opermotd = NULL;
75                 ServerInstance->AddCommand(&cmd);
76                 opermotd = new FileReader;
77                 LoadOperMOTD();
78                 Implementation eventlist[] = { I_OnRehash, I_OnOper };
79                 ServerInstance->Modules->Attach(eventlist, this, 2);
80         }
81
82         virtual ~ModuleOpermotd()
83         {
84                 delete opermotd;
85                 opermotd = NULL;
86         }
87
88         virtual Version GetVersion()
89         {
90                 return Version("Shows a message to opers after oper-up, adds /opermotd", VF_VENDOR);
91         }
92
93         virtual void OnOper(User* user, const std::string &opertype)
94         {
95                 if (onoper)
96                         ShowOperMOTD(user);
97         }
98
99         virtual void OnRehash(User* user)
100         {
101                 LoadOperMOTD();
102         }
103 };
104
105 MODULE_INIT(ModuleOpermotd)