]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Auto loading of commands as shared objects via dlsym (very lightweight interface...
[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
10 #include "inspircd.h"
11
12 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
13
14 static FileReader* opermotd;
15
16 void ShowOperMOTD(userrec* user)
17 {
18         if(!opermotd->FileSize())
19         {
20                 user->WriteServ(std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
21                 return;
22         }
23         user->WriteServ(std::string("375 ") + user->nick + std::string(" :- IRC Operators Message of the Day"));
24         for(int i=0; i != opermotd->FileSize(); i++)
25         {
26                 user->WriteServ(std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i));
27         }
28         user->WriteServ(std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
29 }
30
31 class cmd_opermotd : public command_t
32 {
33  public:
34         cmd_opermotd (InspIRCd* Instance) : command_t(Instance,"OPERMOTD", 'o', 0)
35         {
36                 this->source = "m_opermotd.so";
37                 syntax = "[<servername>]";
38         }
39
40         void Handle (const char** parameters, int pcnt, userrec* user)
41         {
42                 ShowOperMOTD(user);
43         }
44 };
45
46
47 class ModuleOpermotd : public Module
48 {
49         cmd_opermotd* mycommand;
50  public:
51
52         void LoadOperMOTD()
53         {
54                 ConfigReader* conf = new ConfigReader(ServerInstance);
55                 std::string filename;
56                 filename = conf->ReadValue("opermotd","file",0);
57                 if (opermotd)
58                 {
59                         delete opermotd;
60                         opermotd = NULL;
61                 }
62                 opermotd = new FileReader(ServerInstance, filename);
63                 DELETE(conf);
64         }
65         
66         ModuleOpermotd(InspIRCd* Me)
67                 : Module::Module(Me)
68         {
69                 opermotd = NULL;
70                 mycommand = new cmd_opermotd(ServerInstance);
71                 ServerInstance->AddCommand(mycommand);
72                 opermotd = new FileReader(ServerInstance);
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 class ModuleOpermotdFactory : public ModuleFactory
102 {
103  public:
104         ModuleOpermotdFactory()
105         {
106         }
107
108         ~ModuleOpermotdFactory()
109         {
110         }
111
112         virtual Module* CreateModule(InspIRCd* Me)
113         {
114                 return new ModuleOpermotd(Me);
115         }
116 };
117
118 extern "C" void* init_module(void)
119 {
120         return new ModuleOpermotdFactory;
121 }