]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
First-revision m_securelist.cpp, prevents /LIST in the first minute of connection...
[user/henk/code/inspircd.git] / src / modules / m_securelist.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                     E-mail:
7  *              <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *          the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18  
19 #include "users.h"
20 #include "channels.h"
21 #include "modules.h"
22 #include "helperfuncs.h"
23 #include "message.h"
24 #include <vector>
25  
26 extern time_t TIME;
27
28 /* $ModDesc: A module overriding /list, and making it safe - stop those sendq problems. */
29  
30 class ModuleSecureList : public Module
31 {
32  private:
33          Server *Srv;
34          ListTimer* MyTimer;
35  public:
36         ModuleSecureList(Server* Me) : Module::Module(Me)
37         {
38                 Srv = Me;
39
40                 MyTimer = new ListTimer(1,Srv);
41                 Srv->AddTimer(MyTimer);
42         }
43  
44         virtual ~ModuleSecureList()
45         {
46         }
47  
48         virtual Version GetVersion()
49         {
50                 return Version(1,0,0,0,VF_VENDOR);
51         }
52  
53         void Implements(char* List)
54         {
55                 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, char **parameters, int pcnt, userrec *user, bool validated)
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") && (TIME < (user->signon+60)) && (!*user->oper))
69                 {
70                         WriteServ(user->fd,"NOTICE %s :*** You cannot list within the first minute of connecting. Please try again later.",user->nick);
71                         /* Some crap clients (read: mIRC, various java chat applets) muck up if they don't
72                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
73                          */
74                         WriteServ(u->fd,"321 %s Channel :Users Name",user->nick);
75                         WriteServ(u->fd,"323 %s :End of channel list.",user->nick);
76                         return 1;
77                 }
78                 return 0;
79         }
80
81         virtual void On005Numeric(std::string &output)
82         {
83                 output.append(" SECURELIST");
84         }
85
86         virtual Priority Prioritize()
87         {
88                 return Srv->PriorityBefore("m_safelist.so");
89         }
90
91 };
92  
93  
94  
95 /******************************************************************************************************/
96  
97 class ModuleSecureListFactory : public ModuleFactory
98 {
99  public:
100         ModuleSecureListFactory()
101         {
102         }
103  
104         ~ModuleSecureListFactory()
105         {
106         }
107  
108         virtual Module * CreateModule(Server* Me)
109         {
110                 return new ModuleSecureList(Me);
111         }
112  
113 };
114  
115 extern "C" void * init_module( void )
116 {
117         return new ModuleSecureListFactory;
118 }