1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides support to block all-CAPS channel messages and notices */
19 /** Handles the +B channel mode
21 class BlockCaps : public SimpleChannelModeHandler
24 BlockCaps(Module* Creator) : SimpleChannelModeHandler(Creator, "blockcaps", 'B') { }
27 class ModuleBlockCAPS : public Module
35 ModuleBlockCAPS() : bc(this)
38 if (!ServerInstance->Modes->AddMode(&bc))
39 throw ModuleException("Could not add new modes!");
40 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_On005Numeric };
41 ServerInstance->Modules->Attach(eventlist, this, 4);
44 virtual void On005Numeric(std::string &output)
46 ServerInstance->AddExtBanChar('B');
49 virtual void OnRehash(User* user)
54 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
56 if (target_type == TYPE_CHANNEL)
58 if ((!IS_LOCAL(user)) || (text.length() < minlen))
59 return MOD_RES_PASSTHRU;
61 Channel* c = (Channel*)dest;
62 ModResult res = ServerInstance->OnCheckExemption(user,c,"blockcaps");
64 if (res == MOD_RES_ALLOW)
65 return MOD_RES_PASSTHRU;
67 if (!c->GetExtBanStatus(user, 'B').check(!c->IsModeSet('B')))
70 const char* actstr = "\1ACTION ";
73 for (std::string::iterator i = text.begin(); i != text.end(); i++)
75 /* Smart fix for suggestion from Jobe, ignore CTCP ACTION (part of /ME) */
76 if (*actstr && *i == *actstr++ && act != -1)
84 caps += capsmap[(unsigned char)*i];
86 if ( ((caps*100)/(int)text.length()) >= percent )
88 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s %s :Your message cannot contain more than %d%% capital letters if it's longer than %d characters", user->nick.c_str(), c->name.c_str(), percent, minlen);
93 return MOD_RES_PASSTHRU;
96 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
98 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
104 percent = Conf.ReadInteger("blockcaps", "percent", "100", 0, true);
105 minlen = Conf.ReadInteger("blockcaps", "minlen", "1", 0, true);
106 std::string hmap = Conf.ReadValue("blockcaps", "capsmap", 0);
108 hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
109 memset(capsmap, 0, sizeof(capsmap));
110 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
111 capsmap[(unsigned char)*n] = 1;
112 if (percent < 1 || percent > 100)
114 ServerInstance->Logs->Log("CONFIG",DEFAULT, "<blockcaps:percent> out of range, setting to default of 100.");
117 if (minlen < 1 || minlen > MAXBUF-1)
119 ServerInstance->Logs->Log("CONFIG",DEFAULT, "<blockcaps:minlen> out of range, setting to default of 1.");
124 virtual ~ModuleBlockCAPS()
128 virtual Version GetVersion()
130 return Version("Provides support to block all-CAPS channel messages and notices", VF_VENDOR);
134 MODULE_INIT(ModuleBlockCAPS)