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 void On005Numeric(std::string &output)
54 std::stringstream line(output);
55 std::string temp1, temp2;
59 if (temp1.substr(0,10) == "CHANMODES=")
61 // append the chanmode to the end
62 temp1 = temp1.substr(10,temp1.length());
63 temp1 = "CHANMODES=" + temp1 + "S";
65 temp2 = temp2 + temp1 + " ";
67 output = temp2.substr(0,temp2.length()-1);
70 virtual ~ModuleStripColor()
75 // ANSI colour stripping by Doc (Peter Wood)
76 virtual void ReplaceLine(std::string &text)
78 int i, a, len, remove;
79 char sentence[MAXBUF];
80 strncpy(sentence,text.c_str(),MAXBUF);
82 len = strlen (sentence);
84 for (i = 0; i < len; i++)
101 if (isdigit (sentence[i + remove]))
104 if (isdigit (sentence[i + remove]))
107 if (sentence[i + remove] == ',')
111 if (isdigit (sentence[i + remove]))
120 for (a = i; a <= len; a++)
121 sentence[a] = sentence[a + remove];
129 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
132 if (target_type == TYPE_USER)
134 userrec* t = (userrec*)dest;
135 active = (strchr(t->modes,'S') > 0);
137 else if (target_type == TYPE_CHANNEL)
139 chanrec* t = (chanrec*)dest;
140 active = (t->IsCustomModeSet('S'));
144 this->ReplaceLine(text);
149 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
152 if (target_type == TYPE_USER)
154 userrec* t = (userrec*)dest;
155 active = (strchr(t->modes,'S') > 0);
157 else if (target_type == TYPE_CHANNEL)
159 chanrec* t = (chanrec*)dest;
160 active = (t->IsCustomModeSet('S'));
164 this->ReplaceLine(text);
169 virtual Version GetVersion()
171 // This is version 2 because version 1.x is the unreleased unrealircd module
172 return Version(1,0,0,0);
177 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
179 class ModuleStripColorFactory : public ModuleFactory
182 ModuleStripColorFactory()
186 ~ModuleStripColorFactory()
190 virtual Module * CreateModule()
192 return new ModuleStripColor;
198 extern "C" void * init_module( void )
200 return new ModuleStripColorFactory;