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