]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Server* Srv marked static or moved to private member of module class in all modules...
[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 static FileReader* opermotd;
14 static Server* Srv;
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         delete conf;
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         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         Srv->SendServ(user->fd,std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
43
44 }
45
46 class cmd_opermotd : public command_t
47 {
48  public:
49         cmd_opermotd () : command_t("OPERMOTD", 'o', 0)
50         {
51                 this->source = "m_opermotd.so";
52         }
53
54         void Handle (char** parameters, int pcnt, userrec* user)
55         {
56                 ShowOperMOTD(user);
57         }
58 };
59
60 class ModuleOpermotd : public Module
61 {
62                 cmd_opermotd* mycommand;
63         public:
64                 ModuleOpermotd(Server* Me)
65                         : Module::Module(Me)
66                 {
67                         Srv = Me;
68                         mycommand = new cmd_opermotd();
69                         Srv->AddCommand(mycommand);
70                         opermotd = new FileReader();
71                         LoadOperMOTD();
72                 }
73
74                 virtual ~ModuleOpermotd()
75                 {
76                 }
77
78                 virtual Version GetVersion()
79                 {
80                         return Version(1,0,0,1,VF_VENDOR);
81                 }
82
83                 void Implements(char* List)
84                 {
85                         List[I_OnRehash] = List[I_OnOper] = 1;
86                 }
87
88                 virtual void OnOper(userrec* user, std::string opertype)
89                 {
90                         ShowOperMOTD(user);
91                 }
92
93                 virtual void OnRehash(std::string parameter)
94                 {
95                         LoadOperMOTD();
96                 }
97
98 };
99
100 class ModuleOpermotdFactory : public ModuleFactory
101 {
102         public:
103                 ModuleOpermotdFactory()
104                 {
105                 }
106
107                 ~ModuleOpermotdFactory()
108                 {
109                 }
110
111                 virtual Module* CreateModule(Server* Me)
112                 {
113                         return new ModuleOpermotd(Me);
114                 }
115
116 };
117
118 extern "C" void* init_module(void)
119 {
120         return new ModuleOpermotdFactory;
121 }