]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
a2a3c0312d8428849900186c376597f2c5f7e6f7
[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         ConfigReader* conf = new ConfigReader;
21         std::string filename;
22
23         filename = conf->ReadValue("opermotd","file",0);
24
25         opermotd->LoadFile(filename);
26         delete conf;
27 }
28
29 void ShowOperMOTD(userrec* user)
30 {
31         if(!opermotd->FileSize())
32         {
33                 Srv->SendServ(user->fd,std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
34                 return;
35         }
36
37         Srv->SendServ(user->fd,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                 Srv->SendServ(user->fd,std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i));
42         }
43
44         Srv->SendServ(user->fd,std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
45
46 }
47
48 void do_opermotd(char** parameters, int pcnt, userrec* user)
49 {
50         ShowOperMOTD(user);
51 }
52
53 class ModuleOpermotd : public Module
54 {
55         public:
56                 ModuleOpermotd(Server* Me)
57                         : Module::Module(Me)
58                 {
59                         Srv = Me;
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                 }
69
70                 virtual Version GetVersion()
71                 {
72                         return Version(1,0,0,1,VF_VENDOR);
73                 }
74
75                 virtual void OnOper(userrec* user, std::string opertype)
76                 {
77                         ShowOperMOTD(user);
78                 }
79
80                 virtual void OnRehash(std::string parameter)
81                 {
82                         LoadOperMOTD();
83                 }
84
85 };
86
87 class ModuleOpermotdFactory : public ModuleFactory
88 {
89         public:
90                 ModuleOpermotdFactory()
91                 {
92                 }
93
94                 ~ModuleOpermotdFactory()
95                 {
96                 }
97
98                 virtual Module* CreateModule(Server* Me)
99                 {
100                         return new ModuleOpermotd(Me);
101                 }
102
103 };
104
105 extern "C" void* init_module(void)
106 {
107         return new ModuleOpermotdFactory;
108 }