1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
11 * Written by Craig Edwards, Craig McLure, and others.
12 * This program is free but copyrighted software; see
13 * the file COPYING for details.
15 * ---------------------------------------------------
18 /* <3's to Lauren for original info on mIRC's weird behaviour */
22 #include "inspircd_config.h"
26 #include "helperfuncs.h"
29 /* $ModDesc: Attempt to block /amsg, at least some of the irritating mIRC scripts. */
33 enum BlockAction { IBLOCK_KILL, IBLOCK_KILLOPERS, IBLOCK_NOTICE, IBLOCK_NOTICEOPERS, IBLOCK_SILENT };
42 BlockedMessage(std::string msg, irc::string tgt, time_t when) : message(msg), target(tgt), sent(when)
47 class ModuleBlockAmsg : public Module
53 ModuleBlockAmsg(Server* Me) : Module::Module(Me)
59 void Implements(char* List)
61 List[I_OnRehash] = List[I_OnPreCommand] = List[I_OnCleanup] = 1;
64 virtual ~ModuleBlockAmsg()
68 virtual Version GetVersion()
70 return Version(1,0,0,0,VF_VENDOR);
73 virtual void OnRehash(std::string parameter)
75 ConfigReader* Conf = new ConfigReader;
77 ForgetDelay = Conf->ReadInteger("blockamsg", "delay", 0, false);
78 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
81 std::string act = Conf->ReadValue("blockamsg", "action", 0);
84 action = IBLOCK_NOTICE;
85 else if(act == "noticeopers")
86 action = IBLOCK_NOTICEOPERS;
87 else if(act == "silent")
88 action = IBLOCK_SILENT;
89 else if(act == "kill")
92 action = IBLOCK_KILLOPERS;
97 virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated)
99 // Don't do anything with unregistered users, or remote ones.
100 if(!user || (user->registered != 7) || !IS_LOCAL(user))
103 // We want case insensitive command comparison.
104 // Add std::string contructor for irc::string :x
105 irc::string cmd = command.c_str();
107 if(validated && (cmd == "PRIVMSG" || cmd == "NOTICE") && (pcnt >= 2))
109 // parameters[0] should have the target(s) in it.
110 // I think it will be faster to first check if there are any commas, and if there are then try and parse it out.
111 // Most messages have a single target so...
116 // Decrement if the first target wasn't a channel.
117 if(*parameters[0] != '#')
120 for(char* c = parameters[0]; *c; c++)
121 if((*c == ',') && *(c+1) && (*(c+1) == '#'))
124 for(unsigned int i = 0; i < user->chans.size(); i++)
125 if(user->chans[i].channel)
128 // Check that this message wasn't already sent within a few seconds.
129 BlockedMessage* m = (BlockedMessage*)user->GetExt("amsgblock");
131 // If the message is identical and within the time.
132 // We check the target is *not* identical, that'd straying into the realms of flood control. Which isn't what we're doing...
134 // The number of target channels is equal to the number of channels the sender is on..a little suspicious.
135 // Check it's more than 1 too, or else users on one channel would have fun.
136 if((m && (m->message == parameters[1]) && (m->target != parameters[0]) && (ForgetDelay != -1) && (m->sent >= TIME-ForgetDelay)) || ((targets > 1) && (targets == userchans)))
139 if(action == IBLOCK_KILLOPERS || action == IBLOCK_NOTICEOPERS)
140 WriteOpers("*** %s had an /amsg or /ame denied", user->nick);
142 if(action == IBLOCK_KILL || action == IBLOCK_KILLOPERS)
143 Srv->QuitUser(user, "Global message (/amsg or /ame) detected");
144 else if(action == IBLOCK_NOTICE || action == IBLOCK_NOTICEOPERS)
145 WriteServ(user->fd, "NOTICE %s :Global message (/amsg or /ame) detected", user->nick);
152 // If there's already a BlockedMessage allocated, use it.
153 m->message = parameters[1];
154 m->target = parameters[0];
159 m = new BlockedMessage(parameters[1], parameters[0], TIME);
160 user->Extend("amsgblock", (char*)m);
166 void OnCleanup(int target_type, void* item)
168 if(target_type == TYPE_USER)
170 userrec* user = (userrec*)item;
171 BlockedMessage* m = (BlockedMessage*)user->GetExt("amsgblock");
175 user->Shrink("amsgblock");
182 class ModuleBlockAmsgFactory : public ModuleFactory
185 ModuleBlockAmsgFactory()
189 ~ModuleBlockAmsgFactory()
193 virtual Module * CreateModule(Server* Me)
195 return new ModuleBlockAmsg(Me);
200 extern "C" void * init_module( void )
202 return new ModuleBlockAmsgFactory;