]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_stripcolor.cpp
Convert ISUPPORT to use a map instead of a string.
[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 /* $ModDesc: Provides channel +S mode (strip ansi color) */
25
26 /** Handles channel mode +S
27  */
28 class ChannelStripColor : public SimpleChannelModeHandler
29 {
30  public:
31         ChannelStripColor(Module* Creator) : SimpleChannelModeHandler(Creator, "stripcolor", 'S') { }
32 };
33
34 /** Handles user mode +S
35  */
36 class UserStripColor : public SimpleUserModeHandler
37 {
38  public:
39         UserStripColor(Module* Creator) : SimpleUserModeHandler(Creator, "u_stripcolor", 'S') { }
40 };
41
42
43 class ModuleStripColor : public Module
44 {
45         ChannelStripColor csc;
46         UserStripColor usc;
47
48  public:
49         ModuleStripColor() : csc(this), usc(this)
50         {
51         }
52
53         void init()
54         {
55                 ServerInstance->Modules->AddService(usc);
56                 ServerInstance->Modules->AddService(csc);
57                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
58                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
59         }
60
61         virtual void On005Numeric(std::map<std::string, std::string>& tokens)
62         {
63                 tokens["EXTBAN"].push_back('S');
64         }
65
66         virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
67         {
68                 if (!IS_LOCAL(user))
69                         return MOD_RES_PASSTHRU;
70
71                 bool active = false;
72                 if (target_type == TYPE_USER)
73                 {
74                         User* t = (User*)dest;
75                         active = t->IsModeSet('S');
76                 }
77                 else if (target_type == TYPE_CHANNEL)
78                 {
79                         Channel* t = (Channel*)dest;
80                         ModResult res = ServerInstance->OnCheckExemption(user,t,"stripcolor");
81
82                         if (res == MOD_RES_ALLOW)
83                                 return MOD_RES_PASSTHRU;
84
85                         active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet('S'));
86                 }
87
88                 if (active)
89                 {
90                         InspIRCd::StripColor(text);
91                 }
92
93                 return MOD_RES_PASSTHRU;
94         }
95
96         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
97         {
98                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
99         }
100
101         virtual Version GetVersion()
102         {
103                 return Version("Provides channel +S mode (strip ansi color)", VF_VENDOR);
104         }
105
106 };
107
108 MODULE_INIT(ModuleStripColor)