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