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