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;
33 ModuleStripColor(Server* Me)
38 Srv->AddExtendedMode('S',MT_CHANNEL,false,0,0);
39 Srv->AddExtendedMode('S',MT_CLIENT,false,0,0);
42 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
44 // check if this is our mode character...
55 virtual void On005Numeric(std::string &output)
57 std::stringstream line(output);
58 std::string temp1, temp2;
62 if (temp1.substr(0,10) == "CHANMODES=")
64 // append the chanmode to the end
65 temp1 = temp1.substr(10,temp1.length());
66 temp1 = "CHANMODES=" + temp1 + "S";
68 temp2 = temp2 + temp1 + " ";
71 output = temp2.substr(0,temp2.length()-1);
74 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]))
124 for (a = i; a <= len; a++)
125 sentence[a] = sentence[a + remove];
133 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
136 if (target_type == TYPE_USER)
138 userrec* t = (userrec*)dest;
139 active = (strchr(t->modes,'S') > 0);
141 else if (target_type == TYPE_CHANNEL)
143 chanrec* t = (chanrec*)dest;
144 active = (t->IsCustomModeSet('S'));
148 this->ReplaceLine(text);
153 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
156 if (target_type == TYPE_USER)
158 userrec* t = (userrec*)dest;
159 active = (strchr(t->modes,'S') > 0);
161 else if (target_type == TYPE_CHANNEL)
163 chanrec* t = (chanrec*)dest;
164 active = (t->IsCustomModeSet('S'));
168 this->ReplaceLine(text);
173 virtual Version GetVersion()
175 // This is version 2 because version 1.x is the unreleased unrealircd module
176 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
181 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
183 class ModuleStripColorFactory : public ModuleFactory
186 ModuleStripColorFactory()
190 ~ModuleStripColorFactory()
194 virtual Module * CreateModule(Server* Me)
196 return new ModuleStripColor(Me);
202 extern "C" void * init_module( void )
204 return new ModuleStripColorFactory;