]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermotd.cpp
Removed superfluous semicolons
[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 "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
20
21 static FileReader* opermotd;
22
23 CmdResult ShowOperMOTD(userrec* user)
24 {
25         if(!opermotd->FileSize())
26         {
27                 user->WriteServ(std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
28                 return CMD_FAILURE;
29         }
30
31         user->WriteServ(std::string("375 ") + user->nick + std::string(" :- IRC Operators Message of the Day"));
32
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
38         user->WriteServ(std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
39
40         /* don't route me */
41         return CMD_LOCALONLY;
42 }
43
44 /** Handle /OPERMOTD
45  */
46 class cmd_opermotd : public command_t
47 {
48  public:
49         cmd_opermotd (InspIRCd* Instance) : command_t(Instance,"OPERMOTD", 'o', 0)
50         {
51                 this->source = "m_opermotd.so";
52                 syntax = "[<servername>]";
53         }
54
55         CmdResult Handle (const char** parameters, int pcnt, userrec* user)
56         {
57                 return ShowOperMOTD(user);
58         }
59 };
60
61
62 class ModuleOpermotd : public Module
63 {
64         cmd_opermotd* mycommand;
65  public:
66
67         void LoadOperMOTD()
68         {
69                 ConfigReader* conf = new ConfigReader(ServerInstance);
70                 std::string filename;
71                 filename = conf->ReadValue("opermotd","file",0);
72                 if (opermotd)
73                 {
74                         delete opermotd;
75                         opermotd = NULL;
76                 }
77                 opermotd = new FileReader(ServerInstance, filename);
78                 DELETE(conf);
79         }
80         
81         ModuleOpermotd(InspIRCd* Me)
82                 : Module(Me)
83         {
84                 opermotd = NULL;
85                 mycommand = new cmd_opermotd(ServerInstance);
86                 ServerInstance->AddCommand(mycommand);
87                 opermotd = new FileReader(ServerInstance);
88                 LoadOperMOTD();
89         }
90
91         virtual ~ModuleOpermotd()
92         {
93         }
94
95         virtual Version GetVersion()
96         {
97                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
98         }
99
100         void Implements(char* List)
101         {
102                 List[I_OnRehash] = List[I_OnOper] = 1;
103         }
104
105         virtual void OnOper(userrec* user, const std::string &opertype)
106         {
107                 ShowOperMOTD(user);
108         }
109
110         virtual void OnRehash(userrec* user, const std::string &parameter)
111         {
112                 LoadOperMOTD();
113         }
114 };
115
116 MODULE_INIT(ModuleOpermotd)