summaryrefslogtreecommitdiff
path: root/src/operserv.cpp
blob: 2d509f25ff2cd6a6fea8b9f28da87dc4f1b12c32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
/* OperServ functions.
 *
 * (C) 2003-2010 Anope Team
 * Contact us at team@anope.org
 *
 * Please read COPYING and README for further details.
 *
 * Based on the original code of Epona by Lara.
 * Based on the original code of Services by Andy Church.
 */

#include "services.h"
#include "modules.h"

std::vector<NewsItem *> News;

std::vector<std::bitset<32> > DefCon;
bool DefConModesSet = false;
/* Defcon modes mlocked on */
Flags<ChannelModeName, CMODE_END * 2> DefConModesOn;
/* Defcon modes mlocked off */
Flags<ChannelModeName, CMODE_END * 2> DefConModesOff;
/* Map of Modesa and Params for DefCon */
std::map<ChannelModeName, Anope::string> DefConModesOnParams;

XLineManager *SGLine = NULL, *SZLine = NULL, *SQLine = NULL, *SNLine = NULL;

void os_init()
{
	if (!Config->s_OperServ.empty())
	{
		ModuleManager::LoadModuleList(Config->OperServCoreModules);

		/* Yes, these are in this order for a reason. Most violent->least violent. */
		XLineManager::RegisterXLineManager(SGLine = new SGLineManager());
		XLineManager::RegisterXLineManager(SZLine = new SZLineManager());
		XLineManager::RegisterXLineManager(SQLine = new SQLineManager());
		XLineManager::RegisterXLineManager(SNLine = new SNLineManager());
	}
}

bool SetDefConParam(ChannelModeName Name, const Anope::string &buf)
{
	return DefConModesOnParams.insert(std::make_pair(Name, buf)).second;
}

bool GetDefConParam(ChannelModeName Name, Anope::string &buf)
{
	std::map<ChannelModeName, Anope::string>::iterator it = DefConModesOnParams.find(Name);

	buf.clear();

	if (it != DefConModesOnParams.end())
	{
		buf = it->second;
		return true;
	}

	return false;
}

void UnsetDefConParam(ChannelModeName Name)
{
	std::map<ChannelModeName, Anope::string>::iterator it = DefConModesOnParams.find(Name);

	if (it != DefConModesOnParams.end())
		DefConModesOnParams.erase(it);
}

/** Check if a certain defcon option is currently in affect
 * @param Level The level
 * @return true and false
 */
bool CheckDefCon(DefconLevel Level)
{
	if (Config->DefConLevel)
		return DefCon[Config->DefConLevel][Level];
	return false;
}

/** Check if a certain defcon option is in a certain defcon level
 * @param level The defcon level
 * @param Level The defcon level name
 * @return true or false
 */
bool CheckDefCon(int level, DefconLevel Level)
{
	return DefCon[level][Level];
}

/** Add a defcon level option to a defcon level
 * @param level The defcon level
 * @param Level The defcon level option
 */
void AddDefCon(int level, DefconLevel Level)
{
	DefCon[level][Level] = true;
}

/** Remove a defcon level option from a defcon level
 * @param level The defcon level
 * @param Level The defcon level option
 */
void DelDefCon(int level, DefconLevel Level)
{
	DefCon[level][Level] = false;
}

void server_global(const Server *s, const Anope::string &message)
{
	if (Config->s_GlobalNoticer.empty())
		return;

	/* Do not send the notice to ourselves our juped servers */
	if (s != Me && !s->HasFlag(SERVER_JUPED))
		notice_server(Config->s_GlobalNoticer, s, "%s", message.c_str());

	if (!s->GetLinks().empty())
	{
		for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
			server_global(s->GetLinks()[i], message);
	}
}

void oper_global(const Anope::string &nick, const char *fmt, ...)
{
	va_list args;
	char msg[2048]; /* largest valid message is 512, this should cover any global */

	va_start(args, fmt);
	vsnprintf(msg, sizeof(msg), fmt, args);
	va_end(args);

	if (!nick.empty() && !Config->AnonymousGlobal)
	{
		Anope::string rmsg = "[" + nick + "] " + msg;
		server_global(Me->GetLinks().front(), rmsg);
	}
	else
		server_global(Me->GetLinks().front(), msg);
}

/**************************************************************************/

