]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
Remove debug stuff
[user/henk/code/inspircd.git] / src / modules / m_sslmodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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)
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))
39                                                 {
40                                                         source->WriteServ("490 %s %s :all members of the channel must be connected via SSL", source->nick, channel->name);
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->AddMode(sslm))
79                         throw ModuleException("Could not add new modes!");
80         }
81
82         void Implements(char* List)
83         {
84                 List[I_OnUserPreJoin] = 1;
85         }
86
87         virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs)
88         {
89                 if(chan && chan->IsModeSet('z'))
90                 {
91                         if(user->GetExt("ssl", dummy))
92                         {
93                                 // Let them in
94                                 return 0;
95                         }
96                         else
97                         {
98                                 // Deny
99                                 user->WriteServ( "489 %s %s :Cannot join channel; SSL users only (+z)", user->nick, cname);
100                                 return 1;
101                         }
102                 }
103                 
104                 return 0;
105         }
106
107         virtual ~ModuleSSLModes()
108         {
109                 ServerInstance->Modes->DelMode(sslm);
110                 DELETE(sslm);
111         }
112         
113         virtual Version GetVersion()
114         {
115                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
116         }
117 };
118
119
120 MODULE_INIT(ModuleSSLModes)
121