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 * ---------------------------------------------------
16 /* $ModDesc: Provides support for channel mode +P to block all-CAPS channel messages and notices */
19 /** Handles the +P channel mode
21 class BlockCaps : public ModeHandler
24 BlockCaps(InspIRCd* Instance) : ModeHandler(Instance, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
26 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
30 if (!channel->IsModeSet('P'))
32 channel->SetMode('P',true);
33 return MODEACTION_ALLOW;
38 if (channel->IsModeSet('P'))
40 channel->SetMode('P',false);
41 return MODEACTION_ALLOW;
45 return MODEACTION_DENY;
49 class ModuleBlockCAPS : public Module
57 ModuleBlockCAPS(InspIRCd* Me) : Module(Me)
60 bc = new BlockCaps(ServerInstance);
61 if (!ServerInstance->AddMode(bc, 'P'))
62 throw ModuleException("Could not add new modes!");
65 void Implements(char* List)
67 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
70 virtual void OnRehash(userrec* user, const std::string ¶m)
75 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
77 if (target_type == TYPE_CHANNEL)
79 if ((!IS_LOCAL(user)) || (text.length() < minlen))
82 chanrec* c = (chanrec*)dest;
84 if (c->IsModeSet('P'))
87 for (std::string::iterator i = text.begin(); i != text.end(); i++)
88 caps += capsmap[(unsigned char)*i];
89 if ( ((caps*100)/(int)text.length()) >= percent )
91 user->WriteServ( "404 %s %s :Your line cannot be more than %d%% capital letters if it is %d or more letters long", user->nick, c->name, percent, minlen);
99 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
101 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
106 ConfigReader Conf(ServerInstance);
107 percent = Conf.ReadInteger("blockcaps", "percent", "100", 0, true);
108 minlen = Conf.ReadInteger("blockcaps", "minlen", "0", 0, true);
109 std::string hmap = Conf.ReadValue("blockcaps", "capsmap", 0);
111 hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
112 memset(&capsmap, 0, 255);
113 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
114 capsmap[(unsigned char)*n] = 1;
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);
139 MODULE_INIT(ModuleBlockCAPS)