1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 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, 'B', 0, 0, false, MODETYPE_CHANNEL, false) { }
26 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
30 if (!channel->IsModeSet('B'))
32 channel->SetMode('B',true);
33 return MODEACTION_ALLOW;
38 if (channel->IsModeSet('B'))
40 channel->SetMode('B',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->Modes->AddMode(bc))
64 throw ModuleException("Could not add new modes!");
66 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash };
67 ServerInstance->Modules->Attach(eventlist, this, 3);
71 virtual void OnRehash(User* user, const std::string ¶m)
76 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
78 if (target_type == TYPE_CHANNEL)
80 if ((!IS_LOCAL(user)) || (text.length() < minlen))
83 Channel* c = (Channel*)dest;
85 if (CHANOPS_EXEMPT(ServerInstance, 'B') && c->GetStatus(user) == STATUS_OP)
90 if (c->IsModeSet('B'))
93 for (std::string::iterator i = text.begin(); i != text.end(); i++)
94 caps += capsmap[(unsigned char)*i];
95 if ( ((caps*100)/(int)text.length()) >= percent )
97 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);
105 virtual int OnUserPreNotice(User* 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", "1", 0, true);
115 std::string hmap = Conf.ReadValue("blockcaps", "capsmap", 0);
117 hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
118 memset(&capsmap, 0, 255);
119 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
120 capsmap[(unsigned char)*n] = 1;
121 if (percent < 1 || percent > 100)
123 ServerInstance->Logs->Log("CONFIG",DEFAULT, "<blockcaps:percent> out of range, setting to default of 100.");
126 if (minlen < 1 || minlen > MAXBUF-1)
128 ServerInstance->Logs->Log("CONFIG",DEFAULT, "<blockcaps:minlen> out of range, setting to default of 1.");
133 virtual ~ModuleBlockCAPS()
135 ServerInstance->Modes->DelMode(bc);
139 virtual Version GetVersion()
141 return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
145 MODULE_INIT(ModuleBlockCAPS)