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