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 * ---------------------------------------------------
16 #include "inspircd_config.h"
24 /* $ModDesc: Attempt to block /amsg, at least some of the irritating mIRC scripts. */
26 enum BlockAction { IBLOCK_KILL, IBLOCK_KILLOPERS, IBLOCK_NOTICE, IBLOCK_NOTICEOPERS, IBLOCK_SILENT };
28 /** Holds a blocked message's details
30 class BlockedMessage : public classbase
37 BlockedMessage(const std::string &msg, const irc::string &tgt, time_t when) : message(msg), target(tgt), sent(when)
42 class ModuleBlockAmsg : public Module
48 ModuleBlockAmsg(InspIRCd* Me) : Module::Module(Me)
51 this->OnRehash(NULL,"");
54 void Implements(char* List)
56 List[I_OnRehash] = List[I_OnPreCommand] = List[I_OnCleanup] = 1;
59 virtual ~ModuleBlockAmsg()
63 virtual Version GetVersion()
65 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
68 virtual void OnRehash(userrec* user, const std::string ¶meter)
70 ConfigReader* Conf = new ConfigReader(ServerInstance);
72 ForgetDelay = Conf->ReadInteger("blockamsg", "delay", 0, false);
73 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
76 std::string act = Conf->ReadValue("blockamsg", "action", 0);
79 action = IBLOCK_NOTICE;
80 else if(act == "noticeopers")
81 action = IBLOCK_NOTICEOPERS;
82 else if(act == "silent")
83 action = IBLOCK_SILENT;
84 else if(act == "kill")
87 action = IBLOCK_KILLOPERS;
92 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
94 // Don't do anything with unregistered users, or remote ones.
95 if(!user || (user->registered != REG_ALL) || !IS_LOCAL(user))
98 // We want case insensitive command comparison.
99 // Add std::string contructor for irc::string :x
100 irc::string cmd = command.c_str();
102 if(validated && (cmd == "PRIVMSG" || cmd == "NOTICE") && (pcnt >= 2))
104 // parameters[0] should have the target(s) in it.
105 // I think it will be faster to first check if there are any commas, and if there are then try and parse it out.
106 // Most messages have a single target so...
111 // Decrement if the first target wasn't a channel.
112 if(*parameters[0] != '#')
115 for(const char* c = parameters[0]; *c; c++)
116 if((*c == ',') && *(c+1) && (*(c+1) == '#'))
119 userchans = user->chans.size();
121 // Check that this message wasn't already sent within a few seconds.
123 user->GetExt("amsgblock", m);
125 // If the message is identical and within the time.
126 // We check the target is *not* identical, that'd straying into the realms of flood control. Which isn't what we're doing...
128 // The number of target channels is equal to the number of channels the sender is on..a little suspicious.
129 // Check it's more than 1 too, or else users on one channel would have fun.
130 if((m && (m->message == parameters[1]) && (m->target != parameters[0]) && (ForgetDelay != -1) && (m->sent >= ServerInstance->Time()-ForgetDelay)) || ((targets > 1) && (targets == userchans)))
133 if(action == IBLOCK_KILLOPERS || action == IBLOCK_NOTICEOPERS)
134 ServerInstance->WriteOpers("*** %s had an /amsg or /ame denied", user->nick);
136 if(action == IBLOCK_KILL || action == IBLOCK_KILLOPERS)
137 userrec::QuitUser(ServerInstance, user, "Global message (/amsg or /ame) detected");
138 else if(action == IBLOCK_NOTICE || action == IBLOCK_NOTICEOPERS)
139 user->WriteServ( "NOTICE %s :Global message (/amsg or /ame) detected", user->nick);
146 // If there's already a BlockedMessage allocated, use it.
147 m->message = parameters[1];
148 m->target = parameters[0];
149 m->sent = ServerInstance->Time();
153 m = new BlockedMessage(parameters[1], parameters[0], ServerInstance->Time());
154 user->Extend("amsgblock", (char*)m);
160 void OnCleanup(int target_type, void* item)
162 if(target_type == TYPE_USER)
164 userrec* user = (userrec*)item;
166 user->GetExt("amsgblock", m);
170 user->Shrink("amsgblock");
177 class ModuleBlockAmsgFactory : public ModuleFactory
180 ModuleBlockAmsgFactory()
184 ~ModuleBlockAmsgFactory()
188 virtual Module * CreateModule(InspIRCd* Me)
190 return new ModuleBlockAmsg(Me);
195 extern "C" void * init_module( void )
197 return new ModuleBlockAmsgFactory;