]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
b988dd00e2d8a7cad09d5bc316acae2b8a623b2e
[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 #include "inspircd.h"
11
12 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
13
14 static FileReader* opermotd;
15
16
17 void LoadOperMOTD()
18 {
19         ConfigReader* conf = new ConfigReader;
20         std::string filename;
21
22         filename = conf->ReadValue("opermotd","file",0);
23
24         opermotd->LoadFile(filename);
25         DELETE(conf);
26 }
27
28 void ShowOperMOTD(userrec* user)
29 {
30         if(!opermotd->FileSize())
31         {
32                 user->WriteServ(std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
33                 return;
34         }
35
36         user->WriteServ(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                 user->WriteServ(std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i));
41         }
42
43         user->WriteServ(std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
44
45 }
46
47 class cmd_opermotd : public command_t
48 {
49  public:
50  cmd_opermotd (InspIRCd* Instance) : command_t(Instance,"OPERMOTD", 'o', 0)
51         {
52                 this->source = "m_opermotd.so";
53                 syntax = "[<servername>]";
54         }
55
56         void Handle (const char** parameters, int pcnt, userrec* user)
57         {
58                 ShowOperMOTD(user);
59         }
60 };
61
62 class ModuleOpermotd : public Module
63 {
64                 cmd_opermotd* mycommand;
65         public:
66                 ModuleOpermotd(InspIRCd* Me)
67                         : Module::Module(Me)
68                 {
69                         
70                         mycommand = new cmd_opermotd(ServerInstance);
71                         ServerInstance->AddCommand(mycommand);
72                         opermotd = new FileReader();
73                         LoadOperMOTD();
74                 }
75
76                 virtual ~ModuleOpermotd()
77                 {
78                 }
79
80                 virtual Version GetVersion()
81                 {
82                         return Version(1,0,0,1,VF_VENDOR);
83                 }
84
85                 void Implements(char* List)
86                 {
87                         List[I_OnRehash] = List[I_OnOper] = 1;
88                 }
89
90                 virtual void OnOper(userrec* user, const std::string &opertype)
91                 {
92                         ShowOperMOTD(user);
93                 }
94
95                 virtual void OnRehash(const std::string &parameter)
96                 {
97                         LoadOperMOTD();
98                 }
99
100 };
101
102 class ModuleOpermotdFactory : public ModuleFactory
103 {
104         public:
105                 ModuleOpermotdFactory()
106                 {
107                 }
108
109                 ~ModuleOpermotdFactory()
110                 {
111                 }
112
113                 virtual Module* CreateModule(InspIRCd* Me)
114                 {
115                         return new ModuleOpermotd(Me);
116                 }
117
118 };
119
120 extern "C" void* init_module(void)
121 {
122         return new ModuleOpermotdFactory;
123 }