]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
Change 974 numeric to 490 to avoid collision with Insp's failed to load module error
[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 ModuleSSLModes : public Module
9 {
10         Server *Srv;
11         
12  public:
13         ModuleSSLModes(Server* Me)
14                 : Module::Module(Me)
15         {
16                 Srv = Me;
17                 Srv->AddExtendedMode('z', MT_CHANNEL, false, 0, 0);
18         }
19
20         void Implements(char* List)
21         {
22                 List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreJoin] = 1;
23         }
24
25         virtual void On005Numeric(std::string &output)
26         {
27                 output.insert(output.find(" ", output.find("CHANMODES=", 0)), "z");
28         }
29         
30         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
31         {
32                 if(chan && chan->IsCustomModeSet('z'))
33                 {
34                         if(user->GetExt("ssl"))
35                         {
36                                 // Let them in
37                                 return 0;
38                         }
39                         else
40                         {
41                                 // Deny
42                                 WriteServ(user->fd, "489 %s %s :Cannot join channel (+z)", user->nick, cname);
43                                 return 1;
44                         }
45                 }
46                 
47                 return 0;
48         }
49         
50         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
51         {
52                 // check if this is our mode character...
53                 if ((modechar == 'z') && (type == MT_CHANNEL))
54                 {
55                         chanrec* chan = (chanrec*)target;
56                         
57                         chanuserlist userlist = Srv->GetUsers(chan);
58                         
59                         for(unsigned int i = 0; i < userlist.size(); i++)
60                         {
61                                 if(!userlist[i]->GetExt("ssl"))
62                                 {
63                                         WriteServ(user->fd, "490 %s %s :all members of the channel must be connected via SSL", user->nick, chan->name);
64                                         return 0;
65                                 }
66                         }
67                         
68                         return 1;
69                 }
70                 else
71                 {
72                         return 0;
73                 }
74         }
75
76         virtual ~ModuleSSLModes()
77         {
78         }
79         
80         virtual Version GetVersion()
81         {
82                 return Version(1, 0, 0, 0, VF_STATIC | VF_VENDOR);
83         }
84 };
85
86
87 class ModuleSSLModesFactory : public ModuleFactory
88 {
89  public:
90         ModuleSSLModesFactory()
91         {
92         }
93         
94         ~ModuleSSLModesFactory()
95         {
96         }
97         
98         virtual Module* CreateModule(Server* Me)
99         {
100                 return new ModuleSSLModes(Me);
101         }
102         
103 };
104
105
106 extern "C" void * init_module( void )
107 {
108         return new ModuleSSLModesFactory;
109 }