]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands.cpp
4e44003850caef1d6d45963e1fa658b5ed750a8d
[user/henk/code/inspircd.git] / src / commands.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 /* $Core: libIRCDcommands */
15
16 #include "inspircd.h"
17 #include "wildcard.h"
18 #include "xline.h"
19 #include "command_parse.h"
20
21 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
22
23 bool InspIRCd::HostMatchesEveryone(const std::string &mask, User* user)
24 {
25         char itrigger[MAXBUF];
26         long matches = 0;
27         
28         if (!Config->ConfValue(Config->config_data, "insane","trigger", 0, itrigger, MAXBUF))
29                 strlcpy(itrigger,"95.5",MAXBUF);
30         
31         if (Config->ConfValueBool(Config->config_data, "insane","hostmasks", 0))
32                 return false;
33         
34         for (user_hash::iterator u = clientlist->begin(); u != clientlist->end(); u++)
35         {
36                 if ((match(u->second->MakeHost(),mask.c_str(),true)) || (match(u->second->MakeHostIP(),mask.c_str(),true)))
37                 {
38                         matches++;
39                 }
40         }
41
42         if (!matches)
43                 return false;
44
45         float percent = ((float)matches / (float)clientlist->size()) * 100;
46         if (percent > (float)atof(itrigger))
47         {
48                 WriteOpers("*** \2WARNING\2: %s tried to set a G/K/E line mask of %s, which covers %.2f%% of the network!",user->nick,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         char itrigger[MAXBUF];
57         long matches = 0;
58         
59         if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
60                 strlcpy(itrigger,"95.5",MAXBUF);
61         
62         if (Config->ConfValueBool(Config->config_data, "insane","ipmasks",0))
63                 return false;
64         
65         for (user_hash::iterator u = clientlist->begin(); u != clientlist->end(); u++)
66         {
67                 if (match(u->second->GetIPString(),ip.c_str(),true))
68                         matches++;
69         }
70
71         if (!matches)
72                 return false;
73
74         float percent = ((float)matches / (float)clientlist->size()) * 100;
75         if (percent > (float)atof(itrigger))
76         {
77                 WriteOpers("*** \2WARNING\2: %s tried to set a Z line mask of %s, which covers %.2f%% of the network!",user->nick,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         char itrigger[MAXBUF];
86         long matches = 0;
87         
88         if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
89                 strlcpy(itrigger,"95.5",MAXBUF);
90         
91         if (Config->ConfValueBool(Config->config_data, "insane","nickmasks",0))
92                 return false;
93
94         for (user_hash::iterator u = clientlist->begin(); u != clientlist->end(); u++)
95         {
96                 if (match(u->second->nick,nick.c_str()))
97                         matches++;
98         }
99
100         if (!matches)
101                 return false;
102
103         float percent = ((float)matches / (float)clientlist->size()) * 100;
104         if (percent > (float)atof(itrigger))
105         {
106                 WriteOpers("*** \2WARNING\2: %s tried to set a Q line mask of %s, which covers %.2f%% of the network!",user->nick,nick.c_str(),percent);
107                 return true;
108         }
109         return false;
110 }