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 // ANSI colour stripping based on C example by Doc (Peter Wood)
116 virtual void ReplaceLine(std::string &sentence)
118 int i, a, len, remove;
119 len = sentence.length();
121 for (i = 0; i < len; i++)
138 if (isdigit(sentence[i + remove]))
141 if (isdigit(sentence[i + remove]))
144 if (sentence[i + remove] == ',')
148 if (isdigit(sentence[i + remove]))
158 for (a = i; a <= len; a++)
159 sentence[a] = sentence[a + remove];
165 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
171 if (target_type == TYPE_USER)
173 userrec* t = (userrec*)dest;
174 active = t->IsModeSet('S');
176 else if (target_type == TYPE_CHANNEL)
178 chanrec* t = (chanrec*)dest;
180 // check if we allow ops to bypass filtering, if we do, check if they're opped accordingly.
181 // note: short circut logic here, don't wreck it. -- w00t
182 if (!CHANOPS_EXEMPT(ServerInstance, 'S') || CHANOPS_EXEMPT(ServerInstance, 'S') && t->GetStatus(user) != STATUS_OP)
183 active = t->IsModeSet('S');
188 this->ReplaceLine(text);
194 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
196 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
199 virtual Version GetVersion()
201 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
206 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
208 class ModuleStripColorFactory : public ModuleFactory
211 ModuleStripColorFactory()
215 ~ModuleStripColorFactory()
219 virtual Module * CreateModule(InspIRCd* Me)
221 return new ModuleStripColor(Me);
227 extern "C" DllExport void * init_module( void )
229 return new ModuleStripColorFactory;