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