1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
27 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
31 class ChannelStripColor : public ModeHandler
34 ChannelStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_CHANNEL, false) { }
36 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
38 /* Only opers can change other users modes */
39 if ((source != dest) && (!*source->oper))
40 return MODEACTION_DENY;
44 if (!channel->IsModeSet('S'))
46 channel->SetMode('S',true);
47 return MODEACTION_ALLOW;
52 if (channel->IsModeSet('S'))
54 channel->SetMode('S',false);
55 return MODEACTION_ALLOW;
59 return MODEACTION_DENY;
63 class UserStripColor : public ModeHandler
66 UserStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_USER, false) { }
68 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
70 /* Only opers can change other users modes */
71 if ((source != dest) && (!*source->oper))
72 return MODEACTION_DENY;
76 if (!dest->IsModeSet('S'))
78 dest->SetMode('S',true);
79 return MODEACTION_ALLOW;
84 if (dest->IsModeSet('S'))
86 dest->SetMode('S',false);
87 return MODEACTION_ALLOW;
91 return MODEACTION_DENY;
96 class ModuleStripColor : public Module
99 ConfigReader *Conf, *MyConf;
100 ChannelStripColor *csc;
104 ModuleStripColor(InspIRCd* Me)
109 usc = new UserStripColor(ServerInstance);
110 csc = new ChannelStripColor(ServerInstance);
112 ServerInstance->AddMode(usc, 'S');
113 ServerInstance->AddMode(csc, 'S');
116 void Implements(char* List)
118 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
121 virtual void On005Numeric(std::string &output)
123 ServerInstance->Modes->InsertMode(output,"S",4);
126 virtual ~ModuleStripColor()
132 // ANSI colour stripping by Doc (Peter Wood)
133 virtual void ReplaceLine(std::string &text)
135 int i, a, len, remove;
136 char sentence[MAXBUF];
137 strlcpy(sentence,text.c_str(),MAXBUF);
141 for (i = 0; i < len; i++)
158 if (isdigit(sentence[i + remove]))
161 if (isdigit(sentence[i + remove]))
164 if (sentence[i + remove] == ',')
168 if (isdigit(sentence[i + remove]))
178 for (a = i; a <= len; a++)
179 sentence[a] = sentence[a + remove];
187 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
190 if (target_type == TYPE_USER)
192 userrec* t = (userrec*)dest;
193 active = t->modes['S'-65];
195 else if (target_type == TYPE_CHANNEL)
197 chanrec* t = (chanrec*)dest;
198 active = (t->IsModeSet('S'));
202 this->ReplaceLine(text);
207 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
209 return OnUserPreMessage(user,dest,target_type,text,status);
212 virtual Version GetVersion()
214 // This is version 2 because version 1.x is the unreleased unrealircd module
215 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
220 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
222 class ModuleStripColorFactory : public ModuleFactory
225 ModuleStripColorFactory()
229 ~ModuleStripColorFactory()
233 virtual Module * CreateModule(InspIRCd* Me)
235 return new ModuleStripColor(Me);
241 extern "C" void * init_module( void )
243 return new ModuleStripColorFactory;