1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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, bool servermode)
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, bool servermode)
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->Modes->AddMode(usc) || !ServerInstance->Modes->AddMode(csc))
96 throw ModuleException("Could not add new modes!");
97 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
98 ServerInstance->Modules->Attach(eventlist, this, 2);
102 virtual ~ModuleStripColor()
104 ServerInstance->Modes->DelMode(usc);
105 ServerInstance->Modes->DelMode(csc);
110 virtual void ReplaceLine(std::string &sentence)
112 /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
114 std::string::iterator i,safei;
115 for (i = sentence.begin(); i != sentence.end(); ++i)
119 else if (seq && ( (*i >= '0') && (*i <= '9') || (*i == ',') ) )
122 if ( (seq <= 4) && (*i == ',') )
130 if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
134 sentence.erase(safei);
139 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
145 if (target_type == TYPE_USER)
147 User* t = (User*)dest;
148 active = t->IsModeSet('S');
150 else if (target_type == TYPE_CHANNEL)
152 Channel* t = (Channel*)dest;
154 // check if we allow ops to bypass filtering, if we do, check if they're opped accordingly.
155 // note: short circut logic here, don't wreck it. -- w00t
156 if (!CHANOPS_EXEMPT(ServerInstance, 'S') || CHANOPS_EXEMPT(ServerInstance, 'S') && t->GetStatus(user) != STATUS_OP)
157 active = t->IsModeSet('S');
162 this->ReplaceLine(text);
168 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
170 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
173 virtual Version GetVersion()
175 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
180 MODULE_INIT(ModuleStripColor)