/* List of XLine managers we check users against in XLineManager::CheckAll */
std::list<XLineManager *> XLineManager::XLineManagers;

XLine::XLine(const Anope::string &mask, const Anope::string &reason) : Mask(mask), Created(0), Expires(0), Reason(reason)
{
}

XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason) : Mask(mask), By(by), Created(Anope::CurTime), Expires(expires), Reason(reason)
{
}

Anope::string XLine::GetNick() const
{
	size_t nick_t = this->Mask.find('!');

	if (nick_t == Anope::string::npos)
		return "";

	return this->Mask.substr(0, nick_t);
}

Anope::string XLine::GetUser() const
{
	size_t user_t = this->Mask.find('!'), host_t = this->Mask.find('@');

	if (host_t != Anope::string::npos)
	{
		if (user_t != Anope::string::npos)
			return this->Mask.substr(user_t + 1, host_t - user_t - 1);
		else
			return this->Mask.substr(0, host_t);
	}
	else
		return "";
}

Anope::string XLine::GetHost() const
{
	size_t host_t = this->Mask.find('@');

	if (host_t == Anope::string::npos)
		return this->Mask;
	else
		return this->Mask.substr(host_t + 1);
}

/** Constructor
 */
XLineManager::XLineManager()
{
}

/** Destructor
 * Clears all XLines in this XLineManager
 */
XLineManager::~XLineManager()
{
	this->Clear();
}

 /** Register a XLineManager, places it in XLineManagers for use in XLineManager::CheckAll
  * It is important XLineManagers are registered in the proper order. Eg, if you had one akilling
  * clients and one handing them free olines, you would want the akilling one first. This way if a client
  * matches an entry on both of the XLineManagers, they would be akilled.
  * @param xlm THe XLineManager
  */
void XLineManager::RegisterXLineManager(XLineManager *xlm)
{
	XLineManagers.push_back(xlm);
}

/** Unregister a XLineManager
 * @param xlm The XLineManager
 */
void XLineManager::UnregisterXLineManager(XLineManager *xlm)
{
	std::list<XLineManager *>::iterator it = std::find(XLineManagers.begin(), XLineManagers.end(), xlm);

	if (it != XLineManagers.end())
		XLineManagers.erase(it);
}

/* Check a user against all known XLineManagers
 * @param u The user
 * @return A pair of the XLineManager the user was found in and the XLine they matched, both may be NULL for no match
 */
std::pair<XLineManager *, XLine *> XLineManager::CheckAll(User *u)
{
	std::pair<XLineManager *, XLine *> ret;

	ret.first = NULL;
	ret.second = NULL;

	for (std::list<XLineManager *>::iterator it = XLineManagers.begin(), it_end = XLineManagers.end(); it != it_end; ++it)
	{
		XLineManager *xlm = *it;

		XLine *x = xlm->Check(u);

		if (x)
		{
			ret.first = xlm;
			ret.second = x;
			break;
		}
	}

	return ret;
}

/** Get the number of XLines in this XLineManager
 * @return The number of XLines
 */
size_t XLineManager::GetCount() const
{
	return this->XLines.size();
}

/** Get the XLine vector
  * @return The vecotr
  */
const std::vector<XLine *> &XLineManager::GetList() const
{
	return this->XLines;
}

/** Add an entry to this XLineManager
 * @param x The entry
 */
void XLineManager::AddXLine(XLine *x)
{
	this->XLines.push_back(x);
}

/** Delete an entry from this XLineManager
 * @param x The entry
 * @return true if the entry was found and deleted, else false
 */
bool XLineManager::DelXLine(XLine *x)
{
	std::vector<XLine *>::iterator it = std::find(this->XLines.begin(), this->XLines.end(), x);

	if (it != this->XLines.end())
	{
		delete x;
		this->XLines.erase(it);

		return true;
	}

	return false;
}

/** Gets an entry by index
  * @param index The index
  * @return The XLine, or NULL if the index is out of bounds
  */
XLine *XLineManager::GetEntry(unsigned index)
{
	if (index >= this->XLines.size())
		return NULL;

	return this->XLines[index];
}

/** Clear the XLine vector
 */
void XLineManager::Clear()
{
	for (std::vector<XLine *>::iterator it = this->XLines.begin(), it_end = this->XLines.end(); it != it_end; ++it)
		delete *it;
	this->XLines.clear();
}

