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 * ---------------------------------------------------
21 /* $ModDesc: Provides support for unreal-style channel mode +c */
23 /** Handles the +c channel mode
25 class BlockColor : public ModeHandler
28 BlockColor(InspIRCd* Instance) : ModeHandler(Instance, 'c', 0, 0, false, MODETYPE_CHANNEL, false) { }
30 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
34 if (!channel->IsModeSet('c'))
36 channel->SetMode('c',true);
37 return MODEACTION_ALLOW;
42 if (channel->IsModeSet('c'))
44 channel->SetMode('c',false);
45 return MODEACTION_ALLOW;
49 return MODEACTION_DENY;
53 class ModuleBlockColour : public Module
59 ModuleBlockColour(InspIRCd* Me) : Module::Module(Me)
62 bc = new BlockColor(ServerInstance);
63 if (!ServerInstance->AddMode(bc, 'c'))
64 throw ModuleException("Could not add new modes!");
67 void Implements(char* List)
69 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
72 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
74 if (target_type == TYPE_CHANNEL)
76 chanrec* c = (chanrec*)dest;
80 /* Replace a strlcpy(), which ran even when +c wasn't set, with this (no copies at all) -- Om */
81 for (std::string::iterator i = text.begin(); i != text.end(); i++)
91 user->WriteServ("404 %s %s :Can't send colours to channel (+c set)",user->nick, c->name);
101 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
103 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
106 virtual ~ModuleBlockColour()
108 ServerInstance->Modes->DelMode(bc);
112 virtual Version GetVersion()
114 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
119 class ModuleBlockColourFactory : public ModuleFactory
122 ModuleBlockColourFactory()
126 ~ModuleBlockColourFactory()
130 virtual Module * CreateModule(InspIRCd* Me)
132 return new ModuleBlockColour(Me);
138 extern "C" void * init_module( void )
140 return new ModuleBlockColourFactory;