]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands.cpp
Debug to try figure this out ..
[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 #include "inspircd.h"
15 #include "wildcard.h"
16 #include "xline.h"
17 #include "command_parse.h"
18
19 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
20
21 bool InspIRCd::HostMatchesEveryone(const std::string &mask, userrec* user)
22 {
23         char itrigger[MAXBUF];
24         long matches = 0;
25         
26         if (!Config->ConfValue(Config->config_data, "insane","trigger", 0, itrigger, MAXBUF))
27                 strlcpy(itrigger,"95.5",MAXBUF);
28         
29         if (Config->ConfValueBool(Config->config_data, "insane","hostmasks", 0))
30                 return false;
31         
32         for (user_hash::iterator u = clientlist->begin(); u != clientlist->end(); u++)
33         {
34                 if ((match(u->second->MakeHost(),mask.c_str(),true)) || (match(u->second->MakeHostIP(),mask.c_str(),true)))
35                 {
36                         matches++;
37                 }
38         }
39
40         if (!matches)
41                 return false;
42
43         float percent = ((float)matches / (float)clientlist->size()) * 100;
44         if (percent > (float)atof(itrigger))
45         {
46                 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);
47                 return true;
48         }
49         return false;
50 }
51
52 bool InspIRCd::IPMatchesEveryone(const std::string &ip, userrec* user)
53 {
54         char itrigger[MAXBUF];
55         long matches = 0;
56         
57         if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
58                 strlcpy(itrigger,"95.5",MAXBUF);
59         
60         if (Config->ConfValueBool(Config->config_data, "insane","ipmasks",0))
61                 return false;
62         
63         for (user_hash::iterator u = clientlist->begin(); u != clientlist->end(); u++)
64         {
65                 if (match(u->second->GetIPString(),ip.c_str(),true))
66                         matches++;
67         }
68
69         if (!matches)
70                 return false;
71
72         float percent = ((float)matches / (float)clientlist->size()) * 100;
73         if (percent > (float)atof(itrigger))
74         {
75                 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);
76                 return true;
77         }
78         return false;
79 }
80
81 bool InspIRCd::NickMatchesEveryone(const std::string &nick, userrec* user)
82 {
83         char itrigger[MAXBUF];
84         long matches = 0;
85         
86         if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
87                 strlcpy(itrigger,"95.5",MAXBUF);
88         
89         if (Config->ConfValueBool(Config->config_data, "insane","nickmasks",0))
90                 return false;
91
92         for (user_hash::iterator u = clientlist->begin(); u != clientlist->end(); u++)
93         {
94                 if (match(u->second->nick,nick.c_str()))
95                         matches++;
96         }
97
98         if (!matches)
99                 return false;
100
101         float percent = ((float)matches / (float)clientlist->size()) * 100;
102         if (percent > (float)atof(itrigger))
103         {
104                 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);
105                 return true;
106         }
107         return false;
108 }