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"
27 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
29 class ChannelStripColor : public ModeHandler
32 ChannelStripColor() : ModeHandler('S', 0, 0, false, MODETYPE_CHANNEL, false) { }
34 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
36 /* Only opers can change other users modes */
37 if ((source != dest) && (!*source->oper))
38 return MODEACTION_DENY;
42 if (!channel->IsModeSet('S'))
44 channel->SetMode('S',true);
45 return MODEACTION_ALLOW;
50 if (channel->IsModeSet('S'))
52 channel->SetMode('S',false);
53 return MODEACTION_ALLOW;
57 return MODEACTION_DENY;
61 class UserStripColor : public ModeHandler
64 UserStripColor() : ModeHandler('S', 0, 0, false, MODETYPE_USER, false) { }
66 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
68 /* Only opers can change other users modes */
69 if ((source != dest) && (!*source->oper))
70 return MODEACTION_DENY;
74 if (!dest->IsModeSet('S'))
76 dest->SetMode('S',true);
77 return MODEACTION_ALLOW;
82 if (dest->IsModeSet('S'))
84 dest->SetMode('S',false);
85 return MODEACTION_ALLOW;
89 return MODEACTION_DENY;
94 class ModuleStripColor : public Module
97 ConfigReader *Conf, *MyConf;
98 ChannelStripColor *csc;
102 ModuleStripColor(Server* Me)
107 usc = new UserStripColor();
108 csc = new ChannelStripColor();
110 Srv->AddMode(usc, 'S');
111 Srv->AddMode(csc, 'S');
114 void Implements(char* List)
116 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
119 virtual void On005Numeric(std::string &output)
121 InsertMode(output,"S",4);
124 virtual ~ModuleStripColor()
130 // ANSI colour stripping by Doc (Peter Wood)
131 virtual void ReplaceLine(std::string &text)
133 int i, a, len, remove;
134 char sentence[MAXBUF];
135 strlcpy(sentence,text.c_str(),MAXBUF);
139 for (i = 0; i < len; i++)
156 if (isdigit(sentence[i + remove]))
159 if (isdigit(sentence[i + remove]))
162 if (sentence[i + remove] == ',')
166 if (isdigit(sentence[i + remove]))
176 for (a = i; a <= len; a++)
177 sentence[a] = sentence[a + remove];
185 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
188 if (target_type == TYPE_USER)
190 userrec* t = (userrec*)dest;
191 active = t->modes['S'-65];
193 else if (target_type == TYPE_CHANNEL)
195 chanrec* t = (chanrec*)dest;
196 active = (t->IsModeSet('S'));
200 this->ReplaceLine(text);
205 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
207 return OnUserPreMessage(user,dest,target_type,text,status);
210 virtual Version GetVersion()
212 // This is version 2 because version 1.x is the unreleased unrealircd module
213 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
218 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
220 class ModuleStripColorFactory : public ModuleFactory
223 ModuleStripColorFactory()
227 ~ModuleStripColorFactory()
231 virtual Module * CreateModule(Server* Me)
233 return new ModuleStripColor(Me);
239 extern "C" void * init_module( void )
241 return new ModuleStripColorFactory;