]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
Add Module* creator to Command and ModeHandler
[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, Module* Creator) : ModeHandler(Instance, Creator, '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), sslm(Me, this)
74         {
75                 if (!ServerInstance->Modes->AddMode(&sslm))
76                         throw ModuleException("Could not add new modes!");
77                 Implementation eventlist[] = { I_OnUserPreJoin };
78                 ServerInstance->Modules->Attach(eventlist, this, 1);
79         }
80
81
82         virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
83         {
84                 if(chan && chan->IsModeSet('z'))
85                 {
86                         if(user->GetExt("ssl", dummy))
87                         {
88                                 // Let them in
89                                 return 0;
90                         }
91                         else
92                         {
93                                 // Deny
94                                 user->WriteServ( "489 %s %s :Cannot join channel; SSL users only (+z)", user->nick.c_str(), cname);
95                                 return 1;
96                         }
97                 }
98
99                 return 0;
100         }
101
102         virtual ~ModuleSSLModes()
103         {
104                 ServerInstance->Modes->DelMode(&sslm);
105         }
106
107         virtual Version GetVersion()
108         {
109                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
110         }
111 };
112
113
114 MODULE_INIT(ModuleSSLModes)
115