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)
37 if (!channel->IsModeSet('S'))
39 channel->SetMode('S',true);
40 return MODEACTION_ALLOW;
45 if (channel->IsModeSet('S'))
47 channel->SetMode('S',false);
48 return MODEACTION_ALLOW;
52 return MODEACTION_DENY;
56 /** Handles user mode +S
58 class UserStripColor : public ModeHandler
61 UserStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_USER, false) { }
63 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
65 /* Only opers can change other users modes */
66 if ((source != dest) && (!*source->oper))
67 return MODEACTION_DENY;
71 if (!dest->IsModeSet('S'))
73 dest->SetMode('S',true);
74 return MODEACTION_ALLOW;
79 if (dest->IsModeSet('S'))
81 dest->SetMode('S',false);
82 return MODEACTION_ALLOW;
86 return MODEACTION_DENY;
91 class ModuleStripColor : public Module
94 ConfigReader *Conf, *MyConf;
95 ChannelStripColor *csc;
99 ModuleStripColor(InspIRCd* Me)
104 usc = new UserStripColor(ServerInstance);
105 csc = new ChannelStripColor(ServerInstance);
107 ServerInstance->AddMode(usc, 'S');
108 ServerInstance->AddMode(csc, 'S');
111 void Implements(char* List)
113 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
116 virtual ~ModuleStripColor()
118 ServerInstance->Modes->DelMode(usc);
119 ServerInstance->Modes->DelMode(csc);
124 // ANSI colour stripping by Doc (Peter Wood)
125 virtual void ReplaceLine(std::string &text)
127 int i, a, len, remove;
128 char sentence[MAXBUF];
129 strlcpy(sentence,text.c_str(),MAXBUF);
133 for (i = 0; i < len; i++)
150 if (isdigit(sentence[i + remove]))
153 if (isdigit(sentence[i + remove]))
156 if (sentence[i + remove] == ',')
160 if (isdigit(sentence[i + remove]))
170 for (a = i; a <= len; a++)
171 sentence[a] = sentence[a + remove];
179 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
182 if (target_type == TYPE_USER)
184 userrec* t = (userrec*)dest;
185 active = t->modes['S'-65];
187 else if (target_type == TYPE_CHANNEL)
189 chanrec* t = (chanrec*)dest;
190 active = (t->IsModeSet('S'));
194 this->ReplaceLine(text);
199 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
201 return OnUserPreMessage(user,dest,target_type,text,status);
204 virtual Version GetVersion()
206 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
211 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
213 class ModuleStripColorFactory : public ModuleFactory
216 ModuleStripColorFactory()
220 ~ModuleStripColorFactory()
224 virtual Module * CreateModule(InspIRCd* Me)
226 return new ModuleStripColor(Me);
232 extern "C" void * init_module( void )
234 return new ModuleStripColorFactory;