]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/xline.cpp
If we have a bitmask of 0 in apply_lines, dont even bother to run the function!
[user/henk/code/inspircd.git] / src / xline.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 "users.h"
16 #include "modules.h"
17 #include "wildcard.h"
18 #include "xline.h"
19 #include "cull_list.h"
20
21 /* Version two, now with optimized expiry!
22  *
23  * Because the old way was horrendously slow, the new way of expiring xlines is very
24  * very efficient. I have improved the efficiency of the algorithm in two ways:
25  *
26  * (1) There are now two lists of items for each linetype. One list holds temporary
27  *     items, and the other list holds permanent items (ones which will expire).
28  *     Items which are on the permanent list are NEVER checked at all by the
29  *     expire_lines() function.
30  * (2) The temporary xline lists are always kept in strict numerical order, keyed by 
31  *     current time + duration. This means that the line which is due to expire the
32  *     soonest is always pointed at by vector::begin(), so a simple while loop can
33  *     very efficiently, very quickly and above all SAFELY pick off the first few
34  *     items in the vector which need zapping.
35  *
36  *     -- Brain
37  */
38
39 bool InitXLine(ServerConfig* conf, const char* tag)
40 {
41         return true;
42 }
43
44 bool DoneZLine(ServerConfig* conf, const char* tag)
45 {
46         conf->GetInstance()->XLines->apply_lines(APPLY_ZLINES|APPLY_PERM_ONLY);
47         return true;
48 }
49
50 bool DoneQLine(ServerConfig* conf, const char* tag)
51 {
52         conf->GetInstance()->XLines->apply_lines(APPLY_QLINES|APPLY_PERM_ONLY);
53         return true;
54 }
55
56 bool DoneKLine(ServerConfig* conf, const char* tag)
57 {
58         conf->GetInstance()->XLines->apply_lines(APPLY_KLINES|APPLY_PERM_ONLY);
59         return true;
60 }
61
62 bool DoneELine(ServerConfig* conf, const char* tag)
63 {
64         /* Yes, this is supposed to do nothing, we dont 'apply' these */
65         return true;
66 }
67
68 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
69 {
70         const char* reason = values[0].GetString();
71         const char* ipmask = values[1].GetString();
72         
73         conf->GetInstance()->XLines->add_zline(0,"<Config>",reason,ipmask);
74         conf->GetInstance()->Log(DEBUG,"Read Z line (badip tag): ipmask=%s reason=%s",ipmask,reason);
75         return true;
76 }
77
78 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
79 {
80         const char* reason = values[0].GetString();
81         const char* nick = values[1].GetString();
82         
83         conf->GetInstance()->XLines->add_qline(0,"<Config>",reason,nick);
84         conf->GetInstance()->Log(DEBUG,"Read Q line (badnick tag): nick=%s reason=%s",nick,reason);
85         return true;
86 }
87
88 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
89 {
90         const char* reason = values[0].GetString();
91         const char* host = values[1].GetString();
92         
93         conf->GetInstance()->XLines->add_kline(0,"<Config>",reason,host);
94         conf->GetInstance()->Log(DEBUG,"Read K line (badhost tag): host=%s reason=%s",host,reason);
95         return true;
96 }
97
98 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
99 {
100         const char* reason = values[0].GetString();
101         const char* host = values[1].GetString();
102         
103         conf->GetInstance()->XLines->add_eline(0,"<Config>",reason,host);
104         conf->GetInstance()->Log(DEBUG,"Read E line (exception tag): host=%s reason=%s",host,reason);
105         return true;
106 }
107
108 IdentHostPair XLineManager::IdentSplit(const std::string &ident_and_host)
109 {
110         IdentHostPair n = std::make_pair<std::string,std::string>("*","*");
111         std::string::size_type x = ident_and_host.find('@');
112         if (x != std::string::npos)
113         {
114                 n.second = ident_and_host.substr(x + 1,ident_and_host.length());
115                 n.first = ident_and_host.substr(0, x);
116                 if (!n.first.length())
117                         n.first = "*";
118                 if (!n.second.length())
119                         n.second = "*";
120         }
121         else
122         {
123                 n.second = ident_and_host;
124         }
125
126         return n;
127 }
128
129 // adds a g:line
130
131 bool XLineManager::add_gline(long duration, const char* source,const char* reason,const char* hostmask)
132 {
133         IdentHostPair ih = IdentSplit(hostmask);
134
135         bool ret = del_gline(hostmask);
136         
137         GLine* item = new GLine(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
138         
139         if (duration)
140         {
141                 glines.push_back(item);
142                 sort(glines.begin(), glines.end(),XLineManager::GSortComparison);
143         }
144         else
145         {
146                 pglines.push_back(item);
147         }
148         
149         return !ret;
150 }
151
152 // adds an e:line (exception to bans)
153
154 bool XLineManager::add_eline(long duration, const char* source, const char* reason, const char* hostmask)
155 {
156         IdentHostPair ih = IdentSplit(hostmask);
157
158         bool ret = del_eline(hostmask);
159
160         ELine* item = new ELine(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
161
162         if (duration)
163         {
164                 elines.push_back(item);
165                 sort(elines.begin(), elines.end(),XLineManager::ESortComparison);
166         }
167         else
168         {
169                 pelines.push_back(item);
170         }
171         return !ret;
172 }
173
174 // adds a q:line
175
176 bool XLineManager::add_qline(long duration, const char* source, const char* reason, const char* nickname)
177 {
178         bool ret = del_qline(nickname);
179         QLine* item = new QLine(ServerInstance->Time(), duration, source, reason, nickname);
180
181         if (duration)
182         {
183                 qlines.push_back(item);
184                 sort(qlines.begin(), qlines.end(),XLineManager::QSortComparison);
185         }
186         else
187         {
188                 pqlines.push_back(item);
189         }
190         return !ret;
191 }
192
193 // adds a z:line
194
195 bool XLineManager::add_zline(long duration, const char* source, const char* reason, const char* ipaddr)
196 {
197         bool ret = del_zline(ipaddr);
198
199         if (strchr(ipaddr,'@'))
200         {
201                 while (*ipaddr != '@')
202                         ipaddr++;
203                 ipaddr++;
204         }
205
206         ZLine* item = new ZLine(ServerInstance->Time(), duration, source, reason, ipaddr);
207
208         if (duration)
209         {
210                 zlines.push_back(item);
211                 sort(zlines.begin(), zlines.end(),XLineManager::ZSortComparison);
212         }
213         else
214         {
215                 pzlines.push_back(item);
216         }
217         return !ret;
218 }
219
220 // adds a k:line
221
222 bool XLineManager::add_kline(long duration, const char* source, const char* reason, const char* hostmask)
223 {
224         IdentHostPair ih = IdentSplit(hostmask);
225
226         bool ret = del_kline(hostmask);
227
228         KLine* item = new KLine(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
229
230         if (duration)
231         {
232                 klines.push_back(item);
233                 sort(klines.begin(), klines.end(),XLineManager::KSortComparison);
234         }
235         else
236         {
237                 pklines.push_back(item);
238         }
239         return !ret;
240 }
241
242 // deletes a g:line, returns true if the line existed and was removed
243
244 bool XLineManager::del_gline(const char* hostmask)
245 {
246         IdentHostPair ih = IdentSplit(hostmask);
247         for (std::vector<GLine*>::iterator i = glines.begin(); i != glines.end(); i++)
248         {
249                 if (!strcasecmp(ih.first.c_str(),(*i)->identmask) && !strcasecmp(ih.second.c_str(),(*i)->hostmask))
250                 {
251                         delete *i;
252                         glines.erase(i);
253                         return true;
254                 }
255         }
256         for (std::vector<GLine*>::iterator i = pglines.begin(); i != pglines.end(); i++)
257         {
258                 if (!strcasecmp(ih.first.c_str(),(*i)->identmask) && !strcasecmp(ih.second.c_str(),(*i)->hostmask))
259                 {
260                         delete *i;
261                         pglines.erase(i);
262                         return true;
263                 }
264         }
265         return false;
266 }
267
268 // deletes a e:line, returns true if the line existed and was removed
269
270 bool XLineManager::del_eline(const char* hostmask)
271 {
272         IdentHostPair ih = IdentSplit(hostmask);
273         for (std::vector<ELine*>::iterator i = elines.begin(); i != elines.end(); i++)
274         {
275                 if (!strcasecmp(ih.first.c_str(),(*i)->identmask) && !strcasecmp(ih.second.c_str(),(*i)->hostmask))
276                 {
277                         delete *i;
278                         elines.erase(i);
279                         return true;
280                 }
281         }
282         for (std::vector<ELine*>::iterator i = pelines.begin(); i != pelines.end(); i++)
283         {
284                 if (!strcasecmp(ih.first.c_str(),(*i)->identmask) && !strcasecmp(ih.second.c_str(),(*i)->hostmask))
285                 {
286                         delete *i;
287                         pelines.erase(i);
288                         return true;
289                 }
290         }
291         return false;
292 }
293
294 // deletes a q:line, returns true if the line existed and was removed
295
296 bool XLineManager::del_qline(const char* nickname)
297 {
298         for (std::vector<QLine*>::iterator i = qlines.begin(); i != qlines.end(); i++)
299         {
300                 if (!strcasecmp(nickname,(*i)->nick))
301                 {
302                         delete *i;
303                         qlines.erase(i);
304                         return true;
305                 }
306         }
307         for (std::vector<QLine*>::iterator i = pqlines.begin(); i != pqlines.end(); i++)
308         {
309                 if (!strcasecmp(nickname,(*i)->nick))
310                 {
311                         delete *i;
312                         pqlines.erase(i);
313                         return true;
314                 }
315         }
316         return false;
317 }
318
319 // deletes a z:line, returns true if the line existed and was removed
320
321 bool XLineManager::del_zline(const char* ipaddr)
322 {
323         for (std::vector<ZLine*>::iterator i = zlines.begin(); i != zlines.end(); i++)
324         {
325                 if (!strcasecmp(ipaddr,(*i)->ipaddr))
326                 {
327                         delete *i;
328                         zlines.erase(i);
329                         return true;
330                 }
331         }
332         for (std::vector<ZLine*>::iterator i = pzlines.begin(); i != pzlines.end(); i++)
333         {
334                 if (!strcasecmp(ipaddr,(*i)->ipaddr))
335                 {
336                         delete *i;
337                         pzlines.erase(i);
338                         return true;
339                 }
340         }
341         return false;
342 }
343
344 // deletes a k:line, returns true if the line existed and was removed
345
346 bool XLineManager::del_kline(const char* hostmask)
347 {
348         IdentHostPair ih = IdentSplit(hostmask);
349         for (std::vector<KLine*>::iterator i = klines.begin(); i != klines.end(); i++)
350         {
351                 if (!strcasecmp(ih.first.c_str(),(*i)->identmask) && !strcasecmp(ih.second.c_str(),(*i)->hostmask))
352                 {
353                         delete *i;
354                         klines.erase(i);
355                         return true;
356                 }
357         }
358         for (std::vector<KLine*>::iterator i = pklines.begin(); i != pklines.end(); i++)
359         {
360                 if (!strcasecmp(ih.first.c_str(),(*i)->identmask) && !strcasecmp(ih.second.c_str(),(*i)->hostmask))
361                 {
362                         delete *i;
363                         pklines.erase(i);
364                         return true;
365                 }
366         }
367         return false;
368 }
369
370 // returns a pointer to the reason if a nickname matches a qline, NULL if it didnt match
371
372 QLine* XLineManager::matches_qline(const char* nick, bool permonly)
373 {
374         if ((qlines.empty()) && (pqlines.empty()))
375                 return NULL;
376         if (!permonly)
377         {
378                 for (std::vector<QLine*>::iterator i = qlines.begin(); i != qlines.end(); i++)
379                         if (match(nick,(*i)->nick))
380                                 return (*i);
381         }
382         for (std::vector<QLine*>::iterator i = pqlines.begin(); i != pqlines.end(); i++)
383                 if (match(nick,(*i)->nick))
384                         return (*i);
385         return NULL;
386 }
387
388 // returns a pointer to the reason if a host matches a gline, NULL if it didnt match
389
390 GLine* XLineManager::matches_gline(userrec* user, bool permonly)
391 {
392         if ((glines.empty()) && (pglines.empty()))
393                 return NULL;
394         if (!permonly)
395         {
396                 for (std::vector<GLine*>::iterator i = glines.begin(); i != glines.end(); i++)
397                 {
398                         if ((match(user->ident,(*i)->identmask)))
399                         {
400                                 if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true)))
401                                 {
402                                         return (*i);
403                                 }
404                         }
405                 }
406         }
407         for (std::vector<GLine*>::iterator i = pglines.begin(); i != pglines.end(); i++)
408         {
409                 if ((match(user->ident,(*i)->identmask)))
410                 {
411                         if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true)))
412                         {
413                                 return (*i);
414                         }
415                 }
416         }
417         return NULL;
418 }
419
420 ELine* XLineManager::matches_exception(userrec* user, bool permonly)
421 {                       
422         if ((elines.empty()) && (pelines.empty()))
423                 return NULL;
424         char host2[MAXBUF];
425         snprintf(host2,MAXBUF,"*@%s",user->host);
426         if (!permonly)
427         {
428                 for (std::vector<ELine*>::iterator i = elines.begin(); i != elines.end(); i++)
429                 {
430                         if ((match(user->ident,(*i)->identmask)))
431                         {
432                                 if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true)))
433                                 {
434                                         return (*i);
435                                 }
436                         }
437                 }
438         }
439         for (std::vector<ELine*>::iterator i = pelines.begin(); i != pelines.end(); i++)
440         {
441                 if ((match(user->ident,(*i)->identmask)))
442                 {
443                         if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true)))
444                         {
445                                 return (*i);
446                         }
447                 }
448         }
449         return NULL;
450 }
451
452
453 void XLineManager::gline_set_creation_time(const char* host, time_t create_time)
454 {
455         for (std::vector<GLine*>::iterator i = glines.begin(); i != glines.end(); i++)
456         {
457                 if (!strcasecmp(host,(*i)->hostmask))
458                 {
459                         (*i)->set_time = create_time;
460                         (*i)->expiry = create_time + (*i)->duration;
461                         return;
462                 }
463         }
464         for (std::vector<GLine*>::iterator i = pglines.begin(); i != pglines.end(); i++)
465         {
466                 if (!strcasecmp(host,(*i)->hostmask))
467                 {
468                         (*i)->set_time = create_time;
469                         return;
470                 }
471         }
472         return ;        
473 }
474
475 void XLineManager::eline_set_creation_time(const char* host, time_t create_time)
476 {
477         for (std::vector<ELine*>::iterator i = elines.begin(); i != elines.end(); i++)
478         {
479                 if (!strcasecmp(host,(*i)->hostmask))
480                 {
481                         (*i)->set_time = create_time;
482                         (*i)->expiry = create_time + (*i)->duration;
483                         return;
484                 }
485         }
486         for (std::vector<ELine*>::iterator i = pelines.begin(); i != pelines.end(); i++)        
487         {
488                 if (!strcasecmp(host,(*i)->hostmask))
489                 {
490                         (*i)->set_time = create_time;
491                         return;
492                 }
493         }
494         return;
495 }
496
497 void XLineManager::qline_set_creation_time(const char* nick, time_t create_time)
498 {
499         for (std::vector<QLine*>::iterator i = qlines.begin(); i != qlines.end(); i++)
500         {
501                 if (!strcasecmp(nick,(*i)->nick))
502                 {
503                         (*i)->set_time = create_time;
504                         (*i)->expiry = create_time + (*i)->duration;
505                         return;
506                 }
507         }
508         for (std::vector<QLine*>::iterator i = pqlines.begin(); i != pqlines.end(); i++)
509         {
510                 if (!strcasecmp(nick,(*i)->nick))
511                 {
512                         (*i)->set_time = create_time;
513                         return;
514                 }
515         }
516         return;
517 }
518
519 void XLineManager::zline_set_creation_time(const char* ip, time_t create_time)
520 {
521         for (std::vector<ZLine*>::iterator i = zlines.begin(); i != zlines.end(); i++)
522         {
523                 if (!strcasecmp(ip,(*i)->ipaddr))
524                 {
525                         (*i)->set_time = create_time;
526                         (*i)->expiry = create_time + (*i)->duration;
527                         return;
528                 }
529         }
530         for (std::vector<ZLine*>::iterator i = pzlines.begin(); i != pzlines.end(); i++)
531         {
532                 if (!strcasecmp(ip,(*i)->ipaddr))
533                 {
534                         (*i)->set_time = create_time;
535                         return;
536                 }
537         }
538         return;
539 }
540
541 // returns a pointer to the reason if an ip address matches a zline, NULL if it didnt match
542
543 ZLine* XLineManager::matches_zline(const char* ipaddr, bool permonly)
544 {
545         if ((zlines.empty()) && (pzlines.empty()))
546                 return NULL;
547         if (!permonly)
548         {
549                 for (std::vector<ZLine*>::iterator i = zlines.begin(); i != zlines.end(); i++)
550                         if (match(ipaddr,(*i)->ipaddr, true))
551                                 return (*i);
552         }
553         for (std::vector<ZLine*>::iterator i = pzlines.begin(); i != pzlines.end(); i++)
554                 if (match(ipaddr,(*i)->ipaddr, true))
555                         return (*i);
556         return NULL;
557 }
558
559 // returns a pointer to the reason if a host matches a kline, NULL if it didnt match
560
561 KLine* XLineManager::matches_kline(userrec* user, bool permonly)
562 {
563         if ((klines.empty()) && (pklines.empty()))
564                 return NULL;
565         if (!permonly)
566         {
567                 for (std::vector<KLine*>::iterator i = klines.begin(); i != klines.end(); i++)
568                 {
569                         if ((match(user->ident,(*i)->identmask)))
570                         {
571                                 if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true)))
572                                 {
573                                         return (*i);
574                                 }
575                         }
576                 }
577         }
578         for (std::vector<KLine*>::iterator i = pklines.begin(); i != pklines.end(); i++)
579         {
580                 if ((match(user->ident,(*i)->identmask)))
581                 {
582                         if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true)))
583                         {
584                                 return (*i);
585                         }
586                 }
587         }
588         return NULL;
589 }
590
591 bool XLineManager::GSortComparison ( const GLine* one, const GLine* two )
592 {
593         return (one->expiry) < (two->expiry);
594 }
595
596 bool XLineManager::ESortComparison ( const ELine* one, const ELine* two )
597 {
598         return (one->expiry) < (two->expiry);
599 }
600
601 bool XLineManager::ZSortComparison ( const ZLine* one, const ZLine* two )
602 {
603         return (one->expiry) < (two->expiry);
604 }
605
606 bool XLineManager::KSortComparison ( const KLine* one, const KLine* two )
607 {
608         return (one->expiry) < (two->expiry);
609 }
610
611 bool XLineManager::QSortComparison ( const QLine* one, const QLine* two )
612 {
613         return (one->expiry) < (two->expiry);
614 }
615
616 // removes lines that have expired
617
618 void XLineManager::expire_lines()
619 {
620         time_t current = ServerInstance->Time();
621
622         /* Because we now store all our XLines in sorted order using ((*i)->duration + (*i)->set_time) as a key, this
623          * means that to expire the XLines we just need to do a while, picking off the top few until there are
624          * none left at the head of the queue that are after the current time.
625          */
626
627         while ((glines.size()) && (current > (*glines.begin())->expiry))
628         {
629                 std::vector<GLine*>::iterator i = glines.begin();
630                 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed G-Line %s@%s (set by %s %d seconds ago)",(*i)->identmask,(*i)->hostmask,(*i)->source,(*i)->duration);
631                 glines.erase(i);
632         }
633
634         while ((elines.size()) && (current > (*elines.begin())->expiry))
635         {
636                 std::vector<ELine*>::iterator i = elines.begin();
637                 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed E-Line %s@%s (set by %s %d seconds ago)",(*i)->identmask,(*i)->hostmask,(*i)->source,(*i)->duration);
638                 elines.erase(i);
639         }
640
641         while ((zlines.size()) && (current > (*zlines.begin())->expiry))
642         {
643                 std::vector<ZLine*>::iterator i = zlines.begin();
644                 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed Z-Line %s (set by %s %d seconds ago)",(*i)->ipaddr,(*i)->source,(*i)->duration);
645                 zlines.erase(i);
646         }
647
648         while ((klines.size()) && (current > (*klines.begin())->expiry))
649         {
650                 std::vector<KLine*>::iterator i = klines.begin();
651                 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed K-Line %s@%s (set by %s %d seconds ago)",(*i)->identmask,(*i)->hostmask,(*i)->source,(*i)->duration);
652                 klines.erase(i);
653         }
654
655         while ((qlines.size()) && (current > (*qlines.begin())->expiry))
656         {
657                 std::vector<QLine*>::iterator i = qlines.begin();
658                 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed Q-Line %s (set by %s %d seconds ago)",(*i)->nick,(*i)->source,(*i)->duration);
659                 qlines.erase(i);
660         }
661         
662 }
663
664 // applies lines, removing clients and changing nicks etc as applicable
665
666 void XLineManager::apply_lines(const int What)
667 {
668         if (!What)
669                 return;
670
671         if (What & APPLY_PERM_ONLY)
672         {
673                 char reason[MAXBUF];
674
675                 if ((!pglines.size()) && (!pklines.size()) && (!pzlines.size()) && (!pqlines.size()))
676                         return;
677
678                 CullList* Goners = new CullList(ServerInstance);
679                 XLine* check = NULL;
680                 for (std::vector<userrec*>::const_iterator u2 = ServerInstance->local_users.begin(); u2 != ServerInstance->local_users.end(); u2++)
681                 {
682                         userrec* u = (userrec*)(*u2);
683
684                         if (elines.size() || pelines.size())
685                                 if (matches_exception(u))
686                                         continue;
687
688                         if ((What & APPLY_GLINES) && pglines.size())
689                         {
690                                 if ((check = matches_gline(u,true)))
691                                 {
692                                         snprintf(reason,MAXBUF,"G-Lined: %s",check->reason);
693                                         Goners->AddItem(u,reason);
694                                 }
695                         }
696
697                         if ((What & APPLY_KLINES) && pklines.size())
698                         {
699                                 if ((check = matches_kline(u,true)))
700                                 {
701                                         snprintf(reason,MAXBUF,"K-Lined: %s",check->reason);
702                                         Goners->AddItem(u,reason);
703                                 }
704                         }
705
706                         if ((What & APPLY_QLINES) && pqlines.size())
707                         {
708                                 if ((check = matches_qline(u->nick,true)))
709                                 {
710                                         snprintf(reason,MAXBUF,"Q-Lined: %s",check->reason);
711                                         Goners->AddItem(u,reason);
712                                 }
713                         }
714
715                         if ((What & APPLY_ZLINES) && pzlines.size())
716                         {
717                                 if ((check = matches_zline(u->GetIPString(),true)))
718                                 {
719                                         snprintf(reason,MAXBUF,"Z-Lined: %s",check->reason);
720                                         Goners->AddItem(u,reason);
721                                 }
722                         }
723                 }
724
725                 Goners->Apply();
726                 DELETE(Goners);
727         }
728         else
729         {
730                 char reason[MAXBUF];
731
732                 if ((!glines.size()) && (!klines.size()) && (!zlines.size()) && (!qlines.size()) &&
733                 (!pglines.size()) && (!pklines.size()) && (!pzlines.size()) && (!pqlines.size()))
734                         return;
735         
736                 CullList* Goners = new CullList(ServerInstance);
737                 XLine* check = NULL;
738                 for (std::vector<userrec*>::const_iterator u2 = ServerInstance->local_users.begin(); u2 != ServerInstance->local_users.end(); u2++)
739                 {
740                         userrec* u = (userrec*)(*u2);
741
742                         if (elines.size() || pelines.size())
743                         {
744                                 // ignore people matching exempts
745                                 if (matches_exception(u))
746                                         continue;
747                         }
748                         if ((What & APPLY_GLINES) && (glines.size() || pglines.size()))
749                         {
750                                 if ((check = matches_gline(u)))
751                                 {
752                                         snprintf(reason,MAXBUF,"G-Lined: %s",check->reason);
753                                         Goners->AddItem(u,reason);
754                                 }
755                         }
756                         if ((What & APPLY_KLINES) && (klines.size() || pklines.size()))
757                         {
758                                 if ((check = matches_kline(u)))
759                                 {
760                                         snprintf(reason,MAXBUF,"K-Lined: %s",check->reason);
761                                         Goners->AddItem(u,reason);
762                                 }
763                         }
764                         if ((What & APPLY_QLINES) && (qlines.size() || pqlines.size()))
765                         {
766                                 if ((check = matches_qline(u->nick)))
767                                 {
768                                         snprintf(reason,MAXBUF,"Q-Lined: %s",check->reason);
769                                         Goners->AddItem(u,reason);
770                                 }
771                         }
772                         if ((What & APPLY_ZLINES) && (zlines.size() || pzlines.size()))
773                         {
774                                 if ((check = matches_zline(u->GetIPString())))
775                                 {
776                                         snprintf(reason,MAXBUF,"Z-Lined: %s",check->reason);
777                                         Goners->AddItem(u,reason);
778                                 }
779                         }
780                 }
781
782                 Goners->Apply();
783                 DELETE(Goners);
784         }
785 }
786
787 void XLineManager::stats_k(userrec* user, string_list &results)
788 {
789         std::string sn = ServerInstance->Config->ServerName;
790         for (std::vector<KLine*>::iterator i = klines.begin(); i != klines.end(); i++)
791                 results.push_back(sn+" 216 "+user->nick+" :"+(*i)->identmask+"@"+(*i)->hostmask+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
792         for (std::vector<KLine*>::iterator i = pklines.begin(); i != pklines.end(); i++)
793                 results.push_back(sn+" 216 "+user->nick+" :"+(*i)->identmask+"@"+(*i)->hostmask+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
794 }
795
796 void XLineManager::stats_g(userrec* user, string_list &results)
797 {
798         std::string sn = ServerInstance->Config->ServerName;
799         for (std::vector<GLine*>::iterator i = glines.begin(); i != glines.end(); i++)
800                 results.push_back(sn+" 223 "+user->nick+" :"+(*i)->identmask+"@"+(*i)->hostmask+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
801         for (std::vector<GLine*>::iterator i = pglines.begin(); i != pglines.end(); i++)
802                 results.push_back(sn+" 223 "+user->nick+" :"+(*i)->identmask+"@"+(*i)->hostmask+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
803 }
804
805 void XLineManager::stats_q(userrec* user, string_list &results)
806 {
807         std::string sn = ServerInstance->Config->ServerName;
808         for (std::vector<QLine*>::iterator i = qlines.begin(); i != qlines.end(); i++)
809                 results.push_back(sn+" 217 "+user->nick+" :"+(*i)->nick+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
810         for (std::vector<QLine*>::iterator i = pqlines.begin(); i != pqlines.end(); i++)
811                 results.push_back(sn+" 217 "+user->nick+" :"+(*i)->nick+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
812 }
813
814 void XLineManager::stats_z(userrec* user, string_list &results)
815 {
816         std::string sn = ServerInstance->Config->ServerName;
817         for (std::vector<ZLine*>::iterator i = zlines.begin(); i != zlines.end(); i++)
818                 results.push_back(sn+" 223 "+user->nick+" :"+(*i)->ipaddr+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
819         for (std::vector<ZLine*>::iterator i = pzlines.begin(); i != pzlines.end(); i++)
820                 results.push_back(sn+" 223 "+user->nick+" :"+(*i)->ipaddr+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
821 }
822
823 void XLineManager::stats_e(userrec* user, string_list &results)
824 {
825         std::string sn = ServerInstance->Config->ServerName;
826         for (std::vector<ELine*>::iterator i = elines.begin(); i != elines.end(); i++)
827                 results.push_back(sn+" 223 "+user->nick+" :"+(*i)->identmask+"@"+(*i)->hostmask+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
828         for (std::vector<ELine*>::iterator i = pelines.begin(); i != pelines.end(); i++)
829                 results.push_back(sn+" 223 "+user->nick+" :"+(*i)->identmask+"@"+(*i)->hostmask+" "+ConvToStr((*i)->set_time)+" "+ConvToStr((*i)->duration)+" "+(*i)->source+" :"+(*i)->reason);
830 }
831
832 XLineManager::XLineManager(InspIRCd* Instance) : ServerInstance(Instance)
833 {
834 }