1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
18 /** Handles channel mode +S
20 class ChannelStripColor : public ModeHandler
23 ChannelStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_CHANNEL, false) { }
25 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
29 if (!channel->IsModeSet('S'))
31 channel->SetMode('S',true);
32 return MODEACTION_ALLOW;
37 if (channel->IsModeSet('S'))
39 channel->SetMode('S',false);
40 return MODEACTION_ALLOW;
44 return MODEACTION_DENY;
48 /** Handles user mode +S
50 class UserStripColor : public ModeHandler
53 UserStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_USER, false) { }
55 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
57 /* Only opers can change other users modes */
59 return MODEACTION_DENY;
63 if (!dest->IsModeSet('S'))
65 dest->SetMode('S',true);
66 return MODEACTION_ALLOW;
71 if (dest->IsModeSet('S'))
73 dest->SetMode('S',false);
74 return MODEACTION_ALLOW;
78 return MODEACTION_DENY;
83 class ModuleStripColor : public Module
86 ChannelStripColor *csc;
90 ModuleStripColor(InspIRCd* Me) : Module(Me)
92 usc = new UserStripColor(ServerInstance);
93 csc = new ChannelStripColor(ServerInstance);
95 if (!ServerInstance->AddMode(usc) || !ServerInstance->AddMode(csc))
96 throw ModuleException("Could not add new modes!");
99 void Implements(char* List)
101 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
104 virtual ~ModuleStripColor()
106 ServerInstance->Modes->DelMode(usc);
107 ServerInstance->Modes->DelMode(csc);
112 virtual void ReplaceLine(std::string &sentence)
114 /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
116 std::string::iterator i,safei;
117 for (i = sentence.begin(); i != sentence.end(); ++i)
121 else if (seq && ( (*i >= '0') && (*i <= '9') || (*i == ',') ) )
124 if ( (seq <= 4) && (*i == ',') )
132 if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
136 sentence.erase(safei);
141 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
147 if (target_type == TYPE_USER)
149 User* t = (User*)dest;
150 active = t->IsModeSet('S');
152 else if (target_type == TYPE_CHANNEL)
154 Channel* t = (Channel*)dest;
156 // check if we allow ops to bypass filtering, if we do, check if they're opped accordingly.
157 // note: short circut logic here, don't wreck it. -- w00t
158 if (!CHANOPS_EXEMPT(ServerInstance, 'S') || CHANOPS_EXEMPT(ServerInstance, 'S') && t->GetStatus(user) != STATUS_OP)
159 active = t->IsModeSet('S');
164 this->ReplaceLine(text);
170 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
172 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
175 virtual Version GetVersion()
177 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
182 MODULE_INIT(ModuleStripColor)