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 SimpleChannelModeHandler
23 ChannelStripColor(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'S') { }
26 /** Handles user mode +S
28 class UserStripColor : public SimpleUserModeHandler
31 UserStripColor(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'S') { }
35 class ModuleStripColor : public Module
38 ChannelStripColor *csc;
42 ModuleStripColor(InspIRCd* Me) : Module(Me)
44 usc = new UserStripColor(ServerInstance);
45 csc = new ChannelStripColor(ServerInstance);
47 if (!ServerInstance->Modes->AddMode(usc) || !ServerInstance->Modes->AddMode(csc))
48 throw ModuleException("Could not add new modes!");
49 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
50 ServerInstance->Modules->Attach(eventlist, this, 3);
53 virtual ~ModuleStripColor()
55 ServerInstance->Modes->DelMode(usc);
56 ServerInstance->Modes->DelMode(csc);
61 virtual void On005Numeric(std::string &output)
63 ServerInstance->AddExtBanChar('S');
66 virtual void ReplaceLine(std::string &sentence)
68 /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
70 std::string::iterator i,safei;
71 for (i = sentence.begin(); i != sentence.end();)
75 else if (seq && (( ((*i >= '0') && (*i <= '9')) || (*i == ',') ) ))
78 if ( (seq <= 4) && (*i == ',') )
86 if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
88 if (i != sentence.begin())
92 sentence.erase(safei);
106 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
112 if (target_type == TYPE_USER)
114 User* t = (User*)dest;
115 active = t->IsModeSet('S');
117 else if (target_type == TYPE_CHANNEL)
119 Channel* t = (Channel*)dest;
121 // check if we allow ops to bypass filtering, if we do, check if they're opped accordingly.
122 // note: short circut logic here, don't wreck it. -- w00t
123 if (CHANOPS_EXEMPT(ServerInstance, 'S') && t->GetStatus(user) == STATUS_OP)
128 active = t->IsModeSet('S') || t->IsExtBanned(user, 'S');
133 this->ReplaceLine(text);
139 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
141 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
144 virtual Version GetVersion()
146 return Version(1, 2, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
151 MODULE_INIT(ModuleStripColor)