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