]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands.cpp
Fix mistakenly using Clang instead of GCC on older FreeBSD versions.
[user/henk/code/inspircd.git] / src / commands.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6  *   Copyright (C) 2004-2007 Craig Edwards <craigedwards@brainbox.cc>
7  *   Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
8  *   Copyright (C) 2005 Craig McLure <craig@chatspike.net>
9  *
10  * This file is part of InspIRCd.  InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 /* $Core */
25
26 #include "inspircd.h"
27 #include "xline.h"
28 #include "command_parse.h"
29
30 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
31
32 bool InspIRCd::HostMatchesEveryone(const std::string &mask, User* user)
33 {
34         long matches = 0;
35
36         ConfigTag* insane = Config->ConfValue("insane");
37
38         if (insane->getBool("hostmasks"))
39                 return false;
40
41         float itrigger = insane->getFloat("trigger", 95.5);
42
43         for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
44         {
45                 if ((InspIRCd::Match(u->second->MakeHost(), mask, ascii_case_insensitive_map)) ||
46                     (InspIRCd::Match(u->second->MakeHostIP(), mask, ascii_case_insensitive_map)))
47                 {
48                         matches++;
49                 }
50         }
51
52         if (!matches)
53                 return false;
54
55         float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100;
56         if (percent > itrigger)
57         {
58                 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);
59                 return true;
60         }
61         return false;
62 }
63
64 bool InspIRCd::IPMatchesEveryone(const std::string &ip, User* user)
65 {
66         long matches = 0;
67
68         ConfigTag* insane = Config->ConfValue("insane");
69
70         if (insane->getBool("ipmasks"))
71                 return false;
72
73         float itrigger = insane->getFloat("trigger", 95.5);
74
75         for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
76         {
77                 if (InspIRCd::Match(u->second->GetIPString(), ip, ascii_case_insensitive_map))
78                         matches++;
79         }
80
81         if (!matches)
82                 return false;
83
84         float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100;
85         if (percent > itrigger)
86         {
87                 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);
88                 return true;
89         }
90         return false;
91 }
92
93 bool InspIRCd::NickMatchesEveryone(const std::string &nick, User* user)
94 {
95         long matches = 0;
96
97         ConfigTag* insane = Config->ConfValue("insane");
98
99         if (insane->getBool("nickmasks"))
100                 return false;
101
102         float itrigger = insane->getFloat("trigger", 95.5);
103
104         for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
105         {
106                 if (InspIRCd::Match(u->second->nick, nick))
107                         matches++;
108         }
109
110         if (!matches)
111                 return false;
112
113         float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100;
114         if (percent > itrigger)
115         {
116                 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);
117                 return true;
118         }
119         return false;
120 }
121
122 CmdResult SplitCommand::Handle(const std::vector<std::string>& parms, User* u)
123 {
124         if (IS_LOCAL(u))
125                 return HandleLocal(parms, IS_LOCAL(u));
126         if (IS_REMOTE(u))
127                 return HandleRemote(parms, IS_REMOTE(u));
128         if (IS_SERVER(u))
129                 return HandleServer(parms, IS_SERVER(u));
130         ServerInstance->Logs->Log("COMMAND", DEFAULT, "Unknown user type in command (uuid=%s)!", u->uuid.c_str());
131         return CMD_INVALID;
132 }
133
134 CmdResult SplitCommand::HandleLocal(const std::vector<std::string>&, LocalUser*)
135 {
136         return CMD_INVALID;
137 }
138
139 CmdResult SplitCommand::HandleRemote(const std::vector<std::string>&, RemoteUser*)
140 {
141         return CMD_INVALID;
142 }
143
144 CmdResult SplitCommand::HandleServer(const std::vector<std::string>&, FakeUser*)
145 {
146         return CMD_INVALID;
147 }
148