]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Remove global namespacing, makes modules compile FASTAH. Also massive update on heade...
[user/henk/code/inspircd.git] / src / modules / m_opermotd.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <stdio.h>
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 #include "inspircd.h"
20
21 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
22
23 static FileReader* opermotd;
24
25 CmdResult ShowOperMOTD(userrec* user)
26 {
27         if(!opermotd->FileSize())
28         {
29                 user->WriteServ(std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
30                 return CMD_FAILURE;
31         }
32         user->WriteServ(std::string("375 ") + user->nick + std::string(" :- IRC Operators Message of the Day"));
33         for(int i=0; i != opermotd->FileSize(); i++)
34         {
35                 user->WriteServ(std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i));
36         }
37         user->WriteServ(std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
38
39         return CMD_SUCCESS;
40 }
41
42 /** Handle /OPERMOTD
43  */
44 class cmd_opermotd : public command_t
45 {
46  public:
47         cmd_opermotd (InspIRCd* Instance) : command_t(Instance,"OPERMOTD", 'o', 0)
48         {
49                 this->source = "m_opermotd.so";
50                 syntax = "[<servername>]";
51         }
52
53         CmdResult Handle (const char** parameters, int pcnt, userrec* user)
54         {
55                 return ShowOperMOTD(user);
56         }
57 };
58
59
60 class ModuleOpermotd : public Module
61 {
62         cmd_opermotd* mycommand;
63  public:
64
65         void LoadOperMOTD()
66         {
67                 ConfigReader* conf = new ConfigReader(ServerInstance);
68                 std::string filename;
69                 filename = conf->ReadValue("opermotd","file",0);
70                 if (opermotd)
71                 {
72                         delete opermotd;
73                         opermotd = NULL;
74                 }
75                 opermotd = new FileReader(ServerInstance, filename);
76                 DELETE(conf);
77         }
78         
79         ModuleOpermotd(InspIRCd* Me)
80                 : Module::Module(Me)
81         {
82                 opermotd = NULL;
83                 mycommand = new cmd_opermotd(ServerInstance);
84                 ServerInstance->AddCommand(mycommand);
85                 opermotd = new FileReader(ServerInstance);
86                 LoadOperMOTD();
87         }
88
89         virtual ~ModuleOpermotd()
90         {
91         }
92
93         virtual Version GetVersion()
94         {
95                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
96         }
97
98         void Implements(char* List)
99         {
100                 List[I_OnRehash] = List[I_OnOper] = 1;
101         }
102
103         virtual void OnOper(userrec* user, const std::string &opertype)
104         {
105                 ShowOperMOTD(user);
106         }
107
108         virtual void OnRehash(const std::string &parameter)
109         {
110                 LoadOperMOTD();
111         }
112 };
113
114 class ModuleOpermotdFactory : public ModuleFactory
115 {
116  public:
117         ModuleOpermotdFactory()
118         {
119         }
120
121         ~ModuleOpermotdFactory()
122         {
123         }
124
125         virtual Module* CreateModule(InspIRCd* Me)
126         {
127                 return new ModuleOpermotd(Me);
128         }
129 };
130
131 extern "C" void* init_module(void)
132 {
133         return new ModuleOpermotdFactory;
134 }