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 ModuleStripColor : public Module
31 ConfigReader *Conf, *MyConf;
34 ModuleStripColor(Server* Me)
39 Srv->AddExtendedMode('S',MT_CHANNEL,false,0,0);
40 Srv->AddExtendedMode('S',MT_CLIENT,false,0,0);
43 void Implements(char* List)
45 List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
48 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
50 // check if this is our mode character...
61 virtual void On005Numeric(std::string &output)
63 InsertMode(output,"S",4);
66 virtual ~ModuleStripColor()
70 // ANSI colour stripping by Doc (Peter Wood)
71 virtual void ReplaceLine(std::string &text)
73 int i, a, len, remove;
74 char sentence[MAXBUF];
75 strlcpy(sentence,text.c_str(),MAXBUF);
77 len = strlen(sentence);
79 for (i = 0; i < len; i++)
96 if (isdigit(sentence[i + remove]))
99 if (isdigit(sentence[i + remove]))
102 if (sentence[i + remove] == ',')
106 if (isdigit(sentence[i + remove]))
116 for (a = i; a <= len; a++)
117 sentence[a] = sentence[a + remove];
125 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
128 if (target_type == TYPE_USER)
130 userrec* t = (userrec*)dest;
131 active = (strchr(t->modes,'S') > 0);
133 else if (target_type == TYPE_CHANNEL)
135 chanrec* t = (chanrec*)dest;
136 active = (t->IsCustomModeSet('S'));
140 this->ReplaceLine(text);
145 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
147 return OnUserPreMessage(user,dest,target_type,text,status);
150 virtual Version GetVersion()
152 // This is version 2 because version 1.x is the unreleased unrealircd module
153 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
158 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
160 class ModuleStripColorFactory : public ModuleFactory
163 ModuleStripColorFactory()
167 ~ModuleStripColorFactory()
171 virtual Module * CreateModule(Server* Me)
173 return new ModuleStripColor(Me);
179 extern "C" void * init_module( void )
181 return new ModuleStripColorFactory;