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