1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 * ---------------------------------------------------
20 /* $ModDesc: Attempt to block /amsg, at least some of the irritating mIRC scripts. */
22 enum BlockAction { IBLOCK_KILL, IBLOCK_KILLOPERS, IBLOCK_NOTICE, IBLOCK_NOTICEOPERS, IBLOCK_SILENT };
23 /* IBLOCK_NOTICE - Send a notice to the user informing them of what happened.
24 * IBLOCK_NOTICEOPERS - Send a notice to the user informing them and send an oper notice.
25 * IBLOCK_SILENT - Generate no output, silently drop messages.
26 * IBLOCK_KILL - Kill the user with the reason "Global message (/amsg or /ame) detected".
27 * IBLOCK_KILLOPERS - As above, but send an oper notice as well. This is the default.
30 /** Holds a blocked message's details
32 class BlockedMessage : public classbase
39 BlockedMessage(const std::string &msg, const irc::string &tgt, time_t when)
40 : message(msg), target(tgt), sent(when)
45 class ModuleBlockAmsg : public Module
51 ModuleBlockAmsg(InspIRCd* Me)
55 this->OnRehash(NULL,"");
58 void Implements(char* List)
60 List[I_OnRehash] = List[I_OnPreCommand] = List[I_OnCleanup] = 1;
63 virtual ~ModuleBlockAmsg()
67 virtual Version GetVersion()
69 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
72 virtual void OnRehash(userrec* user, const std::string ¶meter)
74 ConfigReader Conf(ServerInstance);
76 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;
95 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
97 // Don't do anything with unregistered users, or remote ones.
98 if(!user || (user->registered != REG_ALL) || !IS_LOCAL(user))
101 // We want case insensitive command comparison.
102 // Add std::string contructor for irc::string :x
103 irc::string cmd = command.c_str();
105 if(validated && (cmd == "PRIVMSG" || cmd == "NOTICE") && (pcnt >= 2))
107 // parameters[0] should have the target(s) in it.
108 // I think it will be faster to first check if there are any commas, and if there are then try and parse it out.
109 // Most messages have a single target so...
114 if(*parameters[0] != '#')
116 // Decrement if the first target wasn't a channel.
120 for(const char* c = parameters[0]; *c; c++)
121 if((*c == ',') && *(c+1) && (*(c+1) == '#'))
124 /* targets should now contain the number of channel targets the msg/notice was pointed at.
125 * If the msg/notice was a PM there should be no channel targets and 'targets' should = 0.
126 * We don't want to block PMs so...
133 userchans = user->chans.size();
135 // Check that this message wasn't already sent within a few seconds.
137 user->GetExt("amsgblock", m);
139 // If the message is identical and within the time.
140 // We check the target is *not* identical, that'd straying into the realms of flood control. Which isn't what we're doing...
142 // The number of target channels is equal to the number of channels the sender is on..a little suspicious.
143 // Check it's more than 1 too, or else users on one channel would have fun.
144 if((m && (m->message == parameters[1]) && (m->target != parameters[0]) && (ForgetDelay != -1) && (m->sent >= ServerInstance->Time()-ForgetDelay)) || ((targets > 1) && (targets == userchans)))
147 if(action == IBLOCK_KILLOPERS || action == IBLOCK_NOTICEOPERS)
148 ServerInstance->WriteOpers("*** %s had an /amsg or /ame denied", user->nick);
150 if(action == IBLOCK_KILL || action == IBLOCK_KILLOPERS)
151 userrec::QuitUser(ServerInstance, user, "Global message (/amsg or /ame) detected");
152 else if(action == IBLOCK_NOTICE || action == IBLOCK_NOTICEOPERS)
153 user->WriteServ( "NOTICE %s :Global message (/amsg or /ame) detected", user->nick);
160 // If there's already a BlockedMessage allocated, use it.
161 m->message = parameters[1];
162 m->target = parameters[0];
163 m->sent = ServerInstance->Time();
167 m = new BlockedMessage(parameters[1], parameters[0], ServerInstance->Time());
168 user->Extend("amsgblock", (char*)m);
174 void OnCleanup(int target_type, void* item)
176 if(target_type == TYPE_USER)
178 userrec* user = (userrec*)item;
180 user->GetExt("amsgblock", m);
184 user->Shrink("amsgblock");
191 MODULE_INIT(ModuleBlockAmsg)