]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
Update all wiki links to point to the new wiki. This was done automatically with...
[user/henk/code/inspircd.git] / src / modules / m_sslmodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides support for unreal-style channel mode +z */
17
18 static char* dummy;
19
20 /** Handle channel mode +z
21  */
22 class SSLMode : public ModeHandler
23 {
24  public:
25         SSLMode(InspIRCd* Instance) : ModeHandler(Instance, 'z', 0, 0, false, MODETYPE_CHANNEL, false) { }
26
27         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
28         {
29                 if (adding)
30                 {
31                         if (!channel->IsModeSet('z'))
32                         {
33                                 if (IS_LOCAL(source))
34                                 {
35                                         CUList* userlist = channel->GetUsers();
36                                         for(CUList::iterator i = userlist->begin(); i != userlist->end(); i++)
37                                         {
38                                                 if(!i->first->GetExt("ssl", dummy) && !ServerInstance->ULine(i->first->server))
39                                                 {
40                                                         source->WriteNumeric(ERR_ALLMUSTSSL, "%s %s :all members of the channel must be connected via SSL", source->nick.c_str(), channel->name.c_str());
41                                                         return MODEACTION_DENY;
42                                                 }
43                                         }
44                                 }
45                                 channel->SetMode('z',true);
46                                 return MODEACTION_ALLOW;
47                         }
48                         else
49                         {
50                                 return MODEACTION_DENY;
51                         }
52                 }
53                 else
54                 {
55                         if (channel->IsModeSet('z'))
56                         {
57                                 channel->SetMode('z',false);
58                                 return MODEACTION_ALLOW;
59                         }
60
61                         return MODEACTION_DENY;
62                 }
63         }
64 };
65
66 class ModuleSSLModes : public Module
67 {
68
69         SSLMode* sslm;
70
71  public:
72         ModuleSSLModes(InspIRCd* Me)
73                 : Module(Me)
74         {
75
76
77                 sslm = new SSLMode(ServerInstance);
78                 if (!ServerInstance->Modes->AddMode(sslm))
79                         throw ModuleException("Could not add new modes!");
80                 Implementation eventlist[] = { I_OnUserPreJoin };
81                 ServerInstance->Modules->Attach(eventlist, this, 1);
82         }
83
84
85         virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
86         {
87                 if(chan && chan->IsModeSet('z'))
88                 {
89                         if(user->GetExt("ssl", dummy))
90                         {
91                                 // Let them in
92                                 return 0;
93                         }
94                         else
95                         {
96                                 // Deny
97                                 user->WriteServ( "489 %s %s :Cannot join channel; SSL users only (+z)", user->nick.c_str(), cname);
98                                 return 1;
99                         }
100                 }
101
102                 return 0;
103         }
104
105         virtual ~ModuleSSLModes()
106         {
107                 ServerInstance->Modes->DelMode(sslm);
108                 delete sslm;
109         }
110
111         virtual Version GetVersion()
112         {
113                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
114         }
115 };
116
117
118 MODULE_INIT(ModuleSSLModes)
119