1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 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 void Implements(char* List)
44 List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
47 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
49 // check if this is our mode character...
60 virtual void On005Numeric(std::string &output)
62 std::stringstream line(output);
63 std::string temp1, temp2;
67 if (temp1.substr(0,10) == "CHANMODES=")
69 // append the chanmode to the end
70 temp1 = temp1.substr(10,temp1.length());
71 temp1 = "CHANMODES=" + temp1 + "S";
73 temp2 = temp2 + temp1 + " ";
76 output = temp2.substr(0,temp2.length()-1);
79 virtual ~ModuleStripColor()
83 // ANSI colour stripping by Doc (Peter Wood)
84 virtual void ReplaceLine(std::string &text)
86 int i, a, len, remove;
87 char sentence[MAXBUF];
88 strncpy(sentence,text.c_str(),MAXBUF);
90 len = strlen(sentence);
92 for (i = 0; i < len; i++)
109 if (isdigit(sentence[i + remove]))
112 if (isdigit(sentence[i + remove]))
115 if (sentence[i + remove] == ',')
119 if (isdigit(sentence[i + remove]))
129 for (a = i; a <= len; a++)
130 sentence[a] = sentence[a + remove];
138 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
141 if (target_type == TYPE_USER)
143 userrec* t = (userrec*)dest;
144 active = (strchr(t->modes,'S') > 0);
146 else if (target_type == TYPE_CHANNEL)
148 chanrec* t = (chanrec*)dest;
149 active = (t->IsCustomModeSet('S'));
153 this->ReplaceLine(text);
158 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
161 if (target_type == TYPE_USER)
163 userrec* t = (userrec*)dest;
164 active = (strchr(t->modes,'S') > 0);
166 else if (target_type == TYPE_CHANNEL)
168 chanrec* t = (chanrec*)dest;
169 active = (t->IsCustomModeSet('S'));
173 this->ReplaceLine(text);
178 virtual Version GetVersion()
180 // This is version 2 because version 1.x is the unreleased unrealircd module
181 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
186 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
188 class ModuleStripColorFactory : public ModuleFactory
191 ModuleStripColorFactory()
195 ~ModuleStripColorFactory()
199 virtual Module * CreateModule(Server* Me)
201 return new ModuleStripColor(Me);
207 extern "C" void * init_module( void )
209 return new ModuleStripColorFactory;