/** Add an entry to this XLine Manager
 * @param bi The bot error replies should be sent from
 * @param u The user adding the XLine
 * @param mask The mask of the XLine
 * @param expires When this should expire
 * @param reaosn The reason
 * @return A pointer to the XLine
 */
XLine *XLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
	return NULL;
}

/** Delete an XLine, eg, remove it from the IRCd.
 * @param x The xline
 */
void XLineManager::Del(XLine *x)
{
}

/** Checks if a mask can/should be added to the XLineManager
 * @param mask The mask
 * @param expires When the mask would expire
 * @return A pair of int and XLine*.
 * 1 - Mask already exists
 * 2 - Mask already exists, but the expiry time was changed
 * 3 - Mask is already covered by another mask
 * In each case the XLine it matches/is covered by is returned in XLine*
 */
std::pair<int, XLine *> XLineManager::CanAdd(const Anope::string &mask, time_t expires)
{
	std::pair<int, XLine *> ret;

	ret.first = 0;
	ret.second = NULL;

	for (unsigned i = 0, end = this->GetCount(); i < end; ++i)
	{
		XLine *x = this->GetEntry(i);
		ret.second = x;

		if (x->Mask.equals_ci(mask))
		{
			if (!x->Expires || x->Expires >= expires)
			{
				ret.first = 1;
				break;
			}
			else
			{
				x->Expires = expires;

				ret.first = 2;
				break;
			}
		}
		else if (Anope::Match(mask, x->Mask) && (!x->Expires || x->Expires >= expires))
		{
			ret.first = 3;
			break;
		}
		else if (Anope::Match(x->Mask, mask) && (!expires || x->Expires <= expires))
		{
			this->DelXLine(x);
			--i;
		}
	}

	return ret;
}

/** Checks if this list has an entry
 * @param mask The mask
 * @return The XLine the user matches, or NULL
 */
XLine *XLineManager::HasEntry(const Anope::string &mask)
{
	for (unsigned i = 0, end = this->XLines.size(); i < end; ++i)
	{
		XLine *x = this->XLines[i];

		if (x->Mask.equals_ci(mask))
			return x;
	}

	return NULL;
}

/** Check a user against all of the xlines in this XLineManager
 * @param u The user
 * @return The xline the user marches, if any. Also calls OnMatch()
 */
XLine *XLineManager::Check(User *u)
{
	for (unsigned i = this->XLines.size(); i > 0; --i)
	{
		XLine *x = this->XLines[i - 1];

		if (x->Expires && x->Expires < Anope::CurTime)
		{
			OnExpire(x);
			delete x;
			this->XLines.erase(XLines.begin() + i - 1);
			continue;
		}

		if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick()))
			continue;

		if (!x->GetUser().empty() && !Anope::Match(u->GetIdent(), x->GetUser()))
			continue;

		if (x->GetHost().empty() || (u->ip() && Anope::Match(u->ip.addr(), x->GetHost())) || Anope::Match(u->host, x->GetHost()) || (!u->chost.empty() && Anope::Match(u->chost, x->GetHost())) || (!u->vhost.empty() && Anope::Match(u->vhost, x->GetHost())))
		{
			OnMatch(u, x);
			return x;
		}
	}

	return NULL;
}

/** Called when a user matches a xline in this XLineManager
 * @param u The user
 * @param x The XLine they match
 */
void XLineManager::OnMatch(User *u, XLine *x)
{
}

/** Called when an XLine expires
 * @param x The xline
 */
void XLineManager::OnExpire(XLine *x)
{
}

