]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibear.cpp
925ec23149278eb1eae245bfb1329c33879242cd
[user/henk/code/inspircd.git] / src / modules / m_antibear.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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  private:
22
23  public:
24         ModuleAntiBear(InspIRCd* Me) : Module(Me)
25         {
26                 
27                 Implementation eventlist[] = { I_OnUserRegister, I_OnPreCommand };
28                 ServerInstance->Modules->Attach(eventlist, this, 2);
29         }
30         
31         virtual ~ModuleAntiBear()
32         {
33         }
34         
35         virtual Version GetVersion()
36         {
37                 return Version(1,2,0,0,VF_VENDOR,API_VERSION);
38         }
39
40         virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
41         {
42                 if (command == "NOTICE" && !validated && parameters.size() > 1 && user->GetExt("antibear_timewait"))
43                 {
44                         if (!strncmp(parameters[1].c_str(), "\1TIME Mon May 01 18:54:20 2006", 30))
45                         {
46                                 ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), 86400, ServerInstance->Config->ServerName,
47                                                 "Unless you're stuck in a time warp, you appear to be a bear bot!", user->GetIPString());
48                                 if (ServerInstance->XLines->AddLine(zl,NULL))
49                                 {
50                                         ServerInstance->XLines->ApplyLines();
51                                 }
52                                 else
53                                         delete zl;
54
55                                 return 1;
56                         }
57                         
58                         user->Shrink("antibear_timewait");
59                         // Block the command, so the user doesn't receive a no such nick notice
60                         return 1;
61                 }
62                 
63                 return 0;
64         }
65
66         virtual int OnUserRegister(User* user)
67         {
68                 user->WriteNumeric(439, "%s :This server has anti-spambot mechanisms enabled.", user->nick.c_str());
69                 user->WriteNumeric(931, "%s :Malicious bots, spammers, and other automated systems of dubious origin are NOT welcome here.", user->nick.c_str());
70                 user->WriteServ("PRIVMSG %s :\1TIME\1", user->nick.c_str());
71                 user->Extend("antibear_timewait");
72                 return 0;
73         }
74 };
75
76 MODULE_INIT(ModuleAntiBear)