]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
af94bc25ff6032b24185afed297af61b0cc7b643
[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         void Implements(char* List)
42         {
43                 List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreJoin] = 1;
44         }
45         
46         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
47         {
48                 if ((modechar == 'O') && (type == MT_CHANNEL))
49                 {
50                         chanrec* chan = (chanrec*)target;
51                         
52                         if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")) || (strchr(user->modes,'o')))
53                         {
54                                 return 1;
55                         }
56                         else
57                         {
58                                 // eat the mode change, return an error
59                                 WriteServ(user->fd,"468 %s %s :Only servers and opers may set channel mode +O",user->nick, chan->name);
60                                 return 0;
61                         }
62         
63                         // must return 1 to handle the mode!
64                         return 1;
65                 }
66                 
67                 return 0;
68         }
69
70         virtual void On005Numeric(std::string &output)
71         {
72                 std::stringstream line(output);
73                 std::string temp1, temp2;
74                 while (!line.eof())
75                 {
76                         line >> temp1;
77                         if (temp1.substr(0,10) == "CHANMODES=")
78                         {
79                                 // append the chanmode to the end
80                                 temp1 = temp1.substr(10,temp1.length());
81                                 temp1 = "CHANMODES=" + temp1 + "O";
82                         }
83                         temp2 = temp2 + temp1 + " ";
84                 }
85                 if (temp2.length())
86                         output = temp2.substr(0,temp2.length()-1);
87         }
88         
89         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
90         {
91                 if (!strchr(user->modes,'o'))
92                 {
93                         if (chan)
94                         {
95                                 if (chan->IsCustomModeSet('O'))
96                                 {
97                                         WriteServ(user->fd,"520 %s %s :Only IRC operators may join the channel %s (+O is set)",user->nick, chan->name,chan->name);
98                                         return 1;
99                                 }
100                         }
101                 }
102                 return 0;
103         }
104         
105         virtual ~ModuleOperChans()
106         {
107         }
108         
109         virtual Version GetVersion()
110         {
111                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
112         }
113 };
114
115
116 class ModuleOperChansFactory : public ModuleFactory
117 {
118  public:
119         ModuleOperChansFactory()
120         {
121         }
122         
123         ~ModuleOperChansFactory()
124         {
125         }
126         
127         virtual Module * CreateModule(Server* Me)
128         {
129                 return new ModuleOperChans(Me);
130         }
131         
132 };
133
134
135 extern "C" void * init_module( void )
136 {
137         return new ModuleOperChansFactory;
138 }
139