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