]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
Note: FOR THE MOMENT, this is BROKEN. It wont run right until im done.
[user/henk/code/inspircd.git] / src / modules / m_sslmodes.cpp
1 #include "users.h"
2 #include "channels.h"
3 #include "modules.h"
4 #include "helperfuncs.h"
5 #include "inspircd.h"
6
7 /* $ModDesc: Provides support for unreal-style channel mode +z */
8
9 static char* dummy;
10
11 extern InspIRCd* ServerInstance;
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         Server *Srv;
60         SSLMode* sslm;
61         
62  public:
63         ModuleSSLModes(InspIRCd* Me)
64                 : Module::Module(Me)
65         {
66                 
67
68                 sslm = new SSLMode(ServerInstance);
69                 Srv->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                 ServerInstance->ModeGrok->InsertMode(output, "z", 4);
80         }
81         
82         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
83         {
84                 if(chan && chan->IsModeSet('z'))
85                 {
86                         if(user->GetExt("ssl", dummy))
87                         {
88                                 // Let them in
89                                 return 0;
90                         }
91                         else
92                         {
93                                 // Deny
94                                 user->WriteServ( "489 %s %s :Cannot join channel (+z)", user->nick, cname);
95                                 return 1;
96                         }
97                 }
98                 
99                 return 0;
100         }
101
102         virtual ~ModuleSSLModes()
103         {
104                 DELETE(sslm);
105         }
106         
107         virtual Version GetVersion()
108         {
109                 return Version(1, 0, 0, 0, VF_STATIC | VF_VENDOR);
110         }
111 };
112
113
114 class ModuleSSLModesFactory : public ModuleFactory
115 {
116  public:
117         ModuleSSLModesFactory()
118         {
119         }
120         
121         ~ModuleSSLModesFactory()
122         {
123         }
124         
125         virtual Module* CreateModule(InspIRCd* Me)
126         {
127                 return new ModuleSSLModes(Me);
128         }
129         
130 };
131
132
133 extern "C" void * init_module( void )
134 {
135         return new ModuleSSLModesFactory;
136 }