1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 +P channel mode
21 class BlockCaps : public SimpleChannelModeHandler
24 BlockCaps(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'B') { }
27 class ModuleBlockCAPS : public Module
35 ModuleBlockCAPS(InspIRCd* Me) : Module(Me)
38 bc = new BlockCaps(ServerInstance);
39 if (!ServerInstance->Modes->AddMode(bc))
42 throw ModuleException("Could not add new modes!");
44 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_On005Numeric };
45 ServerInstance->Modules->Attach(eventlist, this, 4);
48 virtual void On005Numeric(std::string &output)
50 ServerInstance->AddExtBanChar('B');
53 virtual void OnRehash(User* user, const std::string ¶m)
58 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
60 if (target_type == TYPE_CHANNEL)
62 if ((!IS_LOCAL(user)) || (text.length() < minlen))
65 Channel* c = (Channel*)dest;
67 if (CHANOPS_EXEMPT(ServerInstance, 'B') && c->GetStatus(user) == STATUS_OP)
72 if (c->IsModeSet('B') || c->GetExtBanStatus(user, 'B') < 0)
75 const char* actstr = "\1ACTION ";
78 for (std::string::iterator i = text.begin(); i != text.end(); i++)
80 /* Smart fix for suggestion from Jobe, ignore CTCP ACTION (part of /ME) */
81 if (*actstr && *i == *actstr++ && act != -1)
89 caps += capsmap[(unsigned char)*i];
91 if ( ((caps*100)/(int)text.length()) >= percent )
93 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);
101 virtual int OnUserPreNotice(User* 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);
108 ConfigReader Conf(ServerInstance);
109 percent = Conf.ReadInteger("blockcaps", "percent", "100", 0, true);
110 minlen = Conf.ReadInteger("blockcaps", "minlen", "1", 0, true);
111 std::string hmap = Conf.ReadValue("blockcaps", "capsmap", 0);
113 hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
114 memset(capsmap, 0, sizeof(capsmap));
115 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
116 capsmap[(unsigned char)*n] = 1;
117 if (percent < 1 || percent > 100)
119 ServerInstance->Logs->Log("CONFIG",DEFAULT, "<blockcaps:percent> out of range, setting to default of 100.");
122 if (minlen < 1 || minlen > MAXBUF-1)
124 ServerInstance->Logs->Log("CONFIG",DEFAULT, "<blockcaps:minlen> out of range, setting to default of 1.");
129 virtual ~ModuleBlockCAPS()
131 ServerInstance->Modes->DelMode(bc);
135 virtual Version GetVersion()
137 return Version("$Id$", VF_COMMON|VF_VENDOR,API_VERSION);
141 MODULE_INIT(ModuleBlockCAPS)