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 * ---------------------------------------------------
24 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
26 /** Handles channel mode +S
28 class ChannelStripColor : public ModeHandler
31 ChannelStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_CHANNEL, false) { }
33 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
35 /* Only opers can change other users modes */
36 if ((source != dest) && (!*source->oper))
37 return MODEACTION_DENY;
41 if (!channel->IsModeSet('S'))
43 channel->SetMode('S',true);
44 return MODEACTION_ALLOW;
49 if (channel->IsModeSet('S'))
51 channel->SetMode('S',false);
52 return MODEACTION_ALLOW;
56 return MODEACTION_DENY;
60 class UserStripColor : public ModeHandler
63 UserStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_USER, false) { }
65 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
67 /* Only opers can change other users modes */
68 if ((source != dest) && (!*source->oper))
69 return MODEACTION_DENY;
73 if (!dest->IsModeSet('S'))
75 dest->SetMode('S',true);
76 return MODEACTION_ALLOW;
81 if (dest->IsModeSet('S'))
83 dest->SetMode('S',false);
84 return MODEACTION_ALLOW;
88 return MODEACTION_DENY;
93 class ModuleStripColor : public Module
96 ConfigReader *Conf, *MyConf;
97 ChannelStripColor *csc;
101 ModuleStripColor(InspIRCd* Me)
106 usc = new UserStripColor(ServerInstance);
107 csc = new ChannelStripColor(ServerInstance);
109 ServerInstance->AddMode(usc, 'S');
110 ServerInstance->AddMode(csc, 'S');
113 void Implements(char* List)
115 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
118 virtual ~ModuleStripColor()
120 ServerInstance->Modes->DelMode(usc);
121 ServerInstance->Modes->DelMode(csc);
126 // ANSI colour stripping by Doc (Peter Wood)
127 virtual void ReplaceLine(std::string &text)
129 int i, a, len, remove;
130 char sentence[MAXBUF];
131 strlcpy(sentence,text.c_str(),MAXBUF);
135 for (i = 0; i < len; i++)
152 if (isdigit(sentence[i + remove]))
155 if (isdigit(sentence[i + remove]))
158 if (sentence[i + remove] == ',')
162 if (isdigit(sentence[i + remove]))
172 for (a = i; a <= len; a++)
173 sentence[a] = sentence[a + remove];
181 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
184 if (target_type == TYPE_USER)
186 userrec* t = (userrec*)dest;
187 active = t->modes['S'-65];
189 else if (target_type == TYPE_CHANNEL)
191 chanrec* t = (chanrec*)dest;
192 active = (t->IsModeSet('S'));
196 this->ReplaceLine(text);
201 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
203 return OnUserPreMessage(user,dest,target_type,text,status);
206 virtual Version GetVersion()
208 return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
213 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
215 class ModuleStripColorFactory : public ModuleFactory
218 ModuleStripColorFactory()
222 ~ModuleStripColorFactory()
226 virtual Module * CreateModule(InspIRCd* Me)
228 return new ModuleStripColor(Me);
234 extern "C" void * init_module( void )
236 return new ModuleStripColorFactory;