]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
Changed behaviour of module API to pass Server* to the constructor, rather than have...
[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 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "helperfuncs.h"
24
25 /* $ModDesc: Provides support for oper-only chans via the +O channel mode */
26
27 Server *Srv;
28          
29
30 class ModuleOperChans : public Module
31 {
32  public:
33         ModuleOperChans(Server* Me)
34                 : Module::Module(Me)
35         {
36                 Srv = Me;
37                 // Add a mode +O for channels with no parameters                
38                 Srv->AddExtendedMode('O',MT_CHANNEL,false,0,0);
39         }
40         
41         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
42         {
43                 if ((modechar == 'O') && (type == MT_CHANNEL))
44                 {
45                         chanrec* chan = (chanrec*)target;
46                         
47                         if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")) || (strchr(user->modes,'o')))
48                         {
49                                 return 1;
50                         }
51                         else
52                         {
53                                 // eat the mode change, return an error
54                                 WriteServ(user->fd,"468 %s %s :Only servers and opers may set channel mode +O",user->nick, chan->name);
55                                 return 0;
56                         }
57         
58                         // must return 1 to handle the mode!
59                         return 1;
60                 }
61                 
62                 return 0;
63         }
64
65         virtual void On005Numeric(std::string &output)
66         {
67                 std::stringstream line(output);
68                 std::string temp1, temp2;
69                 while (!line.eof())
70                 {
71                         line >> temp1;
72                         if (temp1.substr(0,10) == "CHANMODES=")
73                         {
74                                 // append the chanmode to the end
75                                 temp1 = temp1.substr(10,temp1.length());
76                                 temp1 = "CHANMODES=" + temp1 + "O";
77                         }
78                         temp2 = temp2 + temp1 + " ";
79                 }
80                 if (temp2.length())
81                         output = temp2.substr(0,temp2.length()-1);
82         }
83         
84         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
85         {
86                 if (!strchr(user->modes,'o'))
87                 {
88                         if (chan)
89                         {
90                                 if (chan->IsCustomModeSet('O'))
91                                 {
92                                         WriteServ(user->fd,"520 %s %s :Only IRC operators may join the channel %s (+O is set)",user->nick, chan->name,chan->name);
93                                         return 1;
94                                 }
95                         }
96                 }
97                 return 0;
98         }
99         
100         virtual ~ModuleOperChans()
101         {
102         }
103         
104         virtual Version GetVersion()
105         {
106                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
107         }
108 };
109
110
111 class ModuleOperChansFactory : public ModuleFactory
112 {
113  public:
114         ModuleOperChansFactory()
115         {
116         }
117         
118         ~ModuleOperChansFactory()
119         {
120         }
121         
122         virtual Module * CreateModule(Server* Me)
123         {
124                 return new ModuleOperChans(Me);
125         }
126         
127 };
128
129
130 extern "C" void * init_module( void )
131 {
132         return new ModuleOperChansFactory;
133 }
134