]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Fixed compile problems... Move along please, nothing to see here..
[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 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                 virtual void OnOper(userrec* user, std::string opertype)
84                 {
85                         ShowOperMOTD(user);
86                 }
87
88                 virtual void OnRehash(std::string parameter)
89                 {
90                         LoadOperMOTD();
91                 }
92
93 };
94
95 class ModuleOpermotdFactory : public ModuleFactory
96 {
97         public:
98                 ModuleOpermotdFactory()
99                 {
100                 }
101
102                 ~ModuleOpermotdFactory()
103                 {
104                 }
105
106                 virtual Module* CreateModule(Server* Me)
107                 {
108                         return new ModuleOpermotd(Me);
109                 }
110
111 };
112
113 extern "C" void* init_module(void)
114 {
115         return new ModuleOpermotdFactory;
116 }