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 + " ";
68 output = temp2.substr(0,temp2.length()-1);
71 virtual ~ModuleStripColor()
76 // ANSI colour stripping by Doc (Peter Wood)
77 virtual void ReplaceLine(std::string &text)
79 int i, a, len, remove;
80 char sentence[MAXBUF];
81 strncpy(sentence,text.c_str(),MAXBUF);
83 len = strlen (sentence);
85 for (i = 0; i < len; i++)
102 if (isdigit (sentence[i + remove]))
105 if (isdigit (sentence[i + remove]))
108 if (sentence[i + remove] == ',')
112 if (isdigit (sentence[i + remove]))
121 for (a = i; a <= len; a++)
122 sentence[a] = sentence[a + remove];
130 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
133 if (target_type == TYPE_USER)
135 userrec* t = (userrec*)dest;
136 active = (strchr(t->modes,'S') > 0);
138 else if (target_type == TYPE_CHANNEL)
140 chanrec* t = (chanrec*)dest;
141 active = (t->IsCustomModeSet('S'));
145 this->ReplaceLine(text);
150 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
153 if (target_type == TYPE_USER)
155 userrec* t = (userrec*)dest;
156 active = (strchr(t->modes,'S') > 0);
158 else if (target_type == TYPE_CHANNEL)
160 chanrec* t = (chanrec*)dest;
161 active = (t->IsCustomModeSet('S'));
165 this->ReplaceLine(text);
170 virtual Version GetVersion()
172 // This is version 2 because version 1.x is the unreleased unrealircd module
173 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
178 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
180 class ModuleStripColorFactory : public ModuleFactory
183 ModuleStripColorFactory()
187 ~ModuleStripColorFactory()
191 virtual Module * CreateModule()
193 return new ModuleStripColor;
199 extern "C" void * init_module( void )
201 return new ModuleStripColorFactory;