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: Attempt to block /amsg, at least some of the irritating mIRC scripts. */
18 enum BlockAction { IBLOCK_KILL, IBLOCK_KILLOPERS, IBLOCK_NOTICE, IBLOCK_NOTICEOPERS, IBLOCK_SILENT };
19 /* IBLOCK_NOTICE - Send a notice to the user informing them of what happened.
20 * IBLOCK_NOTICEOPERS - Send a notice to the user informing them and send an oper notice.
21 * IBLOCK_SILENT - Generate no output, silently drop messages.
22 * IBLOCK_KILL - Kill the user with the reason "Global message (/amsg or /ame) detected".
23 * IBLOCK_KILLOPERS - As above, but send an oper notice as well. This is the default.
26 /** Holds a blocked message's details
35 BlockedMessage(const std::string &msg, const irc::string &tgt, time_t when)
36 : message(msg), target(tgt), sent(when)
41 class ModuleBlockAmsg : public Module
45 SimpleExtItem<BlockedMessage> blockamsg;
48 ModuleBlockAmsg() : blockamsg("blockamsg", this)
51 ServerInstance->Extensions.Register(&blockamsg);
52 Implementation eventlist[] = { I_OnRehash, I_OnPreCommand };
53 ServerInstance->Modules->Attach(eventlist, this, 2);
57 virtual ~ModuleBlockAmsg()
61 virtual Version GetVersion()
63 return Version("Attempt to block /amsg, at least some of the irritating mIRC scripts.",VF_VENDOR);
66 virtual void OnRehash(User* user)
70 ForgetDelay = Conf.ReadInteger("blockamsg", "delay", 0, false);
72 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
75 std::string act = Conf.ReadValue("blockamsg", "action", 0);
78 action = IBLOCK_NOTICE;
79 else if(act == "noticeopers")
80 action = IBLOCK_NOTICEOPERS;
81 else if(act == "silent")
82 action = IBLOCK_SILENT;
83 else if(act == "kill")
86 action = IBLOCK_KILLOPERS;
89 virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶meters, LocalUser *user, bool validated, const std::string &original_line)
91 // Don't do anything with unregistered users, or remote ones.
92 if(!user || (user->registered != REG_ALL) || !IS_LOCAL(user))
93 return MOD_RES_PASSTHRU;
95 // We want case insensitive command comparison.
96 // Add std::string contructor for irc::string :x
97 irc::string cmd = command.c_str();
99 if(validated && (cmd == "PRIVMSG" || cmd == "NOTICE") && (parameters.size() >= 2))
101 // parameters[0] should have the target(s) in it.
102 // I think it will be faster to first check if there are any commas, and if there are then try and parse it out.
103 // Most messages have a single target so...
108 if(*parameters[0].c_str() != '#')
110 // Decrement if the first target wasn't a channel.
114 for(const char* c = parameters[0].c_str(); *c; c++)
115 if((*c == ',') && *(c+1) && (*(c+1) == '#'))
118 /* targets should now contain the number of channel targets the msg/notice was pointed at.
119 * If the msg/notice was a PM there should be no channel targets and 'targets' should = 0.
120 * We don't want to block PMs so...
124 return MOD_RES_PASSTHRU;
127 userchans = user->chans.size();
129 // Check that this message wasn't already sent within a few seconds.
130 BlockedMessage* m = blockamsg.get(user);
132 // If the message is identical and within the time.
133 // We check the target is *not* identical, that'd straying into the realms of flood control. Which isn't what we're doing...
135 // The number of target channels is equal to the number of channels the sender is on..a little suspicious.
136 // Check it's more than 1 too, or else users on one channel would have fun.
137 if((m && (m->message == parameters[1]) && (m->target != parameters[0]) && (ForgetDelay != -1) && (m->sent >= ServerInstance->Time()-ForgetDelay)) || ((targets > 1) && (targets == userchans)))
140 if(action == IBLOCK_KILLOPERS || action == IBLOCK_NOTICEOPERS)
141 ServerInstance->SNO->WriteToSnoMask('a', "%s had an /amsg or /ame denied", user->nick.c_str());
143 if(action == IBLOCK_KILL || action == IBLOCK_KILLOPERS)
144 ServerInstance->Users->QuitUser(user, "Attempted to global message (/amsg or /ame)");
145 else if(action == IBLOCK_NOTICE || action == IBLOCK_NOTICEOPERS)
146 user->WriteServ( "NOTICE %s :Global message (/amsg or /ame) denied", user->nick.c_str());
153 // If there's already a BlockedMessage allocated, use it.
154 m->message = parameters[1];
155 m->target = parameters[0].c_str();
156 m->sent = ServerInstance->Time();
160 m = new BlockedMessage(parameters[1], parameters[0].c_str(), ServerInstance->Time());
161 blockamsg.set(user, m);
164 return MOD_RES_PASSTHRU;
169 MODULE_INIT(ModuleBlockAmsg)