XLine *SGLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
	if (mask.find('!') != Anope::string::npos)
	{
		if (bi && u)
			u->SendMessage(bi, OPER_AKILL_NO_NICK);
		return NULL;
	}

	if (mask.find('@') == Anope::string::npos)
	{
		if (bi && u)
			u->SendMessage(bi, BAD_USERHOST_MASK);
		return NULL;
	}

	if (mask.find_first_not_of("~@.*?") == Anope::string::npos)
	{
		if (bi && u)
			u->SendMessage(bi, USERHOST_MASK_TOO_WIDE, mask.c_str());
		return NULL;
	}

	std::pair<int, XLine *> canAdd = this->CanAdd(mask, expires);
	if (canAdd.first)
	{
		if (bi && u)
		{
			if (canAdd.first == 1)
				u->SendMessage(bi, OPER_AKILL_EXISTS, canAdd.second->Mask.c_str());
			else if (canAdd.first == 2)
				u->SendMessage(bi, OPER_EXPIRY_CHANGED, canAdd.second->Mask.c_str());
			else if (canAdd.first == 3)
				u->SendMessage(bi, OPER_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
		}

		return NULL;
	}

	Anope::string realreason = reason;
	if (u && Config->AddAkiller)
		realreason = "[" + u->nick + "] " + reason;

	XLine *x = new XLine(mask, u ? u->nick : (OperServ ? OperServ->nick : "OperServ"), expires, realreason);

	EventReturn MOD_RESULT;
	FOREACH_RESULT(I_OnAddAkill, OnAddAkill(u, x));
	if (MOD_RESULT == EVENT_STOP)
	{
		delete x;
		return NULL;
	}

	this->AddXLine(x);

	if (Config->AkillOnAdd)
		ircdproto->SendAkill(x);

	return x;
}

void SGLineManager::Del(XLine *x)
{
	ircdproto->SendAkillDel(x);
}

void SGLineManager::OnMatch(User *u, XLine *x)
{
	ircdproto->SendAkill(x);
}

void SGLineManager::OnExpire(XLine *x)
{
	if (Config->WallAkillExpire)
		ircdproto->SendGlobops(OperServ, "AKILL on %s has expired", x->Mask.c_str());
}

XLine *SNLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
	if (!mask.empty() && mask.find_first_not_of("*?") == Anope::string::npos)
	{
		if (bi && u)
			u->SendMessage(bi, USERHOST_MASK_TOO_WIDE, mask.c_str());
		return NULL;
	}

	std::pair<int, XLine *> canAdd = this->CanAdd(mask, expires);
	if (canAdd.first)
	{
		if (bi && u)
		{
			if (canAdd.first == 1)
				u->SendMessage(bi, OPER_SNLINE_EXISTS, canAdd.second->Mask.c_str());
			else if (canAdd.first == 2)
				u->SendMessage(bi, OPER_EXPIRY_CHANGED, canAdd.second->Mask.c_str());
			else if (canAdd.first == 3)
				u->SendMessage(bi, OPER_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
		}

		return NULL;
	}

	XLine *x = new XLine(mask, u ? u->nick : (OperServ ? OperServ->nick : "OperServ"), expires, reason);

	EventReturn MOD_RESULT;
	FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, X_SNLINE));
	if (MOD_RESULT == EVENT_STOP)
	{
		delete x;
		return NULL;
	}

	this->AddXLine(x);

	if (Config->KillonSNline && !ircd->sglineenforce)
	{
		Anope::string rreason = "G-Lined: " + reason;

		for (user_map::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; )
		{
			User *user = it->second;
			++it;

			if (!is_oper(user) && Anope::Match(user->realname, x->Mask))
				kill_user(Config->ServerName, user->nick, rreason);
		}
	}

	return x;
}

void SNLineManager::Del(XLine *x)
{
	ircdproto->SendSGLineDel(x);
}

void SNLineManager::OnMatch(User *u, XLine *x)
{
	ircdproto->SendSGLine(x);

	Anope::string reason = "G-Lined: " + x->Reason;
	kill_user(Config->s_OperServ, u->nick, reason);
}

void SNLineManager::OnExpire(XLine *x)
{
	if (Config->WallSNLineExpire)
		ircdproto->SendGlobops(OperServ, "SNLINE on \2%s\2 has expired", x->Mask.c_str());
}

