1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 * ---------------------------------------------------
19 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
21 /** Handles channel mode +S
23 class ChannelStripColor : public ModeHandler
26 ChannelStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_CHANNEL, false) { }
28 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
32 if (!channel->IsModeSet('S'))
34 channel->SetMode('S',true);
35 return MODEACTION_ALLOW;
40 if (channel->IsModeSet('S'))
42 channel->SetMode('S',false);
43 return MODEACTION_ALLOW;
47 return MODEACTION_DENY;
51 /** Handles user mode +S
53 class UserStripColor : public ModeHandler
56 UserStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_USER, false) { }
58 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
60 /* Only opers can change other users modes */
62 return MODEACTION_DENY;
66 if (!dest->IsModeSet('S'))
68 dest->SetMode('S',true);
69 return MODEACTION_ALLOW;
74 if (dest->IsModeSet('S'))
76 dest->SetMode('S',false);
77 return MODEACTION_ALLOW;
81 return MODEACTION_DENY;
86 class ModuleStripColor : public Module
89 ChannelStripColor *csc;
93 ModuleStripColor(InspIRCd* Me) : Module(Me)
95 usc = new UserStripColor(ServerInstance);
96 csc = new ChannelStripColor(ServerInstance);
98 if (!ServerInstance->AddMode(usc, 'S') || !ServerInstance->AddMode(csc, 'S'))
99 throw ModuleException("Could not add new modes!");
102 void Implements(char* List)
104 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
107 virtual ~ModuleStripColor()
109 ServerInstance->Modes->DelMode(usc);
110 ServerInstance->Modes->DelMode(csc);
115 virtual void ReplaceLine(std::string &sentence)
117 /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
119 std::string::iterator i,safei;
120 for (i = sentence.begin(); i != sentence.end(); ++i)
124 else if (seq && ( (*i >= '0') && (*i <= '9') || (*i == ',') ) )
127 if ( (seq <= 4) && (*i == ',') )
135 if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
139 sentence.erase(safei);
144 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
150 if (target_type == TYPE_USER)
152 userrec* t = (userrec*)dest;
153 active = t->IsModeSet('S');
155 else if (target_type == TYPE_CHANNEL)
157 chanrec* t = (chanrec*)dest;
159 // check if we allow ops to bypass filtering, if we do, check if they're opped accordingly.
160 // note: short circut logic here, don't wreck it. -- w00t
161 if (!CHANOPS_EXEMPT(ServerInstance, 'S') || CHANOPS_EXEMPT(ServerInstance, 'S') && t->GetStatus(user) != STATUS_OP)
162 active = t->IsModeSet('S');
167 this->ReplaceLine(text);
173 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
175 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
178 virtual Version GetVersion()
180 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
185 MODULE_INIT(ModuleStripColor)