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