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