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(InspIRCd* Instance, Module* Creator) : SimpleChannelModeHandler(Instance, Creator, 'S') { }
26 /** Handles user mode +S
28 class UserStripColor : public SimpleUserModeHandler
31 UserStripColor(InspIRCd* Instance, Module* Creator) : SimpleUserModeHandler(Creator, 'S') { }
35 class ModuleStripColor : public Module
38 ChannelStripColor csc;
42 ModuleStripColor(InspIRCd* Me) : Module(Me), csc(Me, this), usc(Me, 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()
52 ServerInstance->Modes->DelMode(&usc);
53 ServerInstance->Modes->DelMode(&csc);
56 virtual void On005Numeric(std::string &output)
58 ServerInstance->AddExtBanChar('S');
61 virtual void ReplaceLine(std::string &sentence)
63 /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
65 std::string::iterator i,safei;
66 for (i = sentence.begin(); i != sentence.end();)
70 else if (seq && (( ((*i >= '0') && (*i <= '9')) || (*i == ',') ) ))
73 if ( (seq <= 4) && (*i == ',') )
81 if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
83 if (i != sentence.begin())
87 sentence.erase(safei);
101 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
104 return MOD_RES_PASSTHRU;
107 if (target_type == TYPE_USER)
109 User* t = (User*)dest;
110 active = t->IsModeSet('S');
112 else if (target_type == TYPE_CHANNEL)
114 Channel* t = (Channel*)dest;
116 // check if we allow ops to bypass filtering, if we do, check if they're opped accordingly.
117 // note: short circut logic here, don't wreck it. -- w00t
118 if (CHANOPS_EXEMPT(ServerInstance, 'S') && t->GetPrefixValue(user) == OP_VALUE)
120 return MOD_RES_PASSTHRU;
123 active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet('S'));
128 this->ReplaceLine(text);
131 return MOD_RES_PASSTHRU;
134 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
136 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
139 virtual Version GetVersion()
141 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
146 MODULE_INIT(ModuleStripColor)