]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
Mention that +z means SSL only in the 489, thanks dmb
[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                 if (!ServerInstance->AddMode(sslm, 'z'))
82                         throw ModuleException("Could not add new modes!");
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, std::string &privs)
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; SSL users only (+z)", user->nick, cname);
103                                 return 1;
104                         }
105                 }
106                 
107                 return 0;
108         }
109
110         virtual ~ModuleSSLModes()
111         {
112                 ServerInstance->Modes->DelMode(sslm);
113                 DELETE(sslm);
114         }
115         
116         virtual Version GetVersion()
117         {
118                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
119         }
120 };
121
122
123 class ModuleSSLModesFactory : public ModuleFactory
124 {
125  public:
126         ModuleSSLModesFactory()
127         {
128         }
129         
130         ~ModuleSSLModesFactory()
131         {
132         }
133         
134         virtual Module* CreateModule(InspIRCd* Me)
135         {
136                 return new ModuleSSLModes(Me);
137         }
138         
139 };
140
141
142 extern "C" void * init_module( void )
143 {
144         return new ModuleSSLModesFactory;
145 }