]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands.cpp
Hash rehashing change
[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 bool InspIRCd::ULine(const char* server)
23 {
24         if (!server)
25                 return false;
26         if (!*server)
27                 return true;
28
29         return (find(Config->ulines.begin(),Config->ulines.end(),server) != Config->ulines.end());
30 }
31
32 int InspIRCd::OperPassCompare(const char* data,const char* input, int tagnum)
33 {
34         int MOD_RESULT = 0;
35         FOREACH_RESULT_I(this,I_OnOperCompare,OnOperCompare(data, input, tagnum))
36         if (MOD_RESULT == 1)
37                 return 0;
38         if (MOD_RESULT == -1)
39                 return 1;
40         return strcmp(data,input);
41 }
42
43 long InspIRCd::Duration(const char* str)
44 {
45         char n_field[MAXBUF];
46         long total = 0;
47         n_field[0] = 0;
48
49         if ((!strchr(str,'s')) && (!strchr(str,'m')) && (!strchr(str,'h')) && (!strchr(str,'d')) && (!strchr(str,'w')) && (!strchr(str,'y')))
50         {
51                 std::string n = str;
52                 n += 's';
53                 return Duration(n.c_str());
54         }
55         
56         for (char* i = (char*)str; *i; i++)
57         {
58                 // if we have digits, build up a string for the value in n_field,
59                 // up to 10 digits in size.
60                 if ((*i >= '0') && (*i <= '9'))
61                 {
62                         strlcat(n_field,i,10);
63                 }
64                 else
65                 {
66                         // we dont have a digit, check for numeric tokens
67                         switch (tolower(*i))
68                         {
69                                 case 's':
70                                         total += atoi(n_field);
71                                 break;
72
73                                 case 'm':
74                                         total += (atoi(n_field)*duration_m);
75                                 break;
76
77                                 case 'h':
78                                         total += (atoi(n_field)*duration_h);
79                                 break;
80
81                                 case 'd':
82                                         total += (atoi(n_field)*duration_d);
83                                 break;
84
85                                 case 'w':
86                                         total += (atoi(n_field)*duration_w);
87                                 break;
88
89                                 case 'y':
90                                         total += (atoi(n_field)*duration_y);
91                                 break;
92                         }
93                         n_field[0] = 0;
94                 }
95         }
96         // add trailing seconds
97         total += atoi(n_field);
98         
99         return total;
100 }
101
102 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
103
104 bool InspIRCd::HostMatchesEveryone(const std::string &mask, userrec* user)
105 {
106         char buffer[MAXBUF];
107         char itrigger[MAXBUF];
108         long matches = 0;
109         
110         if (!Config->ConfValue(Config->config_data, "insane","trigger", 0, itrigger, MAXBUF))
111                 strlcpy(itrigger,"95.5",MAXBUF);
112         
113         if (Config->ConfValueBool(Config->config_data, "insane","hostmasks", 0))
114                 return false;
115         
116         for (user_hash::iterator u = clientlist->begin(); u != clientlist->end(); u++)
117         {
118                 strlcpy(buffer,u->second->ident,MAXBUF);
119                 charlcat(buffer,'@',MAXBUF);
120                 strlcat(buffer,u->second->host,MAXBUF);
121                 if (match(buffer,mask.c_str()))
122                         matches++;
123         }
124         float percent = ((float)matches / (float)clientlist->size()) * 100;
125         if (percent > (float)atof(itrigger))
126         {
127                 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);
128                 return true;
129         }
130         return false;
131 }
132
133 bool InspIRCd::IPMatchesEveryone(const std::string &ip, userrec* user)
134 {
135         char itrigger[MAXBUF];
136         long matches = 0;
137         
138         if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
139                 strlcpy(itrigger,"95.5",MAXBUF);
140         
141         if (Config->ConfValueBool(Config->config_data, "insane","ipmasks",0))
142                 return false;
143         
144         for (user_hash::iterator u = clientlist->begin(); u != clientlist->end(); u++)
145         {
146                 if (match(u->second->GetIPString(),ip.c_str(),true))
147                         matches++;
148         }
149         
150         float percent = ((float)matches / (float)clientlist->size()) * 100;
151         if (percent > (float)atof(itrigger))
152         {
153                 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);
154                 return true;
155         }
156         return false;
157 }
158
159 bool InspIRCd::NickMatchesEveryone(const std::string &nick, userrec* user)
160 {
161         char itrigger[MAXBUF];
162         long matches = 0;
163         
164         if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
165                 strlcpy(itrigger,"95.5",MAXBUF);
166         
167         if (Config->ConfValueBool(Config->config_data, "insane","nickmasks",0))
168                 return false;
169
170         for (user_hash::iterator u = clientlist->begin(); u != clientlist->end(); u++)
171         {
172                 if (match(u->second->nick,nick.c_str()))
173                         matches++;
174         }
175         
176         float percent = ((float)matches / (float)clientlist->size()) * 100;
177         if (percent > (float)atof(itrigger))
178         {
179                 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);
180                 return true;
181         }
182         return false;
183 }