]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
447468cafa9196a107e570a4d01a583abf071135
[user/henk/code/inspircd.git] / src / modules / m_opermotd.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <stdio.h>
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 #include "inspircd.h"
20
21 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
22
23 static FileReader* opermotd;
24
25 CmdResult ShowOperMOTD(userrec* user)
26 {
27         if(!opermotd->FileSize())
28         {
29                 user->WriteServ(std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
30                 return CMD_FAILURE;
31         }
32
33         user->WriteServ(std::string("375 ") + user->nick + std::string(" :- IRC Operators Message of the Day"));
34
35         for(int i=0; i != opermotd->FileSize(); i++)
36         {
37                 user->WriteServ(std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i));
38         }
39
40         user->WriteServ(std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
41
42         /* don't route me */
43         return CMD_LOCALONLY;
44 }
45
46 /** Handle /OPERMOTD
47  */
48 class cmd_opermotd : public command_t
49 {
50  public:
51         cmd_opermotd (InspIRCd* Instance) : command_t(Instance,"OPERMOTD", 'o', 0)
52         {
53                 this->source = "m_opermotd.so";
54                 syntax = "[<servername>]";
55         }
56
57         CmdResult Handle (const char** parameters, int pcnt, userrec* user)
58         {
59                 return ShowOperMOTD(user);
60         }
61 };
62
63
64 class ModuleOpermotd : public Module
65 {
66         cmd_opermotd* mycommand;
67  public:
68
69         void LoadOperMOTD()
70         {
71                 ConfigReader* conf = new ConfigReader(ServerInstance);
72                 std::string filename;
73                 filename = conf->ReadValue("opermotd","file",0);
74                 if (opermotd)
75                 {
76                         delete opermotd;
77                         opermotd = NULL;
78                 }
79                 opermotd = new FileReader(ServerInstance, filename);
80                 DELETE(conf);
81         }
82         
83         ModuleOpermotd(InspIRCd* Me)
84                 : Module::Module(Me)
85         {
86                 opermotd = NULL;
87                 mycommand = new cmd_opermotd(ServerInstance);
88                 ServerInstance->AddCommand(mycommand);
89                 opermotd = new FileReader(ServerInstance);
90                 LoadOperMOTD();
91         }
92
93         virtual ~ModuleOpermotd()
94         {
95         }
96
97         virtual Version GetVersion()
98         {
99                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
100         }
101
102         void Implements(char* List)
103         {
104                 List[I_OnRehash] = List[I_OnOper] = 1;
105         }
106
107         virtual void OnOper(userrec* user, const std::string &opertype)
108         {
109                 ShowOperMOTD(user);
110         }
111
112         virtual void OnRehash(userrec* user, const std::string &parameter)
113         {
114                 LoadOperMOTD();
115         }
116 };
117
118 class ModuleOpermotdFactory : public ModuleFactory
119 {
120  public:
121         ModuleOpermotdFactory()
122         {
123         }
124
125         ~ModuleOpermotdFactory()
126         {
127         }
128
129         virtual Module* CreateModule(InspIRCd* Me)
130         {
131                 return new ModuleOpermotd(Me);
132         }
133 };
134
135 extern "C" void* init_module(void)
136 {
137         return new ModuleOpermotdFactory;
138 }