]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_stripcolor.cpp
b50c22297255a40bca75e93c42951f0ae8d82cda
[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
24 /** Handles channel mode +S
25  */
26 class ChannelStripColor : public SimpleChannelModeHandler
27 {
28  public:
29         ChannelStripColor(Module* Creator) : SimpleChannelModeHandler(Creator, "stripcolor", 'S') { }
30 };
31
32 /** Handles user mode +S
33  */
34 class UserStripColor : public SimpleUserModeHandler
35 {
36  public:
37         UserStripColor(Module* Creator) : SimpleUserModeHandler(Creator, "u_stripcolor", 'S') { }
38 };
39
40
41 class ModuleStripColor : public Module
42 {
43         ChannelStripColor csc;
44         UserStripColor usc;
45
46  public:
47         ModuleStripColor() : csc(this), usc(this)
48         {
49         }
50
51         void init() CXX11_OVERRIDE
52         {
53                 ServerInstance->Modules->AddService(usc);
54                 ServerInstance->Modules->AddService(csc);
55         }
56
57         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
58         {
59                 tokens["EXTBAN"].push_back('S');
60         }
61
62         ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
63         {
64                 if (!IS_LOCAL(user))
65                         return MOD_RES_PASSTHRU;
66
67                 bool active = false;
68                 if (target_type == TYPE_USER)
69                 {
70                         User* t = (User*)dest;
71                         active = t->IsModeSet(usc);
72                 }
73                 else if (target_type == TYPE_CHANNEL)
74                 {
75                         Channel* t = (Channel*)dest;
76                         ModResult res = ServerInstance->OnCheckExemption(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         Version GetVersion() CXX11_OVERRIDE
93         {
94                 return Version("Provides channel +S mode (strip ansi color)", VF_VENDOR);
95         }
96
97 };
98
99 MODULE_INIT(ModuleStripColor)