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