]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Added a parameter to OnRehash for the rehash parameter
[user/henk/code/inspircd.git] / src / modules / m_opermotd.cpp
1 // opermotd module by typobox43
2
3 using namespace std;
4
5 #include <stdio.h>
6 #include "users.h"
7 #include "channels.h"
8 #include "modules.h"
9 #include "helperfuncs.h"
10
11 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
12
13 FileReader* opermotd;
14 Server* Srv;
15
16 void do_opermotd(char** parameters, int pcnt, userrec* user);
17
18 void LoadOperMOTD()
19 {
20
21         ConfigReader* conf = new ConfigReader;
22         std::string filename;
23
24         filename = conf->ReadValue("opermotd","file",0);
25
26         opermotd->LoadFile(filename);
27         
28 }
29
30 void ShowOperMOTD(userrec* user)
31 {
32         if(!opermotd->FileSize())
33         {
34                 Srv->SendServ(user->fd,std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
35                 return;
36         }
37
38         Srv->SendServ(user->fd,std::string("375 ") + user->nick + std::string(" :- IRC Operators Message of the Day"));
39
40         for(int i=0; i != opermotd->FileSize(); i++)
41         {
42                 Srv->SendServ(user->fd,std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i));
43         }
44
45         Srv->SendServ(user->fd,std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
46
47 }
48
49 void do_opermotd(char** parameters, int pcnt, userrec* user)
50 {
51         ShowOperMOTD(user);
52 }
53
54 class ModuleOpermotd : public Module
55 {
56         public:
57                 ModuleOpermotd()
58                 {
59                         Srv = new Server;
60                         
61                         Srv->AddCommand("OPERMOTD",do_opermotd,'o',0,"m_opermotd.so");
62                         opermotd = new FileReader();
63                         LoadOperMOTD();
64                 }
65
66                 virtual ~ModuleOpermotd()
67                 {
68                         delete Srv;
69                 }
70
71                 virtual Version GetVersion()
72                 {
73                         return Version(1,0,0,1,VF_VENDOR);
74                 }
75
76                 virtual void OnOper(userrec* user, std::string opertype)
77                 {
78                         ShowOperMOTD(user);
79                 }
80
81                 virtual void OnRehash(std::string parameter)
82                 {
83                         LoadOperMOTD();
84                 }
85
86 };
87
88 class ModuleOpermotdFactory : public ModuleFactory
89 {
90         public:
91                 ModuleOpermotdFactory()
92                 {
93                 }
94
95                 ~ModuleOpermotdFactory()
96                 {
97                 }
98
99                 virtual Module* CreateModule()
100                 {
101                         return new ModuleOpermotd;
102                 }
103
104 };
105
106 extern "C" void* init_module(void)
107 {
108         return new ModuleOpermotdFactory;
109 }