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
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
|
/* Inspircd 2.0 functions
*
* (C) 2003-2013 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 "module.h"
#include "modules/cs_mode.h"
static unsigned int spanningtree_proto_ver = 0;
static ServiceReference<IRCDProto> insp12("IRCDProto", "inspircd12");
class InspIRCd20Proto : public IRCDProto
{
public:
InspIRCd20Proto(Module *creator) : IRCDProto(creator, "InspIRCd 2.0")
{
DefaultPseudoclientModes = "+I";
CanSVSNick = true;
CanSVSJoin = true;
CanSetVHost = true;
CanSetVIdent = true;
CanSQLine = true;
CanSZLine = true;
CanSVSHold = true;
CanCertFP = true;
RequiresID = true;
MaxModes = 20;
}
void SendConnect() anope_override
{
UplinkSocket::Message() << "CAPAB START 1202";
UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202";
UplinkSocket::Message() << "CAPAB END";
insp12->SendConnect();
}
void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override { insp12->SendSVSKillInternal(source, user, buf); }
void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalNotice(bi, dest, msg); }
void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalPrivmsg(bi, dest, msg); }
void SendAkillDel(const XLine *x) anope_override { insp12->SendAkillDel(x); }
void SendTopic(const MessageSource &whosets, Channel *c) anope_override { insp12->SendTopic(whosets, c); };
void SendVhostDel(User *u) anope_override { insp12->SendVhostDel(u); }
void SendAkill(User *u, XLine *x) anope_override { insp12->SendAkill(u, x); }
void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override { insp12->SendNumericInternal(numeric, dest, buf); }
void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override { insp12->SendModeInternal(source, dest, buf); }
void SendClientIntroduction(User *u) anope_override { insp12->SendClientIntroduction(u); }
void SendServer(const Server *server) anope_override { insp12->SendServer(server); }
void SendSquit(Server *s, const Anope::string &message) anope_override { insp12->SendSquit(s, message); }
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { insp12->SendJoin(user, c, status); }
void SendSQLineDel(const XLine *x) anope_override { insp12->SendSQLineDel(x); }
void SendSQLine(User *u, const XLine *x) anope_override { insp12->SendSQLine(u, x); }
void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendVhost(u, vident, vhost); }
void SendSVSHold(const Anope::string &nick, time_t t) anope_override { insp12->SendSVSHold(nick, t); }
void SendSVSHoldDel(const Anope::string &nick) anope_override { insp12->SendSVSHoldDel(nick); }
void SendSZLineDel(const XLine *x) anope_override { insp12->SendSZLineDel(x); }
void SendSZLine(User *u, const XLine *x) anope_override { insp12->SendSZLine(u, x); }
void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &other) anope_override { insp12->SendSVSJoin(source, u, chan, other); }
void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override { insp12->SendSVSPart(source, u, chan, param); }
void SendSWhois(const MessageSource &bi, const Anope::string &who, const Anope::string &mask) anope_override { insp12->SendSWhois(bi, who, mask); }
void SendBOB() anope_override { insp12->SendBOB(); }
void SendEOB() anope_override { insp12->SendEOB(); }
void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) { insp12->SendGlobopsInternal(source, buf); }
void SendLogin(User *u) anope_override { insp12->SendLogin(u); }
void SendLogout(User *u) anope_override { insp12->SendLogout(u); }
void SendChannel(Channel *c) anope_override { insp12->SendChannel(c); }
bool IsExtbanValid(const Anope::string &mask) anope_override { return insp12->IsExtbanValid(mask); }
bool IsIdentValid(const Anope::string &ident) anope_override { return insp12->IsIdentValid(ident); }
};
class InspIRCdExtBan : public ChannelModeList
{
public:
InspIRCdExtBan(const Anope::string &mname, char modeChar) : ChannelModeList(mname, modeChar) { }
bool Matches(User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->GetMask();
if (mask.find("m:") == 0 || mask.find("N:") == 0)
{
Anope::string real_mask = mask.substr(3);
Entry en(this->name, real_mask);
if (en.Matches(u))
return true;
}
else if (mask.find("j:") == 0)
{
Anope::string channel = mask.substr(3);
ChannelMode *cm = NULL;
if (channel[0] != '#')
{
char modeChar = ModeManager::GetStatusChar(channel[0]);
channel.erase(channel.begin());
cm = ModeManager::FindChannelModeByChar(modeChar);
if (cm != NULL && cm->type != MODE_STATUS)
cm = NULL;
}
Channel *c = Channel::Find(channel);
if (c != NULL)
{
ChanUserContainer *uc = c->FindUser(u);
if (uc != NULL)
if (cm == NULL || uc->status.HasMode(cm->mchar))
return true;
}
}
else if (mask.find("R:") == 0)
{
Anope::string real_mask = mask.substr(2);
if (u->IsIdentified() && real_mask.equals_ci(u->Account()->display))
return true;
}
else if (mask.find("r:") == 0)
{
Anope::string real_mask = mask.substr(2);
if (Anope::Match(u->realname, real_mask))
return true;
}
else if (mask.find("s:") == 0)
{
Anope::string real_mask = mask.substr(2);
if (Anope::Match(u->server->GetName(), real_mask))
return true;
}
else if (mask.find("z:") == 0)
{
Anope::string real_mask = mask.substr(2);
if (!u->fingerprint.empty() && Anope::Match(u->fingerprint, real_mask))
return true;
}
return false;
}
};
class ColonDelimitedParamMode : public ChannelModeParam
{
public:
ColonDelimitedParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { }
bool IsValid(const Anope::string &value) const anope_override
{
return IsValid(value, false);
}
bool IsValid(const Anope::string &value, bool historymode) const
{
if (value.empty())
return false; // empty param is never valid
Anope::string::size_type pos = value.find(':');
if ((pos == Anope::string::npos) || (pos == 0))
return false; // no ':' or it's the first char, both are invalid
Anope::string rest;
try
{
if (convertTo<int>(value, rest, false) <= 0)
return false; // negative numbers and zero are invalid
rest = rest.substr(1);
int n;
if (historymode)
{
// For the history mode, the part after the ':' is a duration and it
// can be in the user friendly "1d3h20m" format, make sure we accept that
n = Anope::DoTime(rest);
}
else
n = convertTo<int>(rest);
if (n <= 0)
return false;
}
catch (const ConvertException &e)
{
// conversion error, invalid
return false;
}
return true;
}
};
class SimpleNumberParamMode : public ChannelModeParam
{
public:
SimpleNumberParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { }
bool IsValid(const Anope::string &value) const anope_override
{
if (value.empty())
return false; // empty param is never valid
try
{
if (convertTo<int>(value) <= 0)
return false;
}
catch (const ConvertException &e)
{
// conversion error, invalid
return false;
}
return true;
}
};
class ChannelModeFlood : public ColonDelimitedParamMode
{
public:
ChannelModeFlood(char modeChar) : ColonDelimitedParamMode("FLOOD", modeChar) { }
bool IsValid(const Anope::string &value) const anope_override
{
// The parameter of this mode is a bit different, it may begin with a '*',
// ignore it if that's the case
return ((!value.empty()) && (ColonDelimitedParamMode::IsValid(value[0] == '*' ? value.substr(1) : value)));
}
};
class ChannelModeHistory : public ColonDelimitedParamMode
{
public:
ChannelModeHistory(char modeChar) : ColonDelimitedParamMode("HISTORY", modeChar) { }
bool IsValid(const Anope::string &value) const anope_override
{
return (ColonDelimitedParamMode::IsValid(value, true));
}
};
class ChannelModeRedirect : public ChannelModeParam
{
public:
ChannelModeRedirect(char modeChar) : ChannelModeParam("REDIRECT", modeChar, true) { }
bool IsValid(const Anope::string &value) const anope_override
{
// The parameter of this mode is a channel, and channel names start with '#'
return ((!value.empty()) && (value[0] == '#'));
}
};
struct IRCDMessageCapab : Message::Capab
{
std::map<char, Anope::string> chmodes, umodes;
IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
if (params[0].equals_cs("START"))
{
if (params.size() >= 2)
spanningtree_proto_ver = (Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0);
if (spanningtree_proto_ver < 1202)
{
UplinkSocket::Message() << "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START";
Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START";
Anope::Quitting = true;
return;
}
/* reset CAPAB */
chmodes.clear();
umodes.clear();
Servers::Capab.insert("SERVERS");
Servers::Capab.insert("CHGHOST");
Servers::Capab.insert("CHGIDENT");
Servers::Capab.insert("TOPICLOCK");
IRCD->CanSVSHold = false;
}
else if (params[0].equals_cs("CHANMODES") && params.size() > 1)
{
spacesepstream ssep(params[1]);
Anope::string capab;
while (ssep.GetToken(capab))
{
Anope::string modename = capab.substr(0, capab.find('='));
Anope::string modechar = capab.substr(capab.find('=') + 1);
ChannelMode *cm = NULL;
if (modename.equals_cs("admin"))
cm = new ChannelModeStatus("PROTECT", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 3);
else if (modename.equals_cs("allowinvite"))
cm = new ChannelMode("ALLINVITE", modechar[0]);
else if (modename.equals_cs("auditorium"))
cm = new ChannelMode("AUDITORIUM", modechar[0]);
else if (modename.equals_cs("ban"))
cm = new InspIRCdExtBan("BAN", modechar[0]);
else if (modename.equals_cs("banexception"))
cm = new InspIRCdExtBan("EXCEPT", 'e');
else if (modename.equals_cs("blockcaps"))
cm = new ChannelMode("BLOCKCAPS", modechar[0]);
else if (modename.equals_cs("blockcolor"))
cm = new ChannelMode("BLOCKCOLOR", modechar[0]);
else if (modename.equals_cs("c_registered"))
cm = new ChannelModeNoone("REGISTERED", modechar[0]);
else if (modename.equals_cs("censor"))
cm = new ChannelMode("FILTER", modechar[0]);
else if (modename.equals_cs("delayjoin"))
cm = new ChannelMode("DELAYEDJOIN", modechar[0]);
else if (modename.equals_cs("delaymsg"))
cm = new SimpleNumberParamMode("DELAYMSG", modechar[0]);
else if (modename.equals_cs("filter"))
cm = new ChannelModeList("FILTER", modechar[0]);
else if (modename.equals_cs("flood"))
cm = new ChannelModeFlood(modechar[0]);
else if (modename.equals_cs("founder"))
cm = new ChannelModeStatus("OWNER", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 4);
else if (modename.equals_cs("halfop"))
cm = new ChannelModeStatus("HALFOP", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 1);
else if (modename.equals_cs("history"))
cm = new ChannelModeHistory(modechar[0]);
else if (modename.equals_cs("invex"))
cm = new InspIRCdExtBan("INVITEOVERRIDE", 'I');
else if (modename.equals_cs("inviteonly"))
cm = new ChannelMode("INVITE", modechar[0]);
else if (modename.equals_cs("joinflood"))
cm = new ColonDelimitedParamMode("JOINFLOOD", modechar[0]);
else if (modename.equals_cs("key"))
cm = new ChannelModeKey(modechar[0]);
else if (modename.equals_cs("kicknorejoin"))
cm = new SimpleNumberParamMode("NOREJOIN", modechar[0]);
else if (modename.equals_cs("limit"))
cm = new ChannelModeParam("LIMIT", modechar[0], true);
else if (modename.equals_cs("moderated"))
cm = new ChannelMode("MODERATED", modechar[0]);
else if (modename.equals_cs("nickflood"))
cm = new ColonDelimitedParamMode("NICKFLOOD", modechar[0]);
else if (modename.equals_cs("noctcp"))
cm = new ChannelMode("NOCTCP", modechar[0]);
else if (modename.equals_cs("noextmsg"))
cm = new ChannelMode("NOEXTERNAL", modechar[0]);
else if (modename.equals_cs("nokick"))
cm = new ChannelMode("NOKICK", modechar[0]);
else if (modename.equals_cs("noknock"))
cm = new ChannelMode("NOKNOCK", modechar[0]);
else if (modename.equals_cs("nonick"))
cm = new ChannelMode("NONICK", modechar[0]);
else if (modename.equals_cs("nonotice"))
cm = new ChannelMode("NONOTICE", modechar[0]);
else if (modename.equals_cs("op"))
cm = new ChannelModeStatus("OP", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 2);
else if (modename.equals_cs("operonly"))
cm = new ChannelModeOperOnly("OPERONLY", modechar[0]);
else if (modename.equals_cs("permanent"))
cm = new ChannelMode("PERM", modechar[0]);
else if (modename.equals_cs("private"))
cm = new ChannelMode("PRIVATE", modechar[0]);
else if (modename.equals_cs("redirect"))
cm = new ChannelModeRedirect(modechar[0]);
else if (modename.equals_cs("reginvite"))
cm = new ChannelMode("REGISTEREDONLY", modechar[0]);
else if (modename.equals_cs("regmoderated"))
cm = new ChannelMode("REGMODERATED", modechar[0]);
else if (modename.equals_cs("secret"))
cm = new ChannelMode("SECRET", modechar[0]);
else if (modename.equals_cs("sslonly"))
cm = new ChannelMode("SSL", modechar[0]);
else if (modename.equals_cs("stripcolor"))
cm = new ChannelMode("STRIPCOLOR", modechar[0]);
else if (modename.equals_cs("topiclock"))
cm = new ChannelMode("TOPIC", modechar[0]);
else if (modename.equals_cs("voice"))
cm = new ChannelModeStatus("VOICE", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 0);
/* Unknown status mode, (customprefix) - add it */
else if (modechar.length() == 2)
cm = new ChannelModeStatus(modename.upper(), modechar[1], modechar[0], -1);
/* Unknown non status mode, add it to our list for later */
else
chmodes[modechar[0]] = modename.upper();
if (cm)
ModeManager::AddChannelMode(cm);
}
}
if (params[0].equals_cs("USERMODES") && params.size() > 1)
{
spacesepstream ssep(params[1]);
Anope::string capab;
while (ssep.GetToken(capab))
{
Anope::string modename = capab.substr(0, capab.find('='));
Anope::string modechar = capab.substr(capab.find('=') + 1);
UserMode *um = NULL;
if (modename.equals_cs("bot"))
um = new UserMode("BOT", modechar[0]);
else if (modename.equals_cs("callerid"))
um = new UserMode("CALLERID", modechar[0]);
else if (modename.equals_cs("cloak"))
um = new UserMode("CLOAK", modechar[0]);
else if (modename.equals_cs("deaf"))
um = new UserMode("DEAF", modechar[0]);
else if (modename.equals_cs("deaf_commonchan"))
um = new UserMode("COMMONCHANS", modechar[0]);
else if (modename.equals_cs("helpop"))
um = new UserModeOperOnly("HELPOP", modechar[0]);
else if (modename.equals_cs("hidechans"))
um = new UserMode("PRIV", modechar[0]);
else if (modename.equals_cs("hideoper"))
um = new UserModeOperOnly("HIDEOPER", modechar[0]);
else if (modename.equals_cs("invisible"))
um = new UserMode("INVIS", modechar[0]);
else if (modename.equals_cs("invis-oper"))
um = new UserModeOperOnly("INVISIBLE_OPER", modechar[0]);
else if (modename.equals_cs("oper"))
um = new UserModeOperOnly("OPER", modechar[0]);
else if (modename.equals_cs("regdeaf"))
um = new UserMode("REGPRIV", modechar[0]);
else if (modename.equals_cs("servprotect"))
{
um = new UserModeNoone("PROTECTED", modechar[0]);
IRCD->DefaultPseudoclientModes += modechar;
}
else if (modename.equals_cs("showwhois"))
um = new UserMode("WHOIS", modechar[0]);
else if (modename.equals_cs("u_censor"))
um = new UserMode("FILTER", modechar[0]);
else if (modename.equals_cs("u_registered"))
um = new UserModeNoone("REGISTERED", modechar[0]);
else if (modename.equals_cs("u_stripcolor"))
um = new UserMode("STRIPCOLOR", modechar[0]);
else if (modename.equals_cs("wallops"))
um = new UserMode("WALLOPS", modechar[0]);
else
umodes[modechar[0]] = modename.upper();
if (um)
ModeManager::AddUserMode(um);
}
}
else if (params[0].equals_cs("MODULES") && params.size() > 1)
{
spacesepstream ssep(params[1]);
Anope::string module;
while (ssep.GetToken(module))
{
if (module.equals_cs("m_svshold.so"))
IRCD->CanSVSHold = true;
else if (module.find("m_rline.so") == 0)
{
Servers::Capab.insert("RLINE");
const Anope::string ®exengine = Config->GetBlock("options")->Get<const Anope::string>("regexengine");
if (!regexengine.empty() && module.length() > 11 && regexengine != module.substr(11))
Log() << "Warning: InspIRCd is using regex engine " << module.substr(11) << ", but we have " << regexengine << ". This may cause inconsistencies.";
}
else if (module.equals_cs("m_topiclock.so"))
Servers::Capab.insert("TOPICLOCK");
}
}
else if (params[0].equals_cs("MODSUPPORT") && params.size() > 1)
{
spacesepstream ssep(params[1]);
Anope::string module;
while (ssep.GetToken(module))
{
if (module.equals_cs("m_services_account.so"))
Servers::Capab.insert("SERVICES");
else if (module.equals_cs("m_chghost.so"))
Servers::Capab.insert("CHGHOST");
else if (module.equals_cs("m_chgident.so"))
Servers::Capab.insert("CHGIDENT");
}
}
else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1)
{
spacesepstream ssep(params[1]);
Anope::string capab;
while (ssep.GetToken(capab))
{
if (capab.find("CHANMODES") != Anope::string::npos)
{
Anope::string modes(capab.begin() + 10, capab.end());
commasepstream sep(modes);
Anope::string modebuf;
sep.GetToken(modebuf);
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
if (ModeManager::FindChannelModeByChar(modebuf[t]))
continue;
ModeManager::AddChannelMode(new ChannelModeList(chmodes[modebuf[t]], modebuf[t]));
}
sep.GetToken(modebuf);
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
if (ModeManager::FindChannelModeByChar(modebuf[t]))
continue;
ModeManager::AddChannelMode(new ChannelModeParam(chmodes[modebuf[t]], modebuf[t]));
}
sep.GetToken(modebuf);
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
if (ModeManager::FindChannelModeByChar(modebuf[t]))
continue;
ModeManager::AddChannelMode(new ChannelModeParam(chmodes[modebuf[t]], modebuf[t], true));
}
sep.GetToken(modebuf);
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
if (ModeManager::FindChannelModeByChar(modebuf[t]))
continue;
ModeManager::AddChannelMode(new ChannelMode(chmodes[modebuf[t]], modebuf[t]));
}
}
else if (capab.find("USERMODES") != Anope::string::npos)
{
Anope::string modes(capab.begin() + 10, capab.end());
commasepstream sep(modes);
Anope::string modebuf;
sep.GetToken(modebuf);
sep.GetToken(modebuf);
if (sep.GetToken(modebuf))
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
ModeManager::AddUserMode(new UserModeParam(umodes[modebuf[t]], modebuf[t]));
if (sep.GetToken(modebuf))
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
ModeManager::AddUserMode(new UserMode(umodes[modebuf[t]], modebuf[t]));
}
else if (capab.find("MAXMODES=") != Anope::string::npos)
{
Anope::string maxmodes(capab.begin() + 9, capab.end());
IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3;
}
else if (capab.find("PREFIX=") != Anope::string::npos)
{
Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')'));
Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end());
short level = modes.length() - 1;
for (size_t t = 0, end = modes.length(); t < end; ++t)
{
ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[t]);
if (cm == NULL || cm->type != MODE_STATUS)
{
Log() << "CAPAB PREFIX gave unknown channel status mode " << modes[t];
continue;
}
ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm);
cms->level = level--;
Log(LOG_DEBUG) << cms->name << " is now level " << cms->level;
}
ModeManager::RebuildStatusModes();
}
}
}
else if (params[0].equals_cs("END"))
{
if (!Servers::Capab.count("SERVICES"))
{
UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope";
Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required.";
Anope::Quitting = true;
return;
}
if (!ModeManager::FindUserModeByName("PRIV"))
{
UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope";
Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required.";
Anope::Quitting = true;
return;
}
if (!IRCD->CanSVSHold)
Log() << "SVSHOLD missing, Usage disabled until module is loaded.";
if (!Servers::Capab.count("CHGHOST"))
Log() << "CHGHOST missing, Usage disabled until module is loaded.";
if (!Servers::Capab.count("CHGIDENT"))
Log() << "CHGIDENT missing, Usage disabled until module is loaded.";
chmodes.clear();
umodes.clear();
}
Message::Capab::Run(source, params);
}
};
struct IRCDMessageEncap : IRCDMessage
{
ServiceReference<IRCDMessage> insp12_encap;
IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4), insp12_encap("IRCDMessage", "inspircd12/encap") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
if (Anope::Match(Me->GetSID(), params[0]) == false)
return;
if (params[1] == "CHGIDENT")
{
User *u = User::Find(params[2]);
if (!u || u->server != Me)
return;
u->SetIdent(params[3]);
UplinkSocket::Message(u) << "FIDENT " << params[3];
}
else if (params[1] == "CHGHOST")
{
User *u = User::Find(params[2]);
if (!u || u->server != Me)
return;
u->SetDisplayedHost(params[3]);
UplinkSocket::Message(u) << "FHOST " << params[3];
}
else if (params[1] == "CHGNAME")
{
User *u = User::Find(params[2]);
if (!u || u->server != Me)
return;
u->SetRealname(params[3]);
UplinkSocket::Message(u) << "FNAME " << params[3];
}
if (insp12_encap)
insp12_encap->Run(source, params);
}
};
struct IRCDMessageFIdent : IRCDMessage
{
IRCDMessageFIdent(Module *creator) : IRCDMessage(creator, "FIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
source.GetUser()->SetIdent(params[0]);
}
};
class ProtoInspIRCd : public Module
{
Module *m_insp12;
InspIRCd20Proto ircd_proto;
/* Core message handlers */
Message::Away message_away;
Message::Error message_error;
Message::Invite message_invite;
Message::Join message_join;
Message::Kick message_kick;
Message::Kill message_kill;
Message::MOTD message_motd;
Message::Notice message_notice;
Message::Part message_part;
Message::Ping message_ping;
Message::Privmsg message_privmsg;
Message::Quit message_quit;
Message::Stats message_stats;
Message::Topic message_topic;
/* InspIRCd 1.2 message handlers */
ServiceAlias message_endburst, message_fhost, message_fjoin, message_fmode,
message_ftopic, message_idle, message_metadata, message_mode,
message_nick, message_opertype, message_rsquit, message_server,
message_squit, message_time, message_uid;
/* Our message handlers */
IRCDMessageCapab message_capab;
IRCDMessageEncap message_encap;
IRCDMessageFIdent message_fident;
bool use_server_side_topiclock, use_server_side_mlock;
void SendChannelMetadata(Channel *c, const Anope::string &metadataname, const Anope::string &value)
{
UplinkSocket::Message(Me) << "METADATA " << c->name << " " << metadataname << " :" << value;
}
public:
ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this),
message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this),
message_kill(this), message_motd(this), message_notice(this), message_part(this), message_ping(this),
message_privmsg(this), message_quit(this), message_stats(this), message_topic(this),
message_endburst("IRCDMessage", "inspircd20/endburst", "inspircd12/endburst"),
message_fhost("IRCDMessage", "inspircd20/fhost", "inspircd12/fhost"),
message_fjoin("IRCDMessage", "inspircd20/fjoin", "inspircd12/fjoin"),
message_fmode("IRCDMessage", "inspircd20/fmode", "inspircd12/fmode"),
message_ftopic("IRCDMessage", "inspircd20/ftopic", "inspircd12/ftopic"),
message_idle("IRCDMessage", "inspircd20/idle", "inspircd12/idle"),
message_metadata("IRCDMessage", "inspircd20/metadata", "inspircd12/metadata"),
message_mode("IRCDMessage", "inspircd20/mode", "inspircd12/mode"),
message_nick("IRCDMessage", "inspircd20/nick", "inspircd12/nick"),
message_opertype("IRCDMessage", "inspircd20/opertype", "inspircd12/opertype"),
message_rsquit("IRCDMessage", "inspircd20/rsquit", "inspircd12/rsquit"),
message_server("IRCDMessage", "inspircd20/server", "inspircd12/server"),
message_squit("IRCDMessage", "inspircd20/squit", "inspircd12/squit"),
message_time("IRCDMessage", "inspircd20/time", "inspircd12/time"),
message_uid("IRCDMessage", "inspircd20/uid", "inspircd12/uid"),
message_capab(this), message_encap(this), message_fident(this)
{
if (ModuleManager::LoadModule("inspircd12", User::Find(creator)) != MOD_ERR_OK)
throw ModuleException("Unable to load inspircd12");
m_insp12 = ModuleManager::FindModule("inspircd12");
if (!m_insp12)
throw ModuleException("Unable to find inspircd12");
if (!insp12)
throw ModuleException("No protocol interface for insp12");
ModuleManager::DetachAll(m_insp12);
}
~ProtoInspIRCd()
{
m_insp12 = ModuleManager::FindModule("inspircd12");
ModuleManager::UnloadModule(m_insp12, NULL);
}
void OnReload(Configuration::Conf *conf) anope_override
{
use_server_side_topiclock = conf->GetModule(this)->Get<bool>("use_server_side_topiclock");
use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock");
}
void OnUserNickChange(User *u, const Anope::string &) anope_override
{
u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED"));
}
void OnChannelSync(Channel *c) anope_override
{
if (c->ci)
this->OnChanRegistered(c->ci);
}
void OnChanRegistered(ChannelInfo *ci) anope_override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
if (use_server_side_mlock && ci->c && modelocks && !modelocks->GetMLockAsString(false).empty())
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
SendChannelMetadata(ci->c, "mlock", modes);
}
if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && ci->c)
{
if (ci->HasExt("TOPICLOCK"))
SendChannelMetadata(ci->c, "topiclock", "1");
}
}
void OnDelChan(ChannelInfo *ci) anope_override
{
if (use_server_side_mlock && ci->c)
SendChannelMetadata(ci->c, "mlock", "");
if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && ci->c)
SendChannelMetadata(ci->c, "topiclock", "");
}
EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM))
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar;
SendChannelMetadata(ci->c, "mlock", modes);
}
return EVENT_CONTINUE;
}
EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM))
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, "");
SendChannelMetadata(ci->c, "mlock", modes);
}
return EVENT_CONTINUE;
}
EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) anope_override
{
if (cmd->name == "chanserv/topic" && ci->c)
{
if (setting == "topiclock on")
SendChannelMetadata(ci->c, "topiclock", "1");
else if (setting == "topiclock off")
SendChannelMetadata(ci->c, "topiclock", "0");
}
return EVENT_CONTINUE;
}
};
MODULE_INIT(ProtoInspIRCd)
|