]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Now with added ANGRY MONKEYS.
[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 static FileReader* opermotd;
14 static 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                 syntax = "[<servername>]";
53         }
54
55         void Handle (const char** parameters, int pcnt, userrec* user)
56         {
57                 ShowOperMOTD(user);
58         }
59 };
60
61 class ModuleOpermotd : public Module
62 {
63                 cmd_opermotd* mycommand;
64         public:
65                 ModuleOpermotd(Server* Me)
66                         : Module::Module(Me)
67                 {
68                         Srv = Me;
69                         mycommand = new cmd_opermotd();
70                         Srv->AddCommand(mycommand);
71                         opermotd = new FileReader();
72                         LoadOperMOTD();
73                 }
74
75                 virtual ~ModuleOpermotd()
76                 {
77                 }
78
79                 virtual Version GetVersion()
80                 {
81                         return Version(1,0,0,1,VF_VENDOR);
82                 }
83
84                 void Implements(char* List)
85                 {
86                         List[I_OnRehash] = List[I_OnOper] = 1;
87                 }
88
89                 virtual void OnOper(userrec* user, const std::string &opertype)
90                 {
91                         ShowOperMOTD(user);
92                 }
93
94                 virtual void OnRehash(const std::string &parameter)
95                 {
96                         LoadOperMOTD();
97                 }
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(Server* Me)
113                 {
114                         return new ModuleOpermotd(Me);
115                 }
116
117 };
118
119 extern "C" void* init_module(void)
120 {
121         return new ModuleOpermotdFactory;
122 }