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