]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
Removed a pointless check in ./configure --clean that made it only work with one...
[user/henk/code/inspircd.git] / src / modules / m_sslmodes.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 #include "inspircd.h"
18
19 /* $ModDesc: Provides support for unreal-style channel mode +z */
20
21 static char* dummy;
22
23 /** Handle channel mode +z
24  */
25 class SSLMode : public ModeHandler
26 {
27  public:
28         SSLMode(InspIRCd* Instance) : ModeHandler(Instance, 'z', 0, 0, false, MODETYPE_CHANNEL, false) { }
29
30         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
31         {
32                 if (adding)
33                 {
34                         if (!channel->IsModeSet('z'))
35                         {
36                                 if (IS_LOCAL(source))
37                                 {
38                                         CUList* userlist = channel->GetUsers();
39                                         for(CUList::iterator i = userlist->begin(); i != userlist->end(); i++)
40                                         {
41                                                 if(!i->second->GetExt("ssl", dummy))
42                                                 {
43                                                         source->WriteServ("490 %s %s :all members of the channel must be connected via SSL", source->nick, channel->name);
44                                                         return MODEACTION_DENY;
45                                                 }
46                                         }
47                                 }
48                                 channel->SetMode('z',true);
49                                 return MODEACTION_ALLOW;
50                         }
51                         else
52                         {
53                                 return MODEACTION_DENY;
54                         }
55                 }
56                 else
57                 {
58                         if (channel->IsModeSet('z'))
59                         {
60                                 channel->SetMode('z',false);
61                                 return MODEACTION_ALLOW;
62                         }
63
64                         return MODEACTION_DENY;
65                 }
66         }
67 };
68
69 class ModuleSSLModes : public Module
70 {
71         
72         SSLMode* sslm;
73         
74  public:
75         ModuleSSLModes(InspIRCd* Me)
76                 : Module::Module(Me)
77         {
78                 
79
80                 sslm = new SSLMode(ServerInstance);
81                 ServerInstance->AddMode(sslm, 'z');
82         }
83
84         void Implements(char* List)
85         {
86                 List[I_OnUserPreJoin] = 1;
87         }
88
89         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
90         {
91                 if(chan && chan->IsModeSet('z'))
92                 {
93                         if(user->GetExt("ssl", dummy))
94                         {
95                                 // Let them in
96                                 return 0;
97                         }
98                         else
99                         {
100                                 // Deny
101                                 user->WriteServ( "489 %s %s :Cannot join channel (+z)", user->nick, cname);
102                                 return 1;
103                         }
104                 }
105                 
106                 return 0;
107         }
108
109         virtual ~ModuleSSLModes()
110         {
111                 ServerInstance->Modes->DelMode(sslm);
112                 DELETE(sslm);
113         }
114         
115         virtual Version GetVersion()
116         {
117                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
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 }