]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonotice.cpp
New 'Implements' system
[user/henk/code/inspircd.git] / src / modules / m_nonotice.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 unreal-style channel mode +T */
26
27 class ModuleNoNotice : public Module
28 {
29         Server *Srv;
30  public:
31  
32         ModuleNoNotice(Server* Me)
33                 : Module::Module(Me)
34         {
35                 Srv = Me;
36                 Srv->AddExtendedMode('T',MT_CHANNEL,false,0,0);
37         }
38         
39         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
40         {
41                 if (target_type == TYPE_CHANNEL)
42                 {
43                         chanrec* c = (chanrec*)dest;
44                         if (c->IsCustomModeSet('T'))
45                         {
46                                 if ((Srv->ChanMode(user,c) == "@") || (Srv->ChanMode(user,c) == "%"))
47                                 {
48                                         // ops and halfops can still /NOTICE the channel
49                                         return 0;
50                                 }
51                                 else
52                                 {
53                                         WriteServ(user->fd,"404 %s %s :Can't send NOTICE to channel (+T set)",user->nick, c->name);
54                                         return 1;
55                                 }
56                         }
57                 }
58                 return 0;
59         }
60
61         virtual void On005Numeric(std::string &output)
62         {
63                 std::stringstream line(output);
64                 std::string temp1, temp2;
65                 while (!line.eof())
66                 {
67                         line >> temp1;
68                         if (temp1.substr(0,10) == "CHANMODES=")
69                         {
70                                 // append the chanmode to the end
71                                 temp1 = temp1.substr(10,temp1.length());
72                                 temp1 = "CHANMODES=" + temp1 + "T";
73                         }
74                         temp2 = temp2 + temp1 + " ";
75                 }
76                 if (temp2.length())
77                         output = temp2.substr(0,temp2.length()-1);
78         }
79
80         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
81         {
82                 // check if this is our mode character...
83                 if ((modechar == 'T') && (type == MT_CHANNEL))
84                 {
85                         return 1;
86                 }
87                 else
88                 {
89                         return 0;
90                 }
91         }
92         
93         virtual ~ModuleNoNotice()
94         {
95         }
96         
97         virtual Version GetVersion()
98         {
99                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
100         }
101 };
102
103
104 class ModuleNoNoticeFactory : public ModuleFactory
105 {
106  public:
107         ModuleNoNoticeFactory()
108         {
109         }
110         
111         ~ModuleNoNoticeFactory()
112         {
113         }
114         
115         virtual Module * CreateModule(Server* Me)
116         {
117                 return new ModuleNoNotice(Me);
118         }
119         
120 };
121
122
123 extern "C" void * init_module( void )
124 {
125         return new ModuleNoNoticeFactory;
126 }
127