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 * ---------------------------------------------------
25 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
27 class ModuleStripColor : public Module
30 ConfigReader *Conf, *MyConf;
37 Srv->AddExtendedMode('S',MT_CHANNEL,false,0,0);
38 Srv->AddExtendedMode('S',MT_CLIENT,false,0,0);
41 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
43 // check if this is our mode character...
54 virtual void On005Numeric(std::string &output)
56 std::stringstream line(output);
57 std::string temp1, temp2;
61 if (temp1.substr(0,10) == "CHANMODES=")
63 // append the chanmode to the end
64 temp1 = temp1.substr(10,temp1.length());
65 temp1 = "CHANMODES=" + temp1 + "S";
67 temp2 = temp2 + temp1 + " ";
70 output = temp2.substr(0,temp2.length()-1);
73 virtual ~ModuleStripColor()
78 // ANSI colour stripping by Doc (Peter Wood)
79 virtual void ReplaceLine(std::string &text)
81 int i, a, len, remove;
82 char sentence[MAXBUF];
83 strncpy(sentence,text.c_str(),MAXBUF);
85 len = strlen (sentence);
87 for (i = 0; i < len; i++)
104 if (isdigit (sentence[i + remove]))
107 if (isdigit (sentence[i + remove]))
110 if (sentence[i + remove] == ',')
114 if (isdigit (sentence[i + remove]))
123 for (a = i; a <= len; a++)
124 sentence[a] = sentence[a + remove];
132 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
135 if (target_type == TYPE_USER)
137 userrec* t = (userrec*)dest;
138 active = (strchr(t->modes,'S') > 0);
140 else if (target_type == TYPE_CHANNEL)
142 chanrec* t = (chanrec*)dest;
143 active = (t->IsCustomModeSet('S'));
147 this->ReplaceLine(text);
152 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
155 if (target_type == TYPE_USER)
157 userrec* t = (userrec*)dest;
158 active = (strchr(t->modes,'S') > 0);
160 else if (target_type == TYPE_CHANNEL)
162 chanrec* t = (chanrec*)dest;
163 active = (t->IsCustomModeSet('S'));
167 this->ReplaceLine(text);
172 virtual Version GetVersion()
174 // This is version 2 because version 1.x is the unreleased unrealircd module
175 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
180 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
182 class ModuleStripColorFactory : public ModuleFactory
185 ModuleStripColorFactory()
189 ~ModuleStripColorFactory()
193 virtual Module * CreateModule()
195 return new ModuleStripColor;
201 extern "C" void * init_module( void )
203 return new ModuleStripColorFactory;