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