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 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
|
/* inspircd 1.2 functions
*
* (C) 2003-2024 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/sasl.h"
struct SASLUser
{
Anope::string uid;
Anope::string acc;
time_t created;
};
static std::list<SASLUser> saslusers;
static Anope::string rsquit_server, rsquit_id;
class ChannelModeFlood : public ChannelModeParam
{
public:
ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { }
bool IsValid(Anope::string &value) const anope_override
{
try
{
Anope::string rest;
if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty())
return true;
}
catch (const ConvertException &) { }
return false;
}
};
class InspIRCd12Proto : public IRCDProto
{
private:
void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override
{
IRCDProto::SendSVSKillInternal(source, user, buf);
user->KillInternal(source, buf);
}
void SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent)
{
if (!Servers::Capab.count("CHGIDENT"))
Log() << "CHGIDENT not loaded!";
else
UplinkSocket::Message(Me) << "CHGIDENT " << nick << " " << vIdent;
}
void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost)
{
if (!Servers::Capab.count("CHGHOST"))
Log() << "CHGHOST not loaded!";
else
UplinkSocket::Message(Me) << "CHGHOST " << nick << " " << vhost;
}
void SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason)
{
UplinkSocket::Message(Me) << "ADDLINE " << xtype << " " << mask << " " << addedby << " " << Anope::CurTime << " " << duration << " :" << reason;
}
void SendDelLine(const Anope::string &xtype, const Anope::string &mask)
{
UplinkSocket::Message(Me) << "DELLINE " << xtype << " " << mask;
}
public:
InspIRCd12Proto(Module *creator) : IRCDProto(creator, "InspIRCd 1.2")
{
DefaultPseudoclientModes = "+I";
CanSVSNick = true;
CanSVSJoin = true;
CanSetVHost = true;
CanSetVIdent = true;
CanSQLine = true;
CanSZLine = true;
CanSVSHold = true;
CanCertFP = true;
RequiresID = true;
MaxModes = 20;
}
void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
{
UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg;
}
void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
{
UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg;
}
void SendAkillDel(const XLine *x) anope_override
{
/* InspIRCd may support regex bans
* Mask is expected in format: 'n!u@h\sr' and spaces as '\s'
* We remove the '//' and replace '#' and any ' ' with '\s'
*/
if (x->IsRegex() && Servers::Capab.count("RLINE"))
{
Anope::string mask = x->mask;
if (mask.length() >= 2 && mask[0] == '/' && mask[mask.length() - 1] == '/')
mask = mask.substr(1, mask.length() - 2);
size_t h = mask.find('#');
if (h != Anope::string::npos)
{
mask = mask.replace(h, 1, "\\s");
mask = mask.replace_all_cs(" ", "\\s");
}
SendDelLine("R", mask);
return;
}
else if (x->IsRegex() || x->HasNickOrReal())
return;
/* ZLine if we can instead */
if (x->GetUser() == "*")
{
cidr addr(x->GetHost());
if (addr.valid())
{
IRCD->SendSZLineDel(x);
return;
}
}
SendDelLine("G", x->GetUser() + "@" + x->GetHost());
}
void SendTopic(const MessageSource &source, Channel *c) anope_override
{
if (Servers::Capab.count("SVSTOPIC"))
{
UplinkSocket::Message(c->WhoSends()) << "SVSTOPIC " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic;
}
else
{
/* If the last time a topic was set is after the TS we want for this topic we must bump this topic's timestamp to now */
time_t ts = c->topic_ts;
if (c->topic_time > ts)
ts = Anope::CurTime;
/* But don't modify c->topic_ts, it should remain set to the real TS we want as ci->last_topic_time pulls from it */
UplinkSocket::Message(source) << "FTOPIC " << c->name << " " << ts << " " << c->topic_setter << " :" << c->topic;
}
}
void SendVhostDel(User *u) anope_override
{
UserMode *um = ModeManager::FindUserModeByName("CLOAK");
if (um && !u->HasMode(um->name))
// Just set +x if we can
u->SetMode(NULL, um);
else
// Try to restore cloaked host
this->SendChgHostInternal(u->nick, u->chost);
}
void SendAkill(User *u, XLine *x) anope_override
{
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->expires - Anope::CurTime;
if (timeleft > 172800 || !x->expires)
timeleft = 172800;
/* InspIRCd may support regex bans, if they do we can send this and forget about it
* Mask is expected in format: 'n!u@h\sr' and spaces as '\s'
* We remove the '//' and replace '#' and any ' ' with '\s'
*/
if (x->IsRegex() && Servers::Capab.count("RLINE"))
{
Anope::string mask = x->mask;
if (mask.length() >= 2 && mask[0] == '/' && mask[mask.length() - 1] == '/')
mask = mask.substr(1, mask.length() - 2);
size_t h = mask.find('#');
if (h != Anope::string::npos)
{
mask = mask.replace(h, 1, "\\s");
mask = mask.replace_all_cs(" ", "\\s");
}
SendAddLine("R", mask, timeleft, x->by, x->GetReason());
return;
}
else if (x->IsRegex() || x->HasNickOrReal())
{
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (x->manager->Check(it->second, x))
this->SendAkill(it->second, x);
return;
}
const XLine *old = x;
if (old->manager->HasEntry("*@" + u->host))
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
x = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id);
old->manager->AddXLine(x);
Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask;
}
/* ZLine if we can instead */
if (x->GetUser() == "*")
{
cidr addr(x->GetHost());
if (addr.valid())
{
IRCD->SendSZLine(u, x);
return;
}
}
SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->by, x->GetReason());
}
void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override
{
User *u = User::Find(dest);
UplinkSocket::Message() << "PUSH " << dest << " ::" << Me->GetName() << " " << numeric << " " << (u ? u->nick : dest) << " " << buf;
}
void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override
{
UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf;
}
void SendClientIntroduction(User *u) anope_override
{
Anope::string modes = "+" + u->GetModes();
UplinkSocket::Message(Me) << "UID " << u->GetUID() << " " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " 0.0.0.0 " << u->timestamp << " " << modes << " :" << u->realname;
if (modes.find('o') != Anope::string::npos)
{
// Mark as introduced so we can send an oper type.
BotInfo *bi = BotInfo::Find(u->nick, true);
if (bi)
bi->introduced = true;
UplinkSocket::Message(u) << "OPERTYPE :service";
}
}
/* SERVER services-dev.chatspike.net password 0 :Description here */
void SendServer(const Server *server) anope_override
{
/* if rsquit is set then we are waiting on a squit */
if (rsquit_id.empty() && rsquit_server.empty())
UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[Anope::CurrentUplink].password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription();
}
void SendSquit(Server *s, const Anope::string &message) anope_override
{
if (s != Me)
{
rsquit_id = s->GetSID();
rsquit_server = s->GetName();
UplinkSocket::Message() << "RSQUIT " << s->GetName() << " :" << message;
}
else
UplinkSocket::Message() << "SQUIT " << s->GetName() << " :" << message;
}
/* JOIN */
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
{
UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID();
/* Note that we can send this with the FJOIN but choose not to
* because the mode stacker will handle this and probably will
* merge these modes with +nrt and other mlocked modes
*/
if (status)
{
/* First save the channel status incase uc->Status == status */
ChannelStatus cs = *status;
/* If the user is internally on the channel with flags, kill them so that
* the stacker will allow this.
*/
ChanUserContainer *uc = c->FindUser(user);
if (uc != NULL)
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
for (size_t i = 0; i < cs.Modes().length(); ++i)
c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
/* UNSQLINE */
void SendSQLineDel(const XLine *x) anope_override
{
SendDelLine("Q", x->mask);
}
/* SQLINE */
void SendSQLine(User *, const XLine *x) anope_override
{
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->expires - Anope::CurTime;
if (timeleft > 172800 || !x->expires)
timeleft = 172800;
SendAddLine("Q", x->mask, timeleft, x->by, x->GetReason());
}
void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override
{
if (!vIdent.empty())
this->SendChgIdentInternal(u->nick, vIdent);
if (!vhost.empty())
this->SendChgHostInternal(u->nick, vhost);
}
void SendConnect() anope_override
{
SendServer(Me);
}
/* SVSHOLD - set */
void SendSVSHold(const Anope::string &nick, time_t t) anope_override
{
UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick << " " << t << " :Being held for registered user";
}
/* SVSHOLD - release */
void SendSVSHoldDel(const Anope::string &nick) anope_override
{
UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick;
}
/* UNSZLINE */
void SendSZLineDel(const XLine *x) anope_override
{
SendDelLine("Z", x->GetHost());
}
/* SZLINE */
void SendSZLine(User *, const XLine *x) anope_override
{
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->expires - Anope::CurTime;
if (timeleft > 172800 || !x->expires)
timeleft = 172800;
SendAddLine("Z", x->GetHost(), timeleft, x->by, x->GetReason());
}
void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) anope_override
{
UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan;
}
void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override
{
if (!param.empty())
UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param;
else
UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan;
}
void SendSWhois(const MessageSource &, const Anope::string &who, const Anope::string &mask) anope_override
{
User *u = User::Find(who);
UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " swhois :" << mask;
}
void SendBOB() anope_override
{
UplinkSocket::Message(Me) << "BURST " << Anope::CurTime;
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << IRCD->GetProtocolName() << " - (" << (enc ? enc->name : "none") << ") -- " << Anope::VersionBuildString();
}
void SendEOB() anope_override
{
UplinkSocket::Message(Me) << "ENDBURST";
}
void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
{
if (Servers::Capab.count("GLOBOPS"))
UplinkSocket::Message(source) << "SNONOTICE g :" << buf;
else
UplinkSocket::Message(source) << "SNONOTICE A :" << buf;
}
void SendLogin(User *u, NickAlias *na) anope_override
{
/* InspIRCd uses an account to bypass chmode +R, not umode +r, so we can't send this here */
if (na->nc->HasExt("UNCONFIRMED"))
return;
UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->nc->display;
}
void SendLogout(User *u) anope_override
{
UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :";
}
void SendChannel(Channel *c) anope_override
{
UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :";
}
void SendOper(User *u) anope_override
{
}
void SendSASLMessage(const SASL::Message &message) anope_override
{
UplinkSocket::Message(Me) << "ENCAP " << message.target.substr(0, 3) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext));
}
void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override
{
UplinkSocket::Message(Me) << "METADATA " << uid << " accountname :" << acc;
if (!vident.empty())
UplinkSocket::Message(Me) << "ENCAP " << uid.substr(0, 3) << " CHGIDENT " << uid << " " << vident;
if (!vhost.empty())
UplinkSocket::Message(Me) << "ENCAP " << uid.substr(0, 3) << " CHGHOST " << uid << " " << vhost;
SASLUser su;
su.uid = uid;
su.acc = acc;
su.created = Anope::CurTime;
for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
{
SASLUser &u = *it;
if (u.created + 30 < Anope::CurTime || u.uid == uid)
it = saslusers.erase(it);
else
++it;
}
saslusers.push_back(su);
}
bool IsExtbanValid(const Anope::string &mask) anope_override
{
return mask.length() >= 3 && mask[1] == ':';
}
bool IsIdentValid(const Anope::string &ident) anope_override
{
if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
return false;
for (unsigned i = 0; i < ident.length(); ++i)
{
const char &c = ident[i];
if (c >= 'A' && c <= '}')
continue;
if ((c >= '0' && c <= '9') || c == '-' || c == '.')
continue;
return false;
}
return true;
}
};
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(2);
Entry en(this->name, real_mask);
if (en.Matches(u))
return true;
}
else if (mask.find("j:") == 0)
{
Anope::string real_mask = mask.substr(2);
Channel *c = Channel::Find(real_mask);
if (c != NULL && c->FindUser(u) != NULL)
return true;
}
else if (mask.find("M:") == 0 || 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;
}
return false;
}
};
struct IRCDMessageCapab : Message::Capab
{
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"))
{
/* reset CAPAB */
Servers::Capab.clear();
Servers::Capab.insert("NOQUIT");
IRCD->CanSVSHold = false;
}
else if (params[0].equals_cs("MODULES") && params.size() > 1)
{
if (params[1].find("m_globops.so") != Anope::string::npos)
Servers::Capab.insert("GLOBOPS");
if (params[1].find("m_services_account.so") != Anope::string::npos)
Servers::Capab.insert("SERVICES");
if (params[1].find("m_svshold.so") != Anope::string::npos)
IRCD->CanSVSHold = true;
if (params[1].find("m_chghost.so") != Anope::string::npos)
Servers::Capab.insert("CHGHOST");
if (params[1].find("m_chgident.so") != Anope::string::npos)
Servers::Capab.insert("CHGIDENT");
if (params[1].find("m_hidechans.so") != Anope::string::npos)
Servers::Capab.insert("HIDECHANS");
if (params[1].find("m_servprotect.so") != Anope::string::npos)
IRCD->DefaultPseudoclientModes = "+Ik";
if (params[1].find("m_rline.so") != Anope::string::npos)
Servers::Capab.insert("RLINE");
}
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)
{
switch (modebuf[t])
{
case 'b':
ModeManager::AddChannelMode(new InspIRCdExtBan("BAN", 'b'));
continue;
case 'e':
ModeManager::AddChannelMode(new InspIRCdExtBan("EXCEPT", 'e'));
continue;
case 'I':
ModeManager::AddChannelMode(new InspIRCdExtBan("INVITEOVERRIDE", 'I'));
continue;
/* InspIRCd sends q and a here if they have no prefixes */
case 'q':
ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '@', 4));
continue;
case 'a':
ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT" , 'a', '@', 3));
continue;
default:
ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t]));
}
}
sep.GetToken(modebuf);
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
case 'k':
ModeManager::AddChannelMode(new ChannelModeKey('k'));
continue;
default:
ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t]));
}
}
sep.GetToken(modebuf);
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
case 'F':
ModeManager::AddChannelMode(new ChannelModeParam("NICKFLOOD", 'F', true));
continue;
case 'J':
ModeManager::AddChannelMode(new ChannelModeParam("NOREJOIN", 'J', true));
continue;
case 'L':
ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L', true));
continue;
case 'f':
ModeManager::AddChannelMode(new ChannelModeFlood('f', true));
continue;
case 'j':
ModeManager::AddChannelMode(new ChannelModeParam("JOINFLOOD", 'j', true));
continue;
case 'l':
ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true));
continue;
default:
ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true));
}
}
sep.GetToken(modebuf);
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
case 'A':
ModeManager::AddChannelMode(new ChannelMode("ALLINVITE", 'A'));
continue;
case 'B':
ModeManager::AddChannelMode(new ChannelMode("BLOCKCAPS", 'B'));
continue;
case 'C':
ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C'));
continue;
case 'D':
ModeManager::AddChannelMode(new ChannelMode("DELAYEDJOIN", 'D'));
continue;
case 'G':
ModeManager::AddChannelMode(new ChannelMode("CENSOR", 'G'));
continue;
case 'K':
ModeManager::AddChannelMode(new ChannelMode("NOKNOCK", 'K'));
continue;
case 'M':
ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M'));
continue;
case 'N':
ModeManager::AddChannelMode(new ChannelMode("NONICK", 'N'));
continue;
case 'O':
ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O'));
continue;
case 'P':
ModeManager::AddChannelMode(new ChannelMode("PERM", 'P'));
continue;
case 'Q':
ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q'));
continue;
case 'R':
ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R'));
continue;
case 'S':
ModeManager::AddChannelMode(new ChannelMode("STRIPCOLOR", 'S'));
continue;
case 'T':
ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'T'));
continue;
case 'c':
ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c'));
continue;
case 'i':
ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i'));
continue;
case 'm':
ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm'));
continue;
case 'n':
ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n'));
continue;
case 'p':
ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p'));
continue;
case 'r':
ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r'));
continue;
case 's':
ModeManager::AddChannelMode(new ChannelMode("SECRET", 's'));
continue;
case 't':
ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't'));
continue;
case 'u':
ModeManager::AddChannelMode(new ChannelMode("AUDITORIUM", 'u'));
continue;
case 'z':
ModeManager::AddChannelMode(new ChannelMode("SSL", 'z'));
continue;
default:
ModeManager::AddChannelMode(new ChannelMode("", modebuf[t]));
}
}
}
else if (capab.find("USERMODES") != Anope::string::npos)
{
Anope::string modes(capab.begin() + 10, capab.end());
commasepstream sep(modes);
Anope::string modebuf;
while (sep.GetToken(modebuf))
{
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
case 'h':
ModeManager::AddUserMode(new UserModeOperOnly("HELPOP", 'h'));
continue;
case 'B':
ModeManager::AddUserMode(new UserMode("BOT", 'B'));
continue;
case 'G':
ModeManager::AddUserMode(new UserMode("CENSOR", 'G'));
continue;
case 'H':
ModeManager::AddUserMode(new UserModeOperOnly("HIDEOPER", 'H'));
continue;
case 'I':
ModeManager::AddUserMode(new UserMode("PRIV", 'I'));
continue;
case 'Q':
ModeManager::AddUserMode(new UserModeOperOnly("HIDDEN", 'Q'));
continue;
case 'R':
ModeManager::AddUserMode(new UserMode("REGPRIV", 'R'));
continue;
case 'S':
ModeManager::AddUserMode(new UserMode("STRIPCOLOR", 'S'));
continue;
case 'W':
ModeManager::AddUserMode(new UserMode("WHOIS", 'W'));
continue;
case 'c':
ModeManager::AddUserMode(new UserMode("COMMONCHANS", 'c'));
continue;
case 'g':
ModeManager::AddUserMode(new UserMode("CALLERID", 'g'));
continue;
case 'i':
ModeManager::AddUserMode(new UserMode("INVIS", 'i'));
continue;
case 'k':
ModeManager::AddUserMode(new UserModeNoone("PROTECTED", 'k'));
continue;
case 'o':
ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o'));
continue;
case 'r':
ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r'));
continue;
case 'w':
ModeManager::AddUserMode(new UserMode("WALLOPS", 'w'));
continue;
case 'x':
ModeManager::AddUserMode(new UserMode("CLOAK", 'x'));
continue;
case 'd':
ModeManager::AddUserMode(new UserMode("DEAF", 'd'));
continue;
default:
ModeManager::AddUserMode(new UserMode("", modebuf[t]));
}
}
}
}
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());
unsigned short level = modes.length() - 1;
for (size_t t = 0, end = modes.length(); t < end; ++t)
{
switch (modes[t])
{
case 'q':
ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', chars[t], level--));
continue;
case 'a':
ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', chars[t], level--));
continue;
case 'o':
ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', chars[t], level--));
continue;
case 'h':
ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', chars[t], level--));
continue;
case 'v':
ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', chars[t], level--));
continue;
default:
ModeManager::AddChannelMode(new ChannelModeStatus("", modes[t], chars[t], level--));
}
}
ModeManager::RebuildStatusModes();
}
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 (params[0].equals_cs("END"))
{
if (!Servers::Capab.count("GLOBOPS"))
{
UplinkSocket::Message() << "ERROR :m_globops is not loaded. This is required by Anope";
Anope::QuitReason = "Remote server does not have the m_globops module loaded, and this is required.";
Anope::Quitting = true;
return;
}
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 (!Servers::Capab.count("HIDECHANS"))
{
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.";
}
Message::Capab::Run(source, params);
}
};
struct IRCDMessageChgIdent : IRCDMessage
{
IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
User *u = User::Find(params[0]);
if (u)
u->SetIdent(params[1]);
}
};
struct IRCDMessageChgName : IRCDMessage
{
IRCDMessageChgName(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
source.GetUser()->SetRealname(params[0]);
}
};
struct IRCDMessageEncap : IRCDMessage
{
IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
if (!Anope::Match(Me->GetSID(), params[0]) && !Anope::Match(Me->GetName(), params[0]))
return;
if (SASL::sasl && params[1] == "SASL" && params.size() >= 6)
{
SASL::Message m;
m.source = params[2];
m.target = params[3];
m.type = params[4];
m.data = params[5];
m.ext = params.size() > 6 ? params[6] : "";
SASL::sasl->ProcessMessage(m);
}
}
};
struct IRCDMessageEndburst : IRCDMessage
{
IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
Server *s = source.GetServer();
Log(LOG_DEBUG) << "Processed ENDBURST for " << s->GetName();
s->Sync(true);
}
};
struct IRCDMessageFHost : IRCDMessage
{
IRCDMessageFHost(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
source.GetUser()->SetDisplayedHost(params[0]);
}
};
struct IRCDMessageFJoin : IRCDMessage
{
IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
Anope::string modes;
if (params.size() >= 3)
{
for (unsigned i = 2; i < params.size() - 1; ++i)
modes += " " + params[i];
if (!modes.empty())
modes.erase(modes.begin());
}
std::list<Message::Join::SJoinUser> users;
spacesepstream sep(params[params.size() - 1]);
Anope::string buf;
while (sep.GetToken(buf))
{
Message::Join::SJoinUser sju;
/* Loop through prefixes and find modes for them */
for (char c; (c = buf[0]) != ',' && c;)
{
buf.erase(buf.begin());
sju.first.AddMode(c);
}
/* Erase the , */
if (!buf.empty())
buf.erase(buf.begin());
sju.second = User::Find(buf);
if (!sju.second)
{
Log(LOG_DEBUG) << "FJOIN for nonexistent user " << buf << " on " << params[0];
continue;
}
users.push_back(sju);
}
time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime;
Message::Join::SJoin(source, params[0], ts, modes, users);
}
};
struct IRCDMessageFMode : IRCDMessage
{
IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
/* :source FMODE #test 12345678 +nto foo */
Anope::string modes = params[2];
for (unsigned n = 3; n < params.size(); ++n)
modes += " " + params[n];
Channel *c = Channel::Find(params[0]);
time_t ts;
try
{
ts = convertTo<time_t>(params[1]);
}
catch (const ConvertException &)
{
ts = 0;
}
if (c)
c->SetModesInternal(source, modes, ts);
}
};
struct IRCDMessageFTopic : IRCDMessage
{
IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
/* :source FTOPIC channel topicts setby :topic */
Channel *c = Channel::Find(params[0]);
if (c)
c->ChangeTopicInternal(NULL, params[2], params[3], Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime);
}
};
struct IRCDMessageIdle : IRCDMessage
{
IRCDMessageIdle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
BotInfo *bi = BotInfo::Find(params[0]);
if (bi)
UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " " << (Anope::CurTime - bi->lastmsg);
else
{
User *u = User::Find(params[0]);
if (u && u->server == Me)
UplinkSocket::Message(u) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " 0";
}
}
};
/*
* source = numeric of the sending server
* params[0] = uuid
* params[1] = metadata name
* params[2] = data
*/
struct IRCDMessageMetadata : IRCDMessage
{
IRCDMessageMetadata(Module *creator) : IRCDMessage(creator, "METADATA", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
if (isdigit(params[0][0]))
{
if (params[1].equals_cs("accountname"))
{
User *u = User::Find(params[0]);
NickCore *nc = NickCore::Find(params[2]);
if (u && nc)
u->Login(nc);
}
/*
* possible incoming ssl_cert messages:
* Received: :409 METADATA 409AAAAAA ssl_cert :vTrSe c38070ce96e41cc144ed6590a68d45a6 <...> <...>
* Received: :409 METADATA 409AAAAAC ssl_cert :vTrSE Could not get peer certificate: error:00000000:lib(0):func(0):reason(0)
*/
else if (params[1].equals_cs("ssl_cert"))
{
User *u = User::Find(params[0]);
if (!u)
return;
u->Extend<bool>("ssl");
Anope::string data = params[2].c_str();
size_t pos1 = data.find(' ') + 1;
size_t pos2 = data.find(' ', pos1);
if ((pos2 - pos1) >= 32) // inspircd supports md5 and sha1 fingerprint hashes -> size 32 or 40 bytes.
{
u->fingerprint = data.substr(pos1, pos2 - pos1);
}
FOREACH_MOD(OnFingerprint, (u));
}
}
else if (params[0][0] == '#')
{
}
else if (params[0] == "*")
{
// Wed Oct 3 15:40:27 2012: S[14] O :20D METADATA * modules :-m_svstopic.so
if (params[1].equals_cs("modules") && !params[2].empty())
{
// only interested when it comes from our uplink
Server* server = source.GetServer();
if (!server || server->GetUplink() != Me)
return;
bool plus = (params[2][0] == '+');
if (!plus && params[2][0] != '-')
return;
bool required = false;
Anope::string capab, module = params[2].substr(1);
if (module.equals_cs("m_services_account.so"))
required = true;
else if (module.equals_cs("m_hidechans.so"))
required = true;
else if (module.equals_cs("m_chghost.so"))
capab = "CHGHOST";
else if (module.equals_cs("m_chgident.so"))
capab = "CHGIDENT";
else if (module.equals_cs("m_svshold.so"))
capab = "SVSHOLD";
else if (module.equals_cs("m_rline.so"))
capab = "RLINE";
else if (module.equals_cs("m_topiclock.so"))
capab = "TOPICLOCK";
else
return;
if (required)
{
if (!plus)
Log() << "Warning: InspIRCd unloaded module " << module << ", Anope won't function correctly without it";
}
else
{
if (plus)
Servers::Capab.insert(capab);
else
Servers::Capab.erase(capab);
Log() << "InspIRCd " << (plus ? "loaded" : "unloaded") << " module " << module << ", adjusted functionality";
}
}
}
}
};
struct IRCDMessageMode : IRCDMessage
{
IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
if (IRCD->IsChannelValid(params[0]))
{
Channel *c = Channel::Find(params[0]);
Anope::string modes = params[1];
for (unsigned n = 2; n < params.size(); ++n)
modes += " " + params[n];
if (c)
c->SetModesInternal(source, modes);
}
else
{
/* InspIRCd lets opers change another
users modes, we have to kludge this
as it slightly breaks RFC1459
*/
User *u = User::Find(params[0]);
if (u)
u->SetModesInternal(source, "%s", params[1].c_str());
}
}
};
struct IRCDMessageNick : IRCDMessage
{
IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
source.GetUser()->ChangeNick(params[0]);
}
};
struct IRCDMessageOperType : IRCDMessage
{
IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
/* opertype is equivalent to mode +o because servers
don't do this directly */
User *u = source.GetUser();
if (!u->HasMode("OPER"))
u->SetModesInternal(source, "+o");
}
};
struct IRCDMessageRSQuit : IRCDMessage
{
IRCDMessageRSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
Server *s = Server::Find(params[0]);
const Anope::string &reason = params.size() > 1 ? params[1] : "";
if (!s)
return;
UplinkSocket::Message(Me) << "SQUIT " << s->GetSID() << " :" << reason;
s->Delete(s->GetName() + " " + s->GetUplink()->GetName());
}
};
struct IRCDMessageSetIdent : IRCDMessage
{
IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
source.GetUser()->SetIdent(params[0]);
}
};
struct IRCDMessageServer : IRCDMessage
{
IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 5) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
/*
* [Nov 04 00:08:46.308435 2009] debug: Received: SERVER irc.inspircd.com pass 0 964 :Testnet Central!
* 0: name
* 1: pass
* 2: hops
* 3: numeric
* 4: desc
*/
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
unsigned int hops = Anope::string(params[2]).is_pos_number_only() ? convertTo<unsigned>(params[2]) : 0;
new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[4], params[3]);
}
};
struct IRCDMessageSQuit : Message::SQuit
{
IRCDMessageSQuit(Module *creator) : Message::SQuit(creator) { }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
if (params[0] == rsquit_id || params[0] == rsquit_server)
{
/* squit for a recently squit server, introduce the juped server now */
Server *s = Server::Find(rsquit_server);
rsquit_id.clear();
rsquit_server.clear();
if (s && s->IsJuped())
IRCD->SendServer(s);
}
else
Message::SQuit::Run(source, params);
}
};
struct IRCDMessageTime : IRCDMessage
{
IRCDMessageTime(Module *creator) : IRCDMessage(creator, "TIME", 2) { }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
UplinkSocket::Message(Me) << "TIME " << source.GetSource() << " " << params[1] << " " << Anope::CurTime;
}
};
struct IRCDMessageUID : IRCDMessage
{
IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
/*
* [Nov 03 22:09:58.176252 2009] debug: Received: :964 UID 964AAAAAC 1225746297 w00t2 localhost testnet.user w00t 127.0.0.1 1225746302 +iosw +ACGJKLNOQcdfgjklnoqtx :Robin Burchell <w00t@inspircd.org>
* 0: uid
* 1: ts
* 2: nick
* 3: host
* 4: dhost
* 5: ident
* 6: ip
* 7: signon
* 8+: modes and params -- IMPORTANT, some modes (e.g. +s) may have parameters. So don't assume a fixed position of realname!
* last: realname
*/
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
time_t ts = convertTo<time_t>(params[1]);
Anope::string modes = params[8];
for (unsigned i = 9; i < params.size() - 1; ++i)
modes += " " + params[i];
NickAlias *na = NULL;
if (SASL::sasl)
for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
{
SASLUser &u = *it;
if (u.created + 30 < Anope::CurTime)
it = saslusers.erase(it);
else if (u.uid == params[0])
{
na = NickAlias::Find(u.acc);
it = saslusers.erase(it);
}
else
++it;
}
User *u = User::OnIntroduce(params[2], params[5], params[3], params[4], params[6], source.GetServer(), params[params.size() - 1], ts, modes, params[0], na ? *na->nc : NULL);
if (u)
u->signon = convertTo<time_t>(params[7]);
}
};
class ProtoInspIRCd12 : public Module
{
InspIRCd12Proto ircd_proto;
ExtensibleItem<bool> ssl;
/* 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;
/* Our message handlers */
IRCDMessageChgIdent message_chgident;
IRCDMessageChgName message_setname, message_chgname;
IRCDMessageCapab message_capab;
IRCDMessageEncap message_encap;
IRCDMessageEndburst message_endburst;
IRCDMessageFHost message_fhost, message_sethost;
IRCDMessageFJoin message_fjoin;
IRCDMessageFMode message_fmode;
IRCDMessageFTopic message_ftopic;
IRCDMessageIdle message_idle;
IRCDMessageMetadata message_metadata;
IRCDMessageMode message_mode;
IRCDMessageNick message_nick;
IRCDMessageOperType message_opertype;
IRCDMessageRSQuit message_rsquit;
IRCDMessageSetIdent message_setident;
IRCDMessageServer message_server;
IRCDMessageSQuit message_squit;
IRCDMessageTime message_time;
IRCDMessageUID message_uid;
public:
ProtoInspIRCd12(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this), ssl(this, "ssl"),
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_chgident(this), message_setname(this, "SETNAME"), message_chgname(this, "FNAME"), message_capab(this), message_encap(this),
message_endburst(this),
message_fhost(this, "FHOST"), message_sethost(this, "SETHOST"), message_fjoin(this), message_fmode(this), message_ftopic(this),
message_idle(this), message_metadata(this), message_mode(this), message_nick(this), message_opertype(this), message_rsquit(this),
message_setident(this), message_server(this), message_squit(this), message_time(this), message_uid(this)
{
Servers::Capab.insert("NOQUIT");
}
void OnUserNickChange(User *u, const Anope::string &) anope_override
{
/* InspIRCd 1.2 doesn't set -r on nick change, remove -r here. Note that if we have to set +r later
* this will cancel out this -r, resulting in no mode changes.
*
* Do not set -r if we don't have a NickServ loaded - DP
*/
BotInfo *NickServ = Config->GetClient("NickServ");
if (NickServ)
u->RemoveMode(NickServ, "REGISTERED");
}
};
MODULE_INIT(ProtoInspIRCd12)
|