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