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