]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
e5eefe0cf77357ec160443c9896615e5e2a2bbd5
[user/henk/code/inspircd.git] / src / modules / m_operchans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <stdio.h>
18 #include "users.h"
19 #include "channels.h"
20 #include "modules.h"
21
22 /* $ModDesc: Provides support for oper-only chans via the +O channel mode */
23
24 Server *Srv;
25          
26
27 class ModuleOperChans : public Module
28 {
29  public:
30         ModuleOperChans()
31         {
32                 Srv = new Server;
33
34                 // Add a mode +O for channels with no parameters                
35                 Srv->AddExtendedMode('O',MT_CHANNEL,false,0,0);
36         }
37         
38         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
39         {
40                 if ((modechar == 'O') && (type == MT_CHANNEL))
41                 {
42                         chanrec* chan = (chanrec*)target;
43                         
44                         if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")) || (strchr(user->modes,'o')))
45                         {
46                                 return 1;
47                         }
48                         else
49                         {
50                                 // eat the mode change, return an error
51                                 WriteServ(user->fd,"468 %s %s :Only servers and opers may set channel mode +O",user->nick, chan->name);
52                                 return 0;
53                         }
54         
55                         // must return 1 to handle the mode!
56                         return 1;
57                 }
58                 
59                 return 0;
60         }
61
62         virtual void On005Numeric(std::string &output)
63         {
64                 std::stringstream line(output);
65                 std::string temp1, temp2;
66                 while (!line.eof())
67                 {
68                         line >> temp1;
69                         if (temp1.substr(0,10) == "CHANMODES=")
70                         {
71                                 // append the chanmode to the end
72                                 temp1 = temp1.substr(10,temp1.length());
73                                 temp1 = "CHANMODES=" + temp1 + "O";
74                         }
75                         temp2 = temp2 + temp1 + " ";
76                 }
77                 output = temp2.substr(0,temp2.length()-1);
78         }
79         
80         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
81         {
82                 if (!strchr(user->modes,'o'))
83                 {
84                         if (chan)
85                         {
86                                 if (chan->IsCustomModeSet('O'))
87                                 {
88                                         WriteServ(user->fd,"520 %s %s :Only IRC operators may join the channel %s (+O is set)",user->nick, chan->name,chan->name);
89                                         return 1;
90                                 }
91                         }
92                 }
93                 return 0;
94         }
95         
96         virtual ~ModuleOperChans()
97         {
98                 delete Srv;
99         }
100         
101         virtual Version GetVersion()
102         {
103                 return Version(1,0,0,0);
104         }
105         
106         virtual void OnUserConnect(userrec* user)
107         {
108         }
109
110 };
111
112
113 class ModuleOperChansFactory : public ModuleFactory
114 {
115  public:
116         ModuleOperChansFactory()
117         {
118         }
119         
120         ~ModuleOperChansFactory()
121         {
122         }
123         
124         virtual Module * CreateModule()
125         {
126                 return new ModuleOperChans;
127         }
128         
129 };
130
131
132 extern "C" void * init_module( void )
133 {
134         return new ModuleOperChansFactory;
135 }
136