1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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 color) */
18 /** Handles channel mode +S
20 class ChannelStripColor : public SimpleChannelModeHandler
23 ChannelStripColor(Module* Creator) : SimpleChannelModeHandler(Creator, "stripcolor", 'S') { }
26 /** Handles user mode +S
28 class UserStripColor : public SimpleUserModeHandler
31 UserStripColor(Module* Creator) : SimpleUserModeHandler(Creator, "u_stripcolor", 'S') { }
35 class ModuleStripColor : public Module
38 ChannelStripColor csc;
42 ModuleStripColor() : csc(this), usc(this)
48 ServerInstance->Modules->AddService(usc);
49 ServerInstance->Modules->AddService(csc);
50 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
51 ServerInstance->Modules->Attach(eventlist, this, 3);
54 virtual ~ModuleStripColor()
58 virtual void On005Numeric(std::string &output)
60 ServerInstance->AddExtBanChar('S');
63 virtual void ReplaceLine(std::string &sentence)
65 /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
67 std::string::iterator i,safei;
68 for (i = sentence.begin(); i != sentence.end();)
72 else if (seq && (( ((*i >= '0') && (*i <= '9')) || (*i == ',') ) ))
75 if ( (seq <= 4) && (*i == ',') )
83 if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
85 if (i != sentence.begin())
89 sentence.erase(safei);
103 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
106 return MOD_RES_PASSTHRU;
109 if (target_type == TYPE_USER)
111 User* t = (User*)dest;
112 active = t->IsModeSet('S');
114 else if (target_type == TYPE_CHANNEL)
116 Channel* t = (Channel*)dest;
117 ModResult res = ServerInstance->OnCheckExemption(user,t,"stripcolor");
119 if (res == MOD_RES_ALLOW)
120 return MOD_RES_PASSTHRU;
122 active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet('S'));
127 this->ReplaceLine(text);
130 return MOD_RES_PASSTHRU;
133 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
135 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
138 virtual Version GetVersion()
140 return Version("Provides channel +S mode (strip ansi color)", VF_VENDOR);
145 MODULE_INIT(ModuleStripColor)