1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
21 /** Handles channel mode +S
23 class ChannelStripColor : public ModeHandler
26 ChannelStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_CHANNEL, false) { }
28 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
32 if (!channel->IsModeSet('S'))
34 channel->SetMode('S',true);
35 return MODEACTION_ALLOW;
40 if (channel->IsModeSet('S'))
42 channel->SetMode('S',false);
43 return MODEACTION_ALLOW;
47 return MODEACTION_DENY;
51 /** Handles user mode +S
53 class UserStripColor : public ModeHandler
56 UserStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_USER, false) { }
58 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
60 /* Only opers can change other users modes */
61 if ((source != dest) && (!*source->oper))
62 return MODEACTION_DENY;
66 if (!dest->IsModeSet('S'))
68 dest->SetMode('S',true);
69 return MODEACTION_ALLOW;
74 if (dest->IsModeSet('S'))
76 dest->SetMode('S',false);
77 return MODEACTION_ALLOW;
81 return MODEACTION_DENY;
86 class ModuleStripColor : public Module
89 ConfigReader *Conf, *MyConf;
90 ChannelStripColor *csc;
94 ModuleStripColor(InspIRCd* Me)
99 usc = new UserStripColor(ServerInstance);
100 csc = new ChannelStripColor(ServerInstance);
102 if (!ServerInstance->AddMode(usc, 'S') || !ServerInstance->AddMode(csc, 'S'))
103 throw ModuleException("Could not add new modes!");
106 void Implements(char* List)
108 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
111 virtual ~ModuleStripColor()
113 ServerInstance->Modes->DelMode(usc);
114 ServerInstance->Modes->DelMode(csc);
119 // ANSI colour stripping by Doc (Peter Wood)
120 virtual void ReplaceLine(std::string &text)
122 int i, a, len, remove;
123 char sentence[MAXBUF];
124 strlcpy(sentence,text.c_str(),MAXBUF);
128 for (i = 0; i < len; i++)
145 if (isdigit(sentence[i + remove]))
148 if (isdigit(sentence[i + remove]))
151 if (sentence[i + remove] == ',')
155 if (isdigit(sentence[i + remove]))
165 for (a = i; a <= len; a++)
166 sentence[a] = sentence[a + remove];
174 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
180 if (target_type == TYPE_USER)
182 userrec* t = (userrec*)dest;
183 active = t->modes['S'-65];
185 else if (target_type == TYPE_CHANNEL)
187 chanrec* t = (chanrec*)dest;
188 active = (t->IsModeSet('S'));
192 this->ReplaceLine(text);
197 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
199 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
202 virtual Version GetVersion()
204 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
209 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
211 class ModuleStripColorFactory : public ModuleFactory
214 ModuleStripColorFactory()
218 ~ModuleStripColorFactory()
222 virtual Module * CreateModule(InspIRCd* Me)
224 return new ModuleStripColor(Me);
230 extern "C" void * init_module( void )
232 return new ModuleStripColorFactory;