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 #include "helperfuncs.h"
26 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
28 class ChannelStripColor : public ModeHandler
31 ChannelStripColor() : ModeHandler('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 class UserStripColor : public ModeHandler
63 UserStripColor() : ModeHandler('S', 0, 0, false, MODETYPE_USER, false) { }
65 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
67 /* Only opers can change other users modes */
68 if ((source != dest) && (!*source->oper))
69 return MODEACTION_DENY;
73 if (!dest->IsModeSet('S'))
75 dest->SetMode('S',true);
76 return MODEACTION_ALLOW;
81 if (dest->IsModeSet('S'))
83 dest->SetMode('S',false);
84 return MODEACTION_ALLOW;
88 return MODEACTION_DENY;
93 class ModuleStripColor : public Module
96 ConfigReader *Conf, *MyConf;
97 ChannelStripColor *csc;
101 ModuleStripColor(Server* Me)
106 usc = new UserStripColor();
107 csc = new ChannelStripColor();
109 Srv->AddMode(usc, 'S');
110 Srv->AddMode(csc, 'S');
113 void Implements(char* List)
115 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
118 virtual void On005Numeric(std::string &output)
120 InsertMode(output,"S",4);
123 virtual ~ModuleStripColor()
129 // ANSI colour stripping by Doc (Peter Wood)
130 virtual void ReplaceLine(std::string &text)
132 int i, a, len, remove;
133 char sentence[MAXBUF];
134 strlcpy(sentence,text.c_str(),MAXBUF);
138 for (i = 0; i < len; i++)
155 if (isdigit(sentence[i + remove]))
158 if (isdigit(sentence[i + remove]))
161 if (sentence[i + remove] == ',')
165 if (isdigit(sentence[i + remove]))
175 for (a = i; a <= len; a++)
176 sentence[a] = sentence[a + remove];
184 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
187 if (target_type == TYPE_USER)
189 userrec* t = (userrec*)dest;
190 active = t->modes['S'-65];
192 else if (target_type == TYPE_CHANNEL)
194 chanrec* t = (chanrec*)dest;
195 active = (t->IsModeSet('S'));
199 this->ReplaceLine(text);
204 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
206 return OnUserPreMessage(user,dest,target_type,text,status);
209 virtual Version GetVersion()
211 // This is version 2 because version 1.x is the unreleased unrealircd module
212 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
217 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
219 class ModuleStripColorFactory : public ModuleFactory
222 ModuleStripColorFactory()
226 ~ModuleStripColorFactory()
230 virtual Module * CreateModule(Server* Me)
232 return new ModuleStripColor(Me);
238 extern "C" void * init_module( void )
240 return new ModuleStripColorFactory;