XLine *SQLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
	if (mask.find_first_not_of("*") == Anope::string::npos)
	{
		if (bi && u)
			u->SendMessage(OperServ, USERHOST_MASK_TOO_WIDE, mask.c_str());
		return NULL;
	}

	if (mask[0] == '#' && !ircd->chansqline)
	{
		if (bi && u)
			u->SendMessage(OperServ, OPER_SQLINE_CHANNELS_UNSUPPORTED);
		return NULL;
	}

	std::pair<int, XLine *> canAdd = this->CanAdd(mask, expires);
	if (canAdd.first)
	{
		if (bi && u)
		{
			if (canAdd.first == 1)
				u->SendMessage(bi, OPER_SQLINE_EXISTS, canAdd.second->Mask.c_str());
			else if (canAdd.first == 2)
				u->SendMessage(bi, OPER_EXPIRY_CHANGED, canAdd.second->Mask.c_str());
			else if (canAdd.first == 3)
				u->SendMessage(bi, OPER_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
		}

		return NULL;
	}

	XLine *x = new XLine(mask, u ? u->nick : (OperServ ? OperServ->nick : "OperServ"), expires, reason);

	EventReturn MOD_RESULT;
	FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, X_SQLINE));
	if (MOD_RESULT == EVENT_STOP)
	{
		delete x;
		return NULL;
	}

	this->AddXLine(x);

	if (Config->KillonSQline)
	{
		Anope::string rreason = "Q-Lined: " + reason;

		if (mask[0] == '#')
		{
			for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit)
			{
				Channel *c = cit->second;

				if (!Anope::Match(c->name, mask))
					continue;
				for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; )
				{
					UserContainer *uc = *it;
					++it;

					if (is_oper(uc->user))
						continue;
					c->Kick(NULL, uc->user, "%s", reason.c_str());
				}
			}
		}
		else
		{
			for (user_map::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; )
			{
				User *user = it->second;
				++it;

				if (!is_oper(user) && Anope::Match(user->nick, x->Mask))
					kill_user(Config->ServerName, user->nick, rreason);
			}
		}
	}

	ircdproto->SendSQLine(x);

	return x;
}

void SQLineManager::Del(XLine *x)
{
	ircdproto->SendSQLineDel(x);
}

void SQLineManager::OnMatch(User *u, XLine *x)
{
	ircdproto->SendSQLine(x);

	Anope::string reason = "Q-Lined: " + x->Reason;
	kill_user(Config->s_OperServ, u->nick, reason);
}

void SQLineManager::OnExpire(XLine *x)
{
	if (Config->WallSQLineExpire)
		ircdproto->SendGlobops(OperServ, "SQLINE on \2%s\2 has expired", x->Mask.c_str());
}

bool SQLineManager::Check(Channel *c)
{
	if (ircd->chansqline && SQLine)
	{
		for (std::vector<XLine *>::const_iterator it = SGLine->GetList().begin(), it_end = SGLine->GetList().end(); it != it_end; ++it)
		{
			XLine *x = *it;

			if (Anope::Match(c->name, x->Mask))
				return true;
		}
	}

	return false;
}

XLine *SZLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
	if (mask.find('!') != Anope::string::npos || mask.find('@') != Anope::string::npos)
	{
		u->SendMessage(OperServ, OPER_SZLINE_ONLY_IPS);
		return NULL;
	}

	if (mask.find_first_not_of("*?") == Anope::string::npos)
	{
		u->SendMessage(OperServ, USERHOST_MASK_TOO_WIDE, mask.c_str());
		return NULL;
	}

	std::pair<int, XLine *> canAdd = this->CanAdd(mask, expires);
	if (canAdd.first)
	{
		if (bi && u)
		{
			if (canAdd.first == 1)
				u->SendMessage(bi, OPER_SZLINE_EXISTS, canAdd.second->Mask.c_str());
			else if (canAdd.first == 2)
				u->SendMessage(bi, OPER_EXPIRY_CHANGED, canAdd.second->Mask.c_str());
			else if (canAdd.first == 3)
				u->SendMessage(bi, OPER_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
		}

		return NULL;
	}

	XLine *x = new XLine(mask, u ? u->nick : (OperServ ? OperServ->nick : "OperServ"), expires, reason);

	EventReturn MOD_RESULT;
	FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, X_SZLINE));
	if (MOD_RESULT == EVENT_STOP)
	{
		delete x;
		return NULL;
	}

	this->AddXLine(x);

	ircdproto->SendSZLine(x);

	return x;
}

void SZLineManager::Del(XLine *x)
{
	ircdproto->SendSZLineDel(x);
}

void SZLineManager::OnMatch(User *u, XLine *x)
{
	ircdproto->SendSZLine(x);
}

void SZLineManager::OnExpire(XLine *x)
{
	if (Config->WallSZLineExpire)
		ircdproto->SendGlobops(OperServ, "SZLINE on \2%s\2 has expired", x->Mask.c_str());
}