]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_stripcolor.cpp
6ad32bfc1010207530b46b36c976b3fa857f50ce
[user/henk/code/inspircd.git] / src / modules / m_stripcolor.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2004, 2008 Craig Edwards <craigedwards@brainbox.cc>
5  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23 #include "modules/exemption.h"
24
25 /** Handles channel mode +S
26  */
27 class ChannelStripColor : public SimpleChannelModeHandler
28 {
29  public:
30         ChannelStripColor(Module* Creator) : SimpleChannelModeHandler(Creator, "stripcolor", 'S') { }
31 };
32
33 /** Handles user mode +S
34  */
35 class UserStripColor : public SimpleUserModeHandler
36 {
37  public:
38         UserStripColor(Module* Creator) : SimpleUserModeHandler(Creator, "u_stripcolor", 'S') { }
39 };
40
41
42 class ModuleStripColor : public Module
43 {
44         CheckExemption::EventProvider exemptionprov;
45         ChannelStripColor csc;
46         UserStripColor usc;
47
48  public:
49         ModuleStripColor()
50                 : exemptionprov(this)
51                 , csc(this)
52                 , usc(this)
53         {
54         }
55
56         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
57         {
58                 tokens["EXTBAN"].push_back('S');
59         }
60
61         ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
62         {
63                 if (!IS_LOCAL(user))
64                         return MOD_RES_PASSTHRU;
65
66                 bool active = false;
67                 if (target_type == TYPE_USER)
68                 {
69                         User* t = (User*)dest;
70                         active = t->IsModeSet(usc);
71                 }
72                 else if (target_type == TYPE_CHANNEL)
73                 {
74                         Channel* t = (Channel*)dest;
75                         ModResult res;
76                         FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (user, t, "stripcolor"));
77
78                         if (res == MOD_RES_ALLOW)
79                                 return MOD_RES_PASSTHRU;
80
81                         active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet(csc));
82                 }
83
84                 if (active)
85                 {
86                         InspIRCd::StripColor(text);
87                 }
88
89                 return MOD_RES_PASSTHRU;
90         }
91
92         void OnUserPart(Membership* memb, std::string& partmessage, CUList& except_list) CXX11_OVERRIDE
93         {
94                 User* user = memb->user;
95                 Channel* channel = memb->chan;
96
97                 if (!IS_LOCAL(user))
98                         return;
99
100                 if (channel->GetExtBanStatus(user, 'S').check(!user->IsModeSet(csc)))
101                 {
102                         ModResult res;
103                         FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (user, channel, "stripcolor"));
104
105                         if (res != MOD_RES_ALLOW)
106                                 InspIRCd::StripColor(partmessage);
107                 }
108         }
109
110         Version GetVersion() CXX11_OVERRIDE
111         {
112                 return Version("Provides channel +S mode (strip ansi color)", VF_VENDOR);
113         }
114
115 };
116
117 MODULE_INIT(ModuleStripColor)