]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibear.cpp
e429f5c569bd21ab5b9352c578baef11f0bd848b
[user/henk/code/inspircd.git] / src / modules / m_antibear.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "xline.h"
16
17 /* $ModDesc: Sends a numeric on connect which cripples a common type of trojan/spambot */
18
19 class ModuleAntiBear : public Module
20 {
21         LocalIntExt bearExt;
22  public:
23         ModuleAntiBear(InspIRCd* Me) : Module(Me), bearExt("antibear_timewait", this)
24         {
25                 Extensible::Register(&bearExt);
26                 Implementation eventlist[] = { I_OnUserRegister, I_OnPreCommand };
27                 ServerInstance->Modules->Attach(eventlist, this, 2);
28         }
29
30         virtual ~ModuleAntiBear()
31         {
32         }
33
34         virtual Version GetVersion()
35         {
36                 return Version("Sends a numeric on connect which cripples a common type of trojan/spambot",VF_VENDOR,API_VERSION);
37         }
38
39         virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
40         {
41                 if (command == "NOTICE" && !validated && parameters.size() > 1 && bearExt.get(user))
42                 {
43                         if (!strncmp(parameters[1].c_str(), "\1TIME Mon May 01 18:54:20 2006", 30))
44                         {
45                                 ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), 86400, ServerInstance->Config->ServerName,
46                                                 "Unless you're stuck in a time warp, you appear to be a bear bot!", user->GetIPString());
47                                 if (ServerInstance->XLines->AddLine(zl,NULL))
48                                 {
49                                         ServerInstance->XLines->ApplyLines();
50                                 }
51                                 else
52                                         delete zl;
53
54                                 return MOD_RES_DENY;
55                         }
56
57                         bearExt.set(user, 0);
58                         // Block the command, so the user doesn't receive a no such nick notice
59                         return MOD_RES_DENY;
60                 }
61
62                 return MOD_RES_PASSTHRU;
63         }
64
65         virtual ModResult OnUserRegister(User* user)
66         {
67                 user->WriteNumeric(439, "%s :This server has anti-spambot mechanisms enabled.", user->nick.c_str());
68                 user->WriteNumeric(931, "%s :Malicious bots, spammers, and other automated systems of dubious origin are NOT welcome here.", user->nick.c_str());
69                 user->WriteServ("PRIVMSG %s :\1TIME\1", user->nick.c_str());
70                 bearExt.set(user, 1);
71                 return MOD_RES_PASSTHRU;
72         }
73 };
74
75 MODULE_INIT(ModuleAntiBear)