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 * ---------------------------------------------------
20 /* $ModDesc: Provides support for channel mode +P to block all-CAPS channel messages and notices */
23 /** Handles the +P channel mode
25 class BlockCaps : public ModeHandler
28 BlockCaps(InspIRCd* Instance) : ModeHandler(Instance, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
30 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
34 if (!channel->IsModeSet('P'))
36 channel->SetMode('P',true);
37 return MODEACTION_ALLOW;
42 if (channel->IsModeSet('P'))
44 channel->SetMode('P',false);
45 return MODEACTION_ALLOW;
49 return MODEACTION_DENY;
53 class ModuleBlockCAPS : public Module
60 ModuleBlockCAPS(InspIRCd* Me) : Module::Module(Me)
63 bc = new BlockCaps(ServerInstance);
64 if (!ServerInstance->AddMode(bc, 'P'))
65 throw ModuleException("Could not add new modes!");
68 void Implements(char* List)
70 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
73 virtual void OnRehash(userrec* user, const std::string ¶m)
78 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
80 if ((text.size() < minlen) || (!IS_LOCAL(user)))
83 if (target_type == TYPE_CHANNEL)
85 chanrec* c = (chanrec*)dest;
87 if (c->IsModeSet('P'))
90 for (std::string::iterator i = text.begin(); i != text.end(); i++)
92 if ( (*i >= 'A') && (*i <= 'Z'))
95 if ( (caps * 100 / text.size()) >= percent )
97 user->WriteServ( "404 %s %s :Can't send all-CAPS to channel (+P set)", user->nick, c->name);
105 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
107 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
112 ConfigReader Conf(ServerInstance);
113 percent = Conf.ReadInteger("blockcaps", "percent", "100", 0, true);
114 minlen = Conf.ReadInteger("blockcaps", "minlen", "0", 0, true);
115 if (percent < 0 || percent > 100)
117 ServerInstance->Log(DEFAULT, "<blockcaps:percent> out of range, setting to default of 100.");
120 if (minlen < 0 || minlen > MAXBUF-1)
122 ServerInstance->Log(DEFAULT, "<blockcaps:minlen> out of range, setting to default of 0.");
127 virtual ~ModuleBlockCAPS()
129 ServerInstance->Modes->DelMode(bc);
133 virtual Version GetVersion()
135 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
140 class ModuleBlockCAPSFactory : public ModuleFactory
143 ModuleBlockCAPSFactory()
147 ~ModuleBlockCAPSFactory()
151 virtual Module * CreateModule(InspIRCd* Me)
153 return new ModuleBlockCAPS(Me);
159 extern "C" void * init_module( void )
161 return new ModuleBlockCAPSFactory;