]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
319b58603524d0ddd01b0e8780cd9aac77797867
[user/henk/code/inspircd.git] / src / modules / m_securelist.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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17
18 #include <vector>
19 #include "inspircd.h"
20
21 /* $ModDesc: A module overriding /list, and making it safe - stop those sendq problems. */
22
23 class ModuleSecureList : public Module
24 {
25  private:
26         std::vector<std::string> allowlist;
27         time_t WaitTime;
28  public:
29         ModuleSecureList(InspIRCd* Me) : Module(Me)
30         {
31                 OnRehash(NULL,"");
32         }
33  
34         virtual ~ModuleSecureList()
35         {
36         }
37  
38         virtual Version GetVersion()
39         {
40                 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
41         }
42
43         void OnRehash(userrec* user, const std::string &parameter)
44         {
45                 ConfigReader* MyConf = new ConfigReader(ServerInstance);
46                 allowlist.clear();
47                 for (int i = 0; i < MyConf->Enumerate("securelist"); i++)
48                         allowlist.push_back(MyConf->ReadValue("securelist", "exception", i));
49                 WaitTime = MyConf->ReadInteger("securelist", "waittime", "60", 0, true);
50                 DELETE(MyConf);
51         }
52  
53         void Implements(char* List)
54         {
55                 List[I_OnRehash] = List[I_OnPreCommand] = List[I_On005Numeric] = 1;
56         }
57
58         /*
59          * OnPreCommand()
60          *   Intercept the LIST command.
61          */ 
62         virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
63         {
64                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
65                 if (!validated)
66                         return 0;
67  
68                 if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!IS_OPER(user)))
69                 {
70                         /* Normally wouldnt be allowed here, are they exempt? */
71                         for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
72                                 if (ServerInstance->MatchText(user->MakeHost(), *x))
73                                         return 0;
74
75                         /* Not exempt, BOOK EM DANNO! */
76                         user->WriteServ("NOTICE %s :*** You cannot list within the first %d seconds of connecting. Please try again later.",user->nick, WaitTime);
77                         /* Some crap clients (read: mIRC, various java chat applets) muck up if they don't
78                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
79                          */
80                         user->WriteServ("321 %s Channel :Users Name",user->nick);
81                         user->WriteServ("323 %s :End of channel list.",user->nick);
82                         return 1;
83                 }
84                 return 0;
85         }
86
87         virtual void On005Numeric(std::string &output)
88         {
89                 output.append(" SECURELIST");
90         }
91
92         virtual Priority Prioritize()
93         {
94                 return (Priority)ServerInstance->PriorityBefore("m_safelist.so");
95         }
96
97 };
98  
99  
100  
101 /******************************************************************************************************/
102  
103 class ModuleSecureListFactory : public ModuleFactory
104 {
105  public:
106         ModuleSecureListFactory()
107         {
108         }
109  
110         ~ModuleSecureListFactory()
111         {
112         }
113  
114         virtual Module * CreateModule(InspIRCd* Me)
115         {
116                 return new ModuleSecureList(Me);
117         }
118  
119 };
120  
121 extern "C" DllExport void * init_module( void )
122 {
123         return new ModuleSecureListFactory;
124 }