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 * ---------------------------------------------------
24 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
26 /** Handles channel mode +S
28 class ChannelStripColor : public ModeHandler
31 ChannelStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_CHANNEL, false) { }
33 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
35 /* Only opers can change other users modes */
36 if ((source != dest) && (!*source->oper))
37 return MODEACTION_DENY;
41 if (!channel->IsModeSet('S'))
43 channel->SetMode('S',true);
44 return MODEACTION_ALLOW;
49 if (channel->IsModeSet('S'))
51 channel->SetMode('S',false);
52 return MODEACTION_ALLOW;
56 return MODEACTION_DENY;
60 /** Handles user mode +S
62 class UserStripColor : public ModeHandler
65 UserStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_USER, false) { }
67 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
69 /* Only opers can change other users modes */
70 if ((source != dest) && (!*source->oper))
71 return MODEACTION_DENY;
75 if (!dest->IsModeSet('S'))
77 dest->SetMode('S',true);
78 return MODEACTION_ALLOW;
83 if (dest->IsModeSet('S'))
85 dest->SetMode('S',false);
86 return MODEACTION_ALLOW;
90 return MODEACTION_DENY;
95 class ModuleStripColor : public Module
98 ConfigReader *Conf, *MyConf;
99 ChannelStripColor *csc;
103 ModuleStripColor(InspIRCd* Me)
108 usc = new UserStripColor(ServerInstance);
109 csc = new ChannelStripColor(ServerInstance);
111 ServerInstance->AddMode(usc, 'S');
112 ServerInstance->AddMode(csc, 'S');
115 void Implements(char* List)
117 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
120 virtual ~ModuleStripColor()
122 ServerInstance->Modes->DelMode(usc);
123 ServerInstance->Modes->DelMode(csc);
128 // ANSI colour stripping by Doc (Peter Wood)
129 virtual void ReplaceLine(std::string &text)
131 int i, a, len, remove;
132 char sentence[MAXBUF];
133 strlcpy(sentence,text.c_str(),MAXBUF);
137 for (i = 0; i < len; i++)
154 if (isdigit(sentence[i + remove]))
157 if (isdigit(sentence[i + remove]))
160 if (sentence[i + remove] == ',')
164 if (isdigit(sentence[i + remove]))
174 for (a = i; a <= len; a++)
175 sentence[a] = sentence[a + remove];
183 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
186 if (target_type == TYPE_USER)
188 userrec* t = (userrec*)dest;
189 active = t->modes['S'-65];
191 else if (target_type == TYPE_CHANNEL)
193 chanrec* t = (chanrec*)dest;
194 active = (t->IsModeSet('S'));
198 this->ReplaceLine(text);
203 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
205 return OnUserPreMessage(user,dest,target_type,text,status);
208 virtual Version GetVersion()
210 return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
215 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
217 class ModuleStripColorFactory : public ModuleFactory
220 ModuleStripColorFactory()
224 ~ModuleStripColorFactory()
228 virtual Module * CreateModule(InspIRCd* Me)
230 return new ModuleStripColor(Me);
236 extern "C" void * init_module( void )
238 return new ModuleStripColorFactory;