]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
62c59aa9b522d64108e883a07cd2a0c95ce03023
[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 CmdResult 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 CMD_FAILURE;
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         return CMD_SUCCESS;
31 }
32
33 /** Handle /OPERMOTD
34  */
35 class cmd_opermotd : public command_t
36 {
37  public:
38         cmd_opermotd (InspIRCd* Instance) : command_t(Instance,"OPERMOTD", 'o', 0)
39         {
40                 this->source = "m_opermotd.so";
41                 syntax = "[<servername>]";
42         }
43
44         CmdResult Handle (const char** parameters, int pcnt, userrec* user)
45         {
46                 return ShowOperMOTD(user);
47         }
48 };
49
50
51 class ModuleOpermotd : public Module
52 {
53         cmd_opermotd* mycommand;
54  public:
55
56         void LoadOperMOTD()
57         {
58                 ConfigReader* conf = new ConfigReader(ServerInstance);
59                 std::string filename;
60                 filename = conf->ReadValue("opermotd","file",0);
61                 if (opermotd)
62                 {
63                         delete opermotd;
64                         opermotd = NULL;
65                 }
66                 opermotd = new FileReader(ServerInstance, filename);
67                 DELETE(conf);
68         }
69         
70         ModuleOpermotd(InspIRCd* Me)
71                 : Module::Module(Me)
72         {
73                 opermotd = NULL;
74                 mycommand = new cmd_opermotd(ServerInstance);
75                 ServerInstance->AddCommand(mycommand);
76                 opermotd = new FileReader(ServerInstance);
77                 LoadOperMOTD();
78         }
79
80         virtual ~ModuleOpermotd()
81         {
82         }
83
84         virtual Version GetVersion()
85         {
86                 return Version(1,0,0,1,VF_VENDOR,API_VERSION);
87         }
88
89         void Implements(char* List)
90         {
91                 List[I_OnRehash] = List[I_OnOper] = 1;
92         }
93
94         virtual void OnOper(userrec* user, const std::string &opertype)
95         {
96                 ShowOperMOTD(user);
97         }
98
99         virtual void OnRehash(const std::string &parameter)
100         {
101                 LoadOperMOTD();
102         }
103 };
104
105 class ModuleOpermotdFactory : public ModuleFactory
106 {
107  public:
108         ModuleOpermotdFactory()
109         {
110         }
111
112         ~ModuleOpermotdFactory()
113         {
114         }
115
116         virtual Module* CreateModule(InspIRCd* Me)
117         {
118                 return new ModuleOpermotd(Me);
119         }
120 };
121
122 extern "C" void* init_module(void)
123 {
124         return new ModuleOpermotdFactory;
125 }