1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 colour) */
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, "stripcolor", 'S') { }
35 class ModuleStripColor : public Module
38 ChannelStripColor csc;
42 ModuleStripColor() : csc(this), usc(this)
44 if (!ServerInstance->Modes->AddMode(&usc) || !ServerInstance->Modes->AddMode(&csc))
45 throw ModuleException("Could not add new modes!");
46 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
47 ServerInstance->Modules->Attach(eventlist, this, 3);
50 virtual ~ModuleStripColor()
54 virtual void On005Numeric(std::string &output)
56 ServerInstance->AddExtBanChar('S');
59 virtual void ReplaceLine(std::string &sentence)
61 /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
63 std::string::iterator i,safei;
64 for (i = sentence.begin(); i != sentence.end();)
68 else if (seq && (( ((*i >= '0') && (*i <= '9')) || (*i == ',') ) ))
71 if ( (seq <= 4) && (*i == ',') )
79 if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
81 if (i != sentence.begin())
85 sentence.erase(safei);
99 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
102 return MOD_RES_PASSTHRU;
105 if (target_type == TYPE_USER)
107 User* t = (User*)dest;
108 active = t->IsModeSet('S');
110 else if (target_type == TYPE_CHANNEL)
112 Channel* t = (Channel*)dest;
114 FIRST_MOD_RESULT(OnChannelRestrictionApply, res, (user,t,"stripcolor"));
116 if (res == MOD_RES_ALLOW)
117 return MOD_RES_PASSTHRU;
119 active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet('S'));
124 this->ReplaceLine(text);
127 return MOD_RES_PASSTHRU;
130 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
132 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
135 virtual Version GetVersion()
137 return Version("Provides channel +S mode (strip ansi colour)", VF_COMMON | VF_VENDOR, API_VERSION);
142 MODULE_INIT(ModuleStripColor)