]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
Remove On005Numeric event from a ton of modules which no longer need it (as CHANMODES...
[user/henk/code/inspircd.git] / src / modules / m_sslmodes.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 #include "users.h"
18 #include "channels.h"
19 #include "modules.h"
20 #include "inspircd.h"
21
22 /* $ModDesc: Provides support for unreal-style channel mode +z */
23
24 static char* dummy;
25
26 class SSLMode : public ModeHandler
27 {
28  public:
29         SSLMode(InspIRCd* Instance) : ModeHandler(Instance, 'z', 0, 0, false, MODETYPE_CHANNEL, false) { }
30
31         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
32         {
33                 if (adding)
34                 {
35                         if (!channel->IsModeSet('z'))
36                         {
37                                 if (IS_LOCAL(source))
38                                 {
39                                         CUList* userlist = channel->GetUsers();
40                                         for(CUList::iterator i = userlist->begin(); i != userlist->end(); i++)
41                                         {
42                                                 if(!i->second->GetExt("ssl", dummy))
43                                                 {
44                                                         source->WriteServ("490 %s %s :all members of the channel must be connected via SSL", source->nick, channel->name);
45                                                         return MODEACTION_DENY;
46                                                 }
47                                         }
48                                 }
49                                 channel->SetMode('z',true);
50                                 return MODEACTION_ALLOW;
51                         }
52                         else
53                         {
54                                 return MODEACTION_DENY;
55                         }
56                 }
57                 else
58                 {
59                         if (channel->IsModeSet('z'))
60                         {
61                                 channel->SetMode('z',false);
62                                 return MODEACTION_ALLOW;
63                         }
64
65                         return MODEACTION_DENY;
66                 }
67         }
68 };
69
70 class ModuleSSLModes : public Module
71 {
72         
73         SSLMode* sslm;
74         
75  public:
76         ModuleSSLModes(InspIRCd* Me)
77                 : Module::Module(Me)
78         {
79                 
80
81                 sslm = new SSLMode(ServerInstance);
82                 ServerInstance->AddMode(sslm, 'z');
83         }
84
85         void Implements(char* List)
86         {
87                 List[I_OnUserPreJoin] = 1;
88         }
89
90         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
91         {
92                 if(chan && chan->IsModeSet('z'))
93                 {
94                         if(user->GetExt("ssl", dummy))
95                         {
96                                 // Let them in
97                                 return 0;
98                         }
99                         else
100                         {
101                                 // Deny
102                                 user->WriteServ( "489 %s %s :Cannot join channel (+z)", user->nick, cname);
103                                 return 1;
104                         }
105                 }
106                 
107                 return 0;
108         }
109
110         virtual ~ModuleSSLModes()
111         {
112                 DELETE(sslm);
113         }
114         
115         virtual Version GetVersion()
116         {
117                 return Version(1, 0, 0, 0, VF_STATIC | VF_VENDOR);
118         }
119 };
120
121
122 class ModuleSSLModesFactory : public ModuleFactory
123 {
124  public:
125         ModuleSSLModesFactory()
126         {
127         }
128         
129         ~ModuleSSLModesFactory()
130         {
131         }
132         
133         virtual Module* CreateModule(InspIRCd* Me)
134         {
135                 return new ModuleSSLModes(Me);
136         }
137         
138 };
139
140
141 extern "C" void * init_module( void )
142 {
143         return new ModuleSSLModesFactory;
144 }