1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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 * ---------------------------------------------------
23 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
25 class ModuleStripColor : public Module
28 ConfigReader *Conf, *MyConf;
35 Srv->AddExtendedMode('S',MT_CHANNEL,false,0,0);
36 Srv->AddExtendedMode('S',MT_CLIENT,false,0,0);
39 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
41 // check if this is our mode character...
52 virtual ~ModuleStripColor()
57 // ANSI colour stripping by Doc (Peter Wood)
58 virtual void ReplaceLine(std::string &text)
60 int i, a, len, remove;
61 char sentence[MAXBUF];
62 strncpy(sentence,text.c_str(),MAXBUF);
64 len = strlen (sentence);
66 for (i = 0; i < len; i++)
83 if (isdigit (sentence[i + remove]))
86 if (isdigit (sentence[i + remove]))
89 if (sentence[i + remove] == ',')
93 if (isdigit (sentence[i + remove]))
102 for (a = i; a <= len; a++)
103 sentence[a] = sentence[a + remove];
111 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
114 if (target_type == TYPE_USER)
116 userrec* t = (userrec*)dest;
117 active = (strchr(t->modes,'S') > 0);
119 else if (target_type == TYPE_CHANNEL)
121 chanrec* t = (chanrec*)dest;
122 active = (t->IsCustomModeSet('S'));
126 this->ReplaceLine(text);
131 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
134 if (target_type == TYPE_USER)
136 userrec* t = (userrec*)dest;
137 active = (strchr(t->modes,'S') > 0);
139 else if (target_type == TYPE_CHANNEL)
141 chanrec* t = (chanrec*)dest;
142 active = (t->IsCustomModeSet('S'));
146 this->ReplaceLine(text);
151 virtual Version GetVersion()
153 // This is version 2 because version 1.x is the unreleased unrealircd module
154 return Version(1,0,0,0);
159 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
161 class ModuleStripColorFactory : public ModuleFactory
164 ModuleStripColorFactory()
168 ~ModuleStripColorFactory()
172 virtual Module * CreateModule()
174 return new ModuleStripColor;
180 extern "C" void * init_module( void )
182 return new ModuleStripColorFactory;