]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands.cpp
Show IP of the user in the quit snomask [dKingston]
[user/henk/code/inspircd.git] / src / commands.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 /* $Core */
15
16 #include "inspircd.h"
17 #include "xline.h"
18 #include "command_parse.h"
19
20 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
21
22 bool InspIRCd::HostMatchesEveryone(const std::string &mask, User* user)
23 {
24         long matches = 0;
25
26         ConfigTag* insane = Config->ConfValue("insane");
27
28         if (!insane || !insane->getBool("hostmasks"))
29                 return false;
30
31         float itrigger = insane->getFloat("trigger", 95.5);
32
33         for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
34         {
35                 if ((InspIRCd::Match(u->second->MakeHost(), mask, ascii_case_insensitive_map)) ||
36                     (InspIRCd::Match(u->second->MakeHostIP(), mask, ascii_case_insensitive_map)))
37                 {
38                         matches++;
39                 }
40         }
41
42         if (!matches)
43                 return false;
44
45         float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100;
46         if (percent > itrigger)
47         {
48                 SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a G/K/E line mask of %s, which covers %.2f%% of the network!",user->nick.c_str(),mask.c_str(),percent);
49                 return true;
50         }
51         return false;
52 }
53
54 bool InspIRCd::IPMatchesEveryone(const std::string &ip, User* user)
55 {
56         long matches = 0;
57
58         ConfigTag* insane = Config->ConfValue("insane");
59
60         if (!insane || !insane->getBool("ipmasks"))
61                 return false;
62
63         float itrigger = insane->getFloat("trigger", 95.5);
64
65         for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
66         {
67                 if (InspIRCd::Match(u->second->GetIPString(), ip, ascii_case_insensitive_map))
68                         matches++;
69         }
70
71         if (!matches)
72                 return false;
73
74         float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100;
75         if (percent > itrigger)
76         {
77                 SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a Z line mask of %s, which covers %.2f%% of the network!",user->nick.c_str(),ip.c_str(),percent);
78                 return true;
79         }
80         return false;
81 }
82
83 bool InspIRCd::NickMatchesEveryone(const std::string &nick, User* user)
84 {
85         long matches = 0;
86
87         ConfigTag* insane = Config->ConfValue("insane");
88
89         if (!insane || !insane->getBool("nickmasks"))
90                 return false;
91
92         float itrigger = insane->getFloat("trigger", 95.5);
93
94         for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
95         {
96                 if (InspIRCd::Match(u->second->nick, nick))
97                         matches++;
98         }
99
100         if (!matches)
101                 return false;
102
103         float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100;
104         if (percent > itrigger)
105         {
106                 SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a Q line mask of %s, which covers %.2f%% of the network!",user->nick.c_str(),nick.c_str(),percent);
107                 return true;
108         }
109         return false;
110 }
111
112 CmdResult SplitCommand::Handle(const std::vector<std::string>& parms, User* u)
113 {
114         if (IS_LOCAL(u))
115                 return HandleLocal(parms, IS_LOCAL(u));
116         if (IS_REMOTE(u))
117                 return HandleRemote(parms, IS_REMOTE(u));
118         if (IS_SERVER(u))
119                 return HandleServer(parms, IS_SERVER(u));
120         ServerInstance->Logs->Log("COMMAND", ERROR, "Unknown user type in command (uuid=%s)!", u->uuid.c_str());
121         return CMD_INVALID;
122 }
123
124 CmdResult SplitCommand::HandleLocal(const std::vector<std::string>&, LocalUser*)
125 {
126         return CMD_INVALID;
127 }
128
129 CmdResult SplitCommand::HandleRemote(const std::vector<std::string>&, RemoteUser*)
130 {
131         return CMD_INVALID;
132 }
133
134 CmdResult SplitCommand::HandleServer(const std::vector<std::string>&, FakeUser*)
135 {
136         return CMD_INVALID;
137 }
138