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