]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
b97f099b9d39147526a96d6c9d88c8d377472d95
[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                                 return MODEACTION_ALLOW;
29                         }
30                         else
31                         {
32                                 return MODEACTION_DENY;
33                         }
34                 }
35                 else
36                 {
37                         (channel->IsModeSet('z')) ? return MODEACTION_DENY : return MODEACTION_ALLOW;
38                 }
39         }
40 };
41
42 class ModuleSSLModes : public Module
43 {
44         Server *Srv;
45         SSLMode* sslm;
46         
47  public:
48         ModuleSSLModes(Server* Me)
49                 : Module::Module(Me)
50         {
51                 Srv = Me;
52
53                 sslm = new SSLMode();
54                 Srv->AddMode(sslm, 'z');
55         }
56
57         void Implements(char* List)
58         {
59                 List[I_On005Numeric] = List[I_OnUserPreJoin] = 1;
60         }
61
62         virtual void On005Numeric(std::string &output)
63         {
64                 InsertMode(output, "z", 4);
65         }
66         
67         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
68         {
69                 if(chan && chan->IsModeSet('z'))
70                 {
71                         if(user->GetExt("ssl"))
72                         {
73                                 // Let them in
74                                 return 0;
75                         }
76                         else
77                         {
78                                 // Deny
79                                 WriteServ(user->fd, "489 %s %s :Cannot join channel (+z)", user->nick, cname);
80                                 return 1;
81                         }
82                 }
83                 
84                 return 0;
85         }
86
87         virtual ~ModuleSSLModes()
88         {
89                 DELETE(sslm);
90         }
91         
92         virtual Version GetVersion()
93         {
94                 return Version(1, 0, 0, 0, VF_STATIC | VF_VENDOR);
95         }
96 };
97
98
99 class ModuleSSLModesFactory : public ModuleFactory
100 {
101  public:
102         ModuleSSLModesFactory()
103         {
104         }
105         
106         ~ModuleSSLModesFactory()
107         {
108         }
109         
110         virtual Module* CreateModule(Server* Me)
111         {
112                 return new ModuleSSLModes(Me);
113         }
114         
115 };
116
117
118 extern "C" void * init_module( void )
119 {
120         return new ModuleSSLModesFactory;
121 }