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 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
|
/* Unreal IRCD 4 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/cs_mode.h"
#include "modules/sasl.h"
typedef Anope::map<Anope::string> ModData;
static Anope::string UplinkSID;
class UnrealIRCdProto : public IRCDProto
{
public:
PrimitiveExtensibleItem<ModData> ClientModData;
PrimitiveExtensibleItem<ModData> ChannelModData;
UnrealIRCdProto(Module *creator) : IRCDProto(creator, "UnrealIRCd 4+"), ClientModData(creator, "ClientModData"), ChannelModData(creator, "ChannelModData")
{
DefaultPseudoclientModes = "+BioqS";
CanSVSNick = true;
CanSVSJoin = true;
CanSetVHost = true;
CanSetVIdent = true;
CanSNLine = true;
CanSQLine = true;
CanSQLineChannel = true;
CanSZLine = true;
CanSVSHold = true;
CanCertFP = true;
RequiresID = true;
MaxModes = 12;
}
private:
/* SVSNOOP */
void SendSVSNOOP(const Server *server, bool set) anope_override
{
UplinkSocket::Message() << "SVSNOOP " << server->GetSID() << " " << (set ? "+" : "-");
}
void SendAkillDel(const XLine *x) anope_override
{
if (x->IsRegex() || x->HasNickOrReal())
return;
/* ZLine if we can instead */
if (x->GetUser() == "*")
{
cidr a(x->GetHost());
if (a.valid())
{
IRCD->SendSZLineDel(x);
return;
}
}
UplinkSocket::Message() << "TKL - G " << x->GetUser() << " " << x->GetHost() << " " << x->by;
}
void SendTopic(const MessageSource &source, Channel *c) anope_override
{
UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic;
}
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 SendVhostDel(User *u) anope_override
{
BotInfo *HostServ = Config->GetClient("HostServ");
u->RemoveMode(HostServ, "VHOST");
}
void SendAkill(User *u, XLine *x) anope_override
{
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 */
XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id);
old->manager->AddXLine(xline);
x = xline;
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 a(x->GetHost());
if (a.valid())
{
IRCD->SendSZLine(u, x);
return;
}
}
// 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;
UplinkSocket::Message() << "TKL + G " << x->GetUser() << " " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason();
}
void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override
{
UplinkSocket::Message(source) << "SVSKILL " << user->GetUID() << " :" << buf;
user->KillInternal(source, buf);
}
void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override
{
UplinkSocket::Message(source) << "SVS2MODE " << u->GetUID() <<" " << buf;
}
void SendClientIntroduction(User *u) anope_override
{
Anope::string modes = "+" + u->GetModes();
UplinkSocket::Message(u->server) << "UID " << u->nick << " 1 " << u->timestamp << " " << u->GetIdent() << " " << u->host << " "
<< u->GetUID() << " * " << modes << " " << (!u->vhost.empty() ? u->vhost : "*") << " "
<< (!u->chost.empty() ? u->chost : "*") << " " << "*" << " :" << u->realname;
}
void SendServer(const Server *server) anope_override
{
if (server == Me)
UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() + 1 << " :" << server->GetDescription();
else
UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() + 1 << " " << server->GetSID() << " :" << server->GetDescription();
}
/* JOIN */
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
{
UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name
<< " +" << c->GetModes(true, true) << " :" << user->GetUID();
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
{
UplinkSocket::Message() << "UNSQLINE " << x->mask;
}
/* SQLINE */
/*
** - Unreal will translate this to TKL for us
**
*/
void SendSQLine(User *, const XLine *x) anope_override
{
UplinkSocket::Message() << "TKL + Q * " << x->mask << " " << x->by << " " << x->expires << " " << x->created << " :" << x->GetReason();
}
/* Functions that use serval cmd functions */
void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override
{
if (!vIdent.empty())
UplinkSocket::Message(Me) << "CHGIDENT " << u->GetUID() << " " << vIdent;
if (!vhost.empty())
UplinkSocket::Message(Me) << "CHGHOST " << u->GetUID() << " " << vhost;
// Internally unreal sets +xt on chghost
BotInfo *bi = Config->GetClient("HostServ");
u->SetMode(bi, "CLOAK");
u->SetMode(bi, "VHOST");
}
void SendConnect() anope_override
{
/*
NICKv2 = Nick Version 2
VHP = Sends hidden host
UMODE2 = sends UMODE2 on user modes
NICKIP = Sends IP on NICK
SJ3 = Supports SJOIN
NOQUIT = No Quit
TKLEXT = Extended TKL we don't use it but best to have it
MLOCK = Supports the MLOCK server command
VL = Version Info
SID = SID/UID mode
*/
UplinkSocket::Message() << "PASS :" << Config->Uplinks[Anope::CurrentUplink].password;
UplinkSocket::Message() << "PROTOCTL " << "NICKv2 VHP UMODE2 NICKIP SJOIN SJOIN2 SJ3 NOQUIT TKLEXT MLOCK SID MTAGS";
UplinkSocket::Message() << "PROTOCTL " << "EAUTH=" << Me->GetName() << ",,,Anope-" << Anope::VersionShort();
UplinkSocket::Message() << "PROTOCTL " << "SID=" << Me->GetSID();
SendServer(Me);
}
void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override
{
Anope::string mechlist;
for (unsigned i = 0; i < mechanisms.size(); ++i)
mechlist += "," + mechanisms[i];
UplinkSocket::Message() << "MD client " << Me->GetName() << " saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1));
}
/* SVSHOLD - set */
void SendSVSHold(const Anope::string &nick, time_t t) anope_override
{
UplinkSocket::Message() << "TKL + Q H " << nick << " " << Me->GetName() << " " << Anope::CurTime + t << " " << Anope::CurTime << " :Being held for registered user";
}
/* SVSHOLD - release */
void SendSVSHoldDel(const Anope::string &nick) anope_override
{
UplinkSocket::Message() << "TKL - Q * " << nick << " " << Me->GetName();
}
/* UNSGLINE */
/*
* SVSNLINE - :realname mask
*/
void SendSGLineDel(const XLine *x) anope_override
{
UplinkSocket::Message() << "SVSNLINE - :" << x->mask;
}
/* UNSZLINE */
void SendSZLineDel(const XLine *x) anope_override
{
UplinkSocket::Message() << "TKL - Z * " << x->GetHost() << " " << x->by;
}
/* 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;
UplinkSocket::Message() << "TKL + Z * " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason();
}
/* SGLINE */
/*
* SVSNLINE + reason_where_is_space :realname mask with spaces
*/
void SendSGLine(User *, const XLine *x) anope_override
{
Anope::string edited_reason = x->GetReason();
edited_reason = edited_reason.replace_all_cs(" ", "_");
UplinkSocket::Message() << "SVSNLINE + " << edited_reason << " :" << x->mask;
}
/* svsjoin
parv[0] - sender
parv[1] - nick to make join
parv[2] - channel to join
parv[3] - (optional) channel key(s)
*/
/* In older Unreal SVSJOIN and SVSNLINE tokens were mixed so SVSJOIN and SVSNLINE are broken
when coming from a none TOKEN'd server
*/
void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override
{
if (!param.empty())
UplinkSocket::Message() << "SVSJOIN " << user->GetUID() << " " << chan << " :" << param;
else
UplinkSocket::Message() << "SVSJOIN " << user->GetUID() << " " << chan;
}
void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override
{
if (!param.empty())
UplinkSocket::Message() << "SVSPART " << user->GetUID() << " " << chan << " :" << param;
else
UplinkSocket::Message() << "SVSPART " << user->GetUID() << " " << chan;
}
void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
{
UplinkSocket::Message(Me) << "SENDUMODE o :from " << source.GetName() << ": " << buf;
}
void SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask) anope_override
{
UplinkSocket::Message() << "SWHOIS " << who << " :" << mask;
}
void SendEOB() anope_override
{
UplinkSocket::Message(Me) << "EOS";
}
bool IsNickValid(const Anope::string &nick) anope_override
{
if (nick.equals_ci("ircd") || nick.equals_ci("irc"))
return false;
return IRCDProto::IsNickValid(nick);
}
bool IsChannelValid(const Anope::string &chan) anope_override
{
if (chan.find(':') != Anope::string::npos)
return false;
return IRCDProto::IsChannelValid(chan);
}
bool IsExtbanValid(const Anope::string &mask) anope_override
{
return mask.length() >= 4 && mask[0] == '~' && mask[2] == ':';
}
void SendLogin(User *u, NickAlias *na) anope_override
{
/* 3.2.10.4+ treats users logged in with accounts as fully registered, even if -r, so we can not set this here. Just use the timestamp. */
if (Servers::Capab.count("ESVID") > 0 && !na->nc->HasExt("UNCONFIRMED"))
IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str());
else
IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon);
}
void SendLogout(User *u) anope_override
{
IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 0");
}
void SendChannel(Channel *c) anope_override
{
UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name
<< " +" << c->GetModes(true, true) << " :";
}
void SendSASLMessage(const SASL::Message &message) anope_override
{
size_t p = message.target.find('!');
Anope::string distmask;
if (p == Anope::string::npos)
{
Server *s = Server::Find(message.target.substr(0, 3));
if (!s)
return;
distmask = s->GetName();
}
else
{
distmask = message.target.substr(0, p);
}
UplinkSocket::Message(BotInfo::Find(message.source)) << "SASL " << distmask << " " << 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
{
size_t p = uid.find('!');
Anope::string distmask;
if (p == Anope::string::npos)
{
Server *s = Server::Find(uid.substr(0, 3));
if (!s)
return;
distmask = s->GetName();
}
else
{
distmask = uid.substr(0, p);
}
if (!vident.empty())
UplinkSocket::Message(Me) << "CHGIDENT " << uid << " " << vident;
if (!vhost.empty())
UplinkSocket::Message(Me) << "CHGHOST " << uid << " " << vhost;
UplinkSocket::Message(Me) << "SVSLOGIN " << distmask << " " << uid << " " << acc;
}
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 <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-')
continue;
if (c == '-' || c == '.' || c == '_')
continue;
return false;
}
return true;
}
};
class UnrealExtBan : public ChannelModeVirtual<ChannelModeList>
{
char ext;
public:
UnrealExtBan(const Anope::string &mname, const Anope::string &basename, char extban) : ChannelModeVirtual<ChannelModeList>(mname, basename)
, ext(extban)
{
}
ChannelMode *Wrap(Anope::string ¶m) anope_override
{
param = "~" + Anope::string(ext) + ":" + param;
return ChannelModeVirtual<ChannelModeList>::Wrap(param);
}
ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) anope_override
{
if (cm->type != MODE_LIST || param.length() < 4 || param[0] != '~' || param[1] != ext || param[2] != ':')
return cm;
param = param.substr(3);
return this;
}
};
namespace UnrealExtban
{
class ChannelMatcher : public UnrealExtBan
{
public:
ChannelMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
bool Matches(User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->GetMask();
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;
}
return false;
}
};
class EntryMatcher : public UnrealExtBan
{
public:
EntryMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
bool Matches(User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
return Entry(this->name, real_mask).Matches(u);
}
};
class RealnameMatcher : public UnrealExtBan
{
public:
RealnameMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
bool Matches(User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
return Anope::Match(u->realname, real_mask);
}
};
class RegisteredMatcher : public UnrealExtBan
{
public:
RegisteredMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
bool Matches(User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->GetMask();
return u->HasMode("REGISTERED") && mask.equals_ci(u->nick);
}
};
class AccountMatcher : public UnrealExtBan
{
public:
AccountMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
bool Matches(User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
if (real_mask == "0" && !u->IsIdentified()) /* ~a:0 is special and matches all unauthenticated users */
return true;
return u->IsIdentified() && Anope::Match(u->Account()->display, real_mask);
}
};
class FingerprintMatcher : public UnrealExtBan
{
public:
FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
bool Matches(User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
return !u->fingerprint.empty() && Anope::Match(u->fingerprint, real_mask);
}
};
class OperclassMatcher : public UnrealExtBan
{
public:
OperclassMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
bool Matches(User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
ModData *moddata = u->GetExt<ModData>("ClientModData");
return moddata != NULL && moddata->find("operclass") != moddata->end() && Anope::Match((*moddata)["operclass"], real_mask);
}
};
class TimedBanMatcher : public UnrealExtBan
{
public:
TimedBanMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
bool Matches(User *u, const Entry *e) anope_override
{
/* strip down the time (~t:1234:) and call other matchers */
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
real_mask = real_mask.substr(real_mask.find(":") + 1);
return Entry("BAN", real_mask).Matches(u);
}
};
class CountryMatcher : public UnrealExtBan
{
public:
CountryMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
bool Matches(User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
ModData *moddata = u->GetExt<ModData>("ClientModData");
if (moddata == NULL || moddata->find("geoip") == moddata->end())
return false;
sepstream sep((*moddata)["geoip"], '|');/* "cc=PL|cd=Poland" */
Anope::string tokenbuf;
while (sep.GetToken(tokenbuf))
{
if (tokenbuf.rfind("cc=", 0) == 0)
return (tokenbuf.substr(3, 2) == real_mask);
}
return false;
}
};
}
class ChannelModeFlood : public ChannelModeParam
{
public:
ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { }
/* Borrowed part of this check from UnrealIRCd */
bool IsValid(Anope::string &value) const anope_override
{
if (value.empty())
return false;
try
{
Anope::string rest;
if (value[0] != ':' && convertTo<unsigned>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<unsigned>(rest.substr(1), rest, false) > 0 && rest.empty())
return true;
}
catch (const ConvertException &) { }
/* '['<number><1 letter>[optional: '#'+1 letter],[next..]']'':'<number> */
size_t end_bracket = value.find(']', 1);
if (end_bracket == Anope::string::npos)
return false;
Anope::string xbuf = value.substr(0, end_bracket);
if (value[end_bracket + 1] != ':')
return false;
commasepstream args(xbuf.substr(1));
Anope::string arg;
while (args.GetToken(arg))
{
/* <number><1 letter>[optional: '#'+1 letter] */
size_t p = 0;
while (p < arg.length() && isdigit(arg[p]))
++p;
if (p == arg.length() || !(arg[p] == 'c' || arg[p] == 'j' || arg[p] == 'k' || arg[p] == 'm' || arg[p] == 'n' || arg[p] == 't'))
continue; /* continue instead of break for forward compatibility. */
try
{
int v = arg.substr(0, p).is_number_only() ? convertTo<int>(arg.substr(0, p)) : 0;
if (v < 1 || v > 999)
return false;
}
catch (const ConvertException &)
{
return false;
}
}
return true;
}
};
class ChannelModeHistory : public ChannelModeParam /* stolen from inspircd3's ColonDelimitedParamMode */
{
public:
ChannelModeHistory(char modeChar) : ChannelModeParam("HISTORY", modeChar, true) { }
bool IsValid(Anope::string &value) const anope_override
{
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;
// 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);
if (n <= 0)
return false;
}
catch (const ConvertException &e)
{
// conversion error, invalid
return false;
}
return true;
}
};
class ChannelModeUnrealSSL : public ChannelMode
{
public:
ChannelModeUnrealSSL(const Anope::string &n, char c) : ChannelMode(n, c)
{
}
bool CanSet(User *u) const anope_override
{
return false;
}
};
struct IRCDMessageCapab : Message::Capab
{
IRCDMessageCapab(Module *creator) : Message::Capab(creator, "PROTOCTL") { }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
for (unsigned i = 0; i < params.size(); ++i)
{
Anope::string capab = params[i];
if (capab.find("USERMODES=") != Anope::string::npos)
{
Anope::string modebuf(capab.begin() + 10, capab.end());
for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
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 UserModeOperOnly("HIDEIDLE", 'I'));
continue;
case 'R':
ModeManager::AddUserMode(new UserMode("REGPRIV", 'R'));
continue;
case 'S':
ModeManager::AddUserMode(new UserModeOperOnly("PROTECTED", 'S'));
continue;
case 'T':
ModeManager::AddUserMode(new UserMode("NOCTCP", 'T'));
continue;
case 'W':
ModeManager::AddUserMode(new UserModeOperOnly("WHOIS", 'W'));
continue;
case 'd':
ModeManager::AddUserMode(new UserMode("DEAF", 'd'));
continue;
case 'D':
ModeManager::AddUserMode(new UserMode("PRIVDEAF", 'D'));
continue;
case 'i':
ModeManager::AddUserMode(new UserMode("INVIS", 'i'));
continue;
case 'o':
ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o'));
continue;
case 'p':
ModeManager::AddUserMode(new UserMode("PRIV", 'p'));
continue;
case 'q':
ModeManager::AddUserMode(new UserModeOperOnly("GOD", 'q'));
continue;
case 'r':
ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r'));
continue;
case 's':
ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's'));
continue;
case 't':
ModeManager::AddUserMode(new UserModeNoone("VHOST", 't'));
continue;
case 'w':
ModeManager::AddUserMode(new UserMode("WALLOPS", 'w'));
continue;
case 'x':
ModeManager::AddUserMode(new UserMode("CLOAK", 'x'));
continue;
case 'z':
ModeManager::AddUserMode(new UserModeNoone("SSL", 'z'));
continue;
case 'Z':
ModeManager::AddUserMode(new UserMode("SSLPRIV", 'Z'));
continue;
default:
ModeManager::AddUserMode(new UserMode("", modebuf[t]));
}
}
}
else 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 ChannelModeList("BAN", 'b'));
ModeManager::AddChannelMode(new UnrealExtban::ChannelMatcher("CHANNELBAN", "BAN", 'c'));
ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("JOINBAN", "BAN", 'j'));
ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("NONICKBAN", "BAN", 'n'));
ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("QUIET", "BAN", 'q'));
ModeManager::AddChannelMode(new UnrealExtban::RealnameMatcher("REALNAMEBAN", "BAN", 'r'));
ModeManager::AddChannelMode(new UnrealExtban::RegisteredMatcher("REGISTEREDBAN", "BAN", 'R'));
ModeManager::AddChannelMode(new UnrealExtban::AccountMatcher("ACCOUNTBAN", "BAN", 'a'));
ModeManager::AddChannelMode(new UnrealExtban::FingerprintMatcher("SSLBAN", "BAN", 'S'));
ModeManager::AddChannelMode(new UnrealExtban::TimedBanMatcher("TIMEDBAN", "BAN", 't'));
ModeManager::AddChannelMode(new UnrealExtban::OperclassMatcher("OPERCLASSBAN", "BAN", 'O'));
ModeManager::AddChannelMode(new UnrealExtban::CountryMatcher("COUNTRYBAN", "BAN", 'C'));
continue;
case 'e':
ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e'));
continue;
case 'I':
ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I'));
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;
case 'f':
ModeManager::AddChannelMode(new ChannelModeFlood('f', false));
continue;
case 'L':
ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L'));
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 'l':
ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true));
continue;
case 'H':
ModeManager::AddChannelMode(new ChannelModeHistory('H'));
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 'p':
ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p'));
continue;
case 's':
ModeManager::AddChannelMode(new ChannelMode("SECRET", 's'));
continue;
case 'm':
ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm'));
continue;
case 'n':
ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n'));
continue;
case 't':
ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't'));
continue;
case 'i':
ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i'));
continue;
case 'r':
ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r'));
continue;
case 'R':
ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R'));
continue;
case 'c':
ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c'));
continue;
case 'O':
ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O'));
continue;
case 'Q':
ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q'));
continue;
case 'K':
ModeManager::AddChannelMode(new ChannelMode("NOKNOCK", 'K'));
continue;
case 'V':
ModeManager::AddChannelMode(new ChannelMode("NOINVITE", 'V'));
continue;
case 'C':
ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C'));
continue;
case 'z':
ModeManager::AddChannelMode(new ChannelMode("SSL", 'z'));
continue;
case 'N':
ModeManager::AddChannelMode(new ChannelMode("NONICK", 'N'));
continue;
case 'S':
ModeManager::AddChannelMode(new ChannelMode("STRIPCOLOR", 'S'));
continue;
case 'M':
ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M'));
continue;
case 'T':
ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'T'));
continue;
case 'G':
ModeManager::AddChannelMode(new ChannelMode("CENSOR", 'G'));
continue;
case 'Z':
ModeManager::AddChannelMode(new ChannelModeUnrealSSL("ALLSSL", 'Z'));
continue;
case 'd':
// post delayed. means that channel is -D but invisible users still exist.
continue;
case 'D':
ModeManager::AddChannelMode(new ChannelMode("DELAYEDJOIN", 'D'));
continue;
case 'P':
ModeManager::AddChannelMode(new ChannelModeOperOnly("PERM", 'P'));
continue;
default:
ModeManager::AddChannelMode(new ChannelMode("", modebuf[t]));
}
}
}
else if (!capab.find("SID="))
{
UplinkSID = capab.substr(4);
}
else if (!capab.find("PREFIX=")) /* PREFIX=(qaohv)~&@%+ */
{
Anope::string modes(capab.begin() + 7, capab.end());
reverse(modes.begin(), modes.end()); /* +%@&!)vhoaq( */
std::size_t mode_count = modes.find(')');
Anope::string mode_prefixes = modes.substr(0, mode_count);
Anope::string mode_chars = modes.substr(mode_count+1, mode_count);
for (size_t t = 0, end = mode_chars.length(); t < end; ++t)
{
Anope::string mode_name;
switch (mode_chars[t])
{
case 'v':
mode_name = "VOICE";
break;
case 'h':
mode_name = "HALFOP";
break;
case 'o':
mode_name = "OP";
break;
case 'a':
mode_name = "PROTECT";
break;
case 'q':
mode_name = "OWNER";
break;
default:
mode_name = "";
break;
}
ModeManager::AddChannelMode(new ChannelModeStatus(mode_name, mode_chars[t], mode_prefixes[t], t));
}
}
}
Message::Capab::Run(source, params);
}
};
struct IRCDMessageChgHost : IRCDMessage
{
IRCDMessageChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
User *u = User::Find(params[0]);
if (u)
u->SetDisplayedHost(params[1]);
}
};
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->SetVIdent(params[1]);
}
};
struct IRCDMessageChgName : IRCDMessage
{
IRCDMessageChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
User *u = User::Find(params[0]);
if (u)
u->SetRealname(params[1]);
}
};
struct IRCDMessageMD : IRCDMessage
{
PrimitiveExtensibleItem<ModData> &ClientModData;
PrimitiveExtensibleItem<ModData> &ChannelModData;
IRCDMessageMD(Module *creator, PrimitiveExtensibleItem<ModData> &clmoddata, PrimitiveExtensibleItem<ModData> &chmoddata) : IRCDMessage(creator, "MD", 3), ClientModData(clmoddata), ChannelModData(chmoddata)
{
SetFlag(IRCDMESSAGE_SOFT_LIMIT);
}
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
const Anope::string &mdtype = params[0],
&obj = params[1],
&var = params[2],
&value = params.size() > 3 ? params[3] : "";
if (mdtype == "client") /* can be a server too! */
{
User *u = User::Find(obj);
if (u == NULL)
return;
ModData &clientmd = *ClientModData.Require(u);
if (value.empty())
{
clientmd.erase(var);
Log(LOG_DEBUG) << "Erased client moddata " << var << " from " << u->nick;
}
else
{
clientmd[var] = value;
Log(LOG_DEBUG) << "Set client moddata " << var << "=\"" << value << "\" to " << u->nick;
}
if (var == "certfp" && !value.empty())
{
u->Extend<bool>("ssl");
u->fingerprint = value;
FOREACH_MOD(OnFingerprint, (u));
}
}
else if (mdtype == "channel")
{
Channel *c = Channel::Find(obj);
if (c == NULL)
return;
ModData &channelmd = *ChannelModData.Require(c);
if (value.empty())
{
channelmd.erase(var);
Log(LOG_DEBUG) << "Erased channel moddata " << var << " from " << c->name;
}
else
{
channelmd[var] = value;
Log(LOG_DEBUG) << "Set channel moddata " << var << "=\"" << value << "\" to " << c->name;
}
}
}
};
struct IRCDMessageMode : IRCDMessage
{
IRCDMessageMode(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
bool server_source = source.GetServer() != NULL;
Anope::string modes = params[1];
for (unsigned i = 2; i < params.size() - (server_source ? 1 : 0); ++i)
modes += " " + params[i];
if (IRCD->IsChannelValid(params[0]))
{
Channel *c = Channel::Find(params[0]);
time_t ts = 0;
try
{
if (server_source)
ts = convertTo<time_t>(params[params.size() - 1]);
}
catch (const ConvertException &) { }
if (c)
c->SetModesInternal(source, modes, ts);
}
else
{
User *u = User::Find(params[0]);
if (u)
u->SetModesInternal(source, "%s", params[1].c_str());
}
}
};
/* netinfo
* argv[0] = max global count
* argv[1] = time of end sync
* argv[2] = unreal protocol using (numeric)
* argv[3] = cloak-crc (> u2302)
* argv[4] = free(**)
* argv[5] = free(**)
* argv[6] = free(**)
* argv[7] = ircnet
*/
struct IRCDMessageNetInfo : IRCDMessage
{
IRCDMessageNetInfo(Module *creator) : IRCDMessage(creator, "NETINFO", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
UplinkSocket::Message() << "NETINFO " << MaxUserCount << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7];
}
};
struct IRCDMessageNick : IRCDMessage
{
IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
/*
** NICK - new
** source = NULL
** parv[0] = nickname
** parv[1] = hopcount
** parv[2] = timestamp
** parv[3] = username
** parv[4] = hostname
** parv[5] = servername
** parv[6] = servicestamp
** parv[7] = umodes
** parv[8] = virthost, * if none
** parv[9] = ip
** parv[10] = info
**
** NICK - change
** source = oldnick
** parv[0] = new nickname
** parv[1] = hopcount
*/
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
if (params.size() == 11)
{
Anope::string ip;
if (params[9] != "*")
{
Anope::string decoded_ip;
Anope::B64Decode(params[9], decoded_ip);
sockaddrs ip_addr;
ip_addr.ntop(params[9].length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str());
ip = ip_addr.addr();
}
Anope::string vhost = params[8];
if (vhost.equals_cs("*"))
vhost.clear();
time_t user_ts = params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime;
Server *s = Server::Find(params[5]);
if (s == NULL)
{
Log(LOG_DEBUG) << "User " << params[0] << " introduced from nonexistent server " << params[5] << "?";
return;
}
NickAlias *na = NULL;
if (params[6] == "0")
;
else if (params[6].is_pos_number_only())
{
if (convertTo<time_t>(params[6]) == user_ts)
na = NickAlias::Find(params[0]);
}
else
{
na = NickAlias::Find(params[6]);
}
User::OnIntroduce(params[0], params[3], params[4], vhost, ip, s, params[10], user_ts, params[7], "", na ? *na->nc : NULL);
}
else
{
User *u = source.GetUser();
if (u)
u->ChangeNick(params[0]);
}
}
};
/** This is here because:
*
* If we had three servers, A, B & C linked like so: A<->B<->C
* If Anope is linked to A and B splits from A and then reconnects
* B introduces itself, introduces C, sends EOS for C, introduces Bs clients
* introduces Cs clients, sends EOS for B. This causes all of Cs clients to be introduced
* with their server "not syncing". We now send a PING immediately when receiving a new server
* and then finish sync once we get a pong back from that server.
*/
struct IRCDMessagePong : IRCDMessage
{
IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
if (!source.GetServer()->IsSynced())
source.GetServer()->Sync(false);
}
};
struct IRCDMessageSASL : IRCDMessage
{
IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
if (!SASL::sasl)
return;
SASL::Message m;
m.source = params[1];
m.target = params[0];
m.type = params[2];
m.data = params[3];
m.ext = params.size() > 4 ? params[4] : "";
SASL::sasl->ProcessMessage(m);
}
};
struct IRCDMessageSDesc : IRCDMessage
{
IRCDMessageSDesc(Module *creator) : IRCDMessage(creator, "SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
source.GetServer()->SetDescription(params[0]);
}
};
struct IRCDMessageSetHost : IRCDMessage
{
IRCDMessageSetHost(Module *creator) : IRCDMessage(creator, "SETHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
User *u = source.GetUser();
/* When a user sets +x we receive the new host and then the mode change */
if (u->HasMode("CLOAK"))
u->SetDisplayedHost(params[0]);
else
u->SetCloakedHost(params[0]);
}
};
struct IRCDMessageSetIdent : IRCDMessage
{
IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
User *u = source.GetUser();
u->SetVIdent(params[0]);
}
};
struct IRCDMessageSetName : IRCDMessage
{
IRCDMessageSetName(Module *creator) : IRCDMessage(creator, "SETNAME", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
User *u = source.GetUser();
u->SetRealname(params[0]);
}
};
struct IRCDMessageServer : IRCDMessage
{
IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0;
if (params[1].equals_cs("1"))
{
Anope::string desc;
spacesepstream(params[2]).GetTokenRemainder(desc, 1);
new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, desc, UplinkSID);
}
else
new Server(source.GetServer(), params[0], hops, params[2]);
IRCD->SendPing(Me->GetName(), params[0]);
}
};
struct IRCDMessageSID : IRCDMessage
{
IRCDMessageSID(Module *creator) : IRCDMessage(creator, "SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0;
new Server(source.GetServer(), params[0], hops, params[3], params[2]);
IRCD->SendPing(Me->GetName(), params[0]);
}
};
static char UnrealSjoinPrefixToModeChar(char sjoin_prefix)
{
switch(sjoin_prefix)
{
case '*':
return ModeManager::GetStatusChar('~');
case '~':
return ModeManager::GetStatusChar('&');
default:
return ModeManager::GetStatusChar(sjoin_prefix); /* remaining are regular */
}
}
struct IRCDMessageSJoin : IRCDMessage
{
IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 3) { 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() >= 4)
for (unsigned i = 2; i < params.size() - 1; ++i)
modes += " " + params[i];
if (!modes.empty())
modes.erase(modes.begin());
std::list<Anope::string> bans, excepts, invites;
std::list<Message::Join::SJoinUser> users;
spacesepstream sep(params[params.size() - 1]);
Anope::string buf;
while (sep.GetToken(buf))
{
/* Ban */
if (buf[0] == '&')
{
buf.erase(buf.begin());
bans.push_back(buf);
}
/* Except */
else if (buf[0] == '"')
{
buf.erase(buf.begin());
excepts.push_back(buf);
}
/* Invex */
else if (buf[0] == '\'')
{
buf.erase(buf.begin());
invites.push_back(buf);
}
else
{
Message::Join::SJoinUser sju;
/* Get prefixes from the nick */
for (char ch; (ch = UnrealSjoinPrefixToModeChar(buf[0]));)
{
sju.first.AddMode(ch);
buf.erase(buf.begin());
}
sju.second = User::Find(buf);
if (!sju.second)
{
Log(LOG_DEBUG) << "SJOIN for nonexistent user " << buf << " on " << params[1];
continue;
}
users.push_back(sju);
}
}
time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime;
Message::Join::SJoin(source, params[1], ts, modes, users);
if (!bans.empty() || !excepts.empty() || !invites.empty())
{
Channel *c = Channel::Find(params[1]);
if (!c || c->creation_time != ts)
return;
ChannelMode *ban = ModeManager::FindChannelModeByName("BAN"),
*except = ModeManager::FindChannelModeByName("EXCEPT"),
*invex = ModeManager::FindChannelModeByName("INVITEOVERRIDE");
if (ban)
for (std::list<Anope::string>::iterator it = bans.begin(), it_end = bans.end(); it != it_end; ++it)
c->SetModeInternal(source, ban, *it);
if (except)
for (std::list<Anope::string>::iterator it = excepts.begin(), it_end = excepts.end(); it != it_end; ++it)
c->SetModeInternal(source, except, *it);
if (invex)
for (std::list<Anope::string>::iterator it = invites.begin(), it_end = invites.end(); it != it_end; ++it)
c->SetModeInternal(source, invex, *it);
}
}
};
struct IRCDMessageTopic : IRCDMessage
{
IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { }
/*
** source = sender prefix
** parv[0] = channel name
** parv[1] = topic nickname
** parv[2] = topic time
** parv[3] = topic text
*/
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
Channel *c = Channel::Find(params[0]);
if (c)
c->ChangeTopicInternal(source.GetUser(), params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime);
}
};
/*
* parv[0] = nickname
* parv[1] = hopcount
* parv[2] = timestamp
* parv[3] = username
* parv[4] = hostname
* parv[5] = UID
* parv[6] = servicestamp
* parv[7] = umodes
* parv[8] = virthost, * if none
* parv[9] = cloaked host, * if none
* parv[10] = ip
* parv[11] = info
*/
struct IRCDMessageUID : IRCDMessage
{
IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 12) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
Anope::string
nickname = params[0],
hopcount = params[1],
timestamp = params[2],
username = params[3],
hostname = params[4],
uid = params[5],
account = params[6],
umodes = params[7],
vhost = params[8],
chost = params[9],
ip = params[10],
info = params[11];
if (ip != "*")
{
Anope::string decoded_ip;
Anope::B64Decode(ip, decoded_ip);
sockaddrs ip_addr;
ip_addr.ntop(ip.length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str());
ip = ip_addr.addr();
}
if (vhost == "*")
vhost.clear();
if (chost == "*")
chost.clear();
time_t user_ts;
try
{
user_ts = convertTo<time_t>(timestamp);
}
catch (const ConvertException &)
{
user_ts = Anope::CurTime;
}
NickAlias *na = NULL;
if (account == "0")
{
;
}
else if (account.is_pos_number_only())
{
if (convertTo<time_t>(account) == user_ts)
na = NickAlias::Find(nickname);
}
else
{
na = NickAlias::Find(account);
}
User *u = User::OnIntroduce(nickname, username, hostname, vhost, ip, source.GetServer(), info, user_ts, umodes, uid, na ? *na->nc : NULL);
if (u && !chost.empty() && chost != u->GetCloakedHost())
u->SetCloakedHost(chost);
}
};
struct IRCDMessageUmode2 : IRCDMessage
{
IRCDMessageUmode2(Module *creator) : IRCDMessage(creator, "UMODE2", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
source.GetUser()->SetModesInternal(source, "%s", params[0].c_str());
}
};
class ProtoUnreal : public Module
{
UnrealIRCdProto 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_svskill;
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::SQuit message_squit;
Message::Stats message_stats;
Message::Time message_time;
Message::Version message_version;
Message::Whois message_whois;
/* Our message handlers */
IRCDMessageCapab message_capab;
IRCDMessageChgHost message_chghost;
IRCDMessageChgIdent message_chgident;
IRCDMessageChgName message_chgname;
IRCDMessageMD message_md;
IRCDMessageMode message_mode, message_svsmode, message_svs2mode;
IRCDMessageNetInfo message_netinfo;
IRCDMessageNick message_nick;
IRCDMessagePong message_pong;
IRCDMessageSASL message_sasl;
IRCDMessageSDesc message_sdesc;
IRCDMessageSetHost message_sethost;
IRCDMessageSetIdent message_setident;
IRCDMessageSetName message_setname;
IRCDMessageServer message_server;
IRCDMessageSID message_sid;
IRCDMessageSJoin message_sjoin;
IRCDMessageTopic message_topic;
IRCDMessageUID message_uid;
IRCDMessageUmode2 message_umode2;
bool use_server_side_mlock;
public:
ProtoUnreal(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_svskill(this, "SVSKILL"), message_motd(this), message_notice(this), message_part(this), message_ping(this),
message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), message_time(this),
message_version(this), message_whois(this),
message_capab(this), message_chghost(this), message_chgident(this), message_chgname(this),
message_md(this, ircd_proto.ClientModData, ircd_proto.ChannelModData),message_mode(this, "MODE"),
message_svsmode(this, "SVSMODE"), message_svs2mode(this, "SVS2MODE"), message_netinfo(this), message_nick(this), message_pong(this),
message_sasl(this), message_sdesc(this), message_sethost(this), message_setident(this), message_setname(this), message_server(this),
message_sid(this), message_sjoin(this), message_topic(this), message_uid(this), message_umode2(this)
{
}
void Prioritize() anope_override
{
ModuleManager::SetPriority(this, PRIORITY_FIRST);
}
void OnReload(Configuration::Conf *conf) anope_override
{
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"));
if (Servers::Capab.count("ESVID") == 0)
IRCD->SendLogout(u);
}
void OnChannelSync(Channel *c) anope_override
{
if (!c->ci)
return;
ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks");
if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && modelocks)
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->name << " " << modes;
}
}
void OnChanRegistered(ChannelInfo *ci) anope_override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
if (!ci->c || !use_server_side_mlock || !modelocks || !Servers::Capab.count("MLOCK"))
return;
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
}
void OnDelChan(ChannelInfo *ci) anope_override
{
if (!ci->c || !use_server_side_mlock || !Servers::Capab.count("MLOCK"))
return;
UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " :";
}
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 && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0)
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar;
UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << 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 && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0)
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, "");
UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
}
return EVENT_CONTINUE;
}
void OnChannelUnban(User *u, ChannelInfo *ci) anope_override
{
UplinkSocket::Message(ci->WhoSends()) << "SVS2MODE " << ci->c->name << " -b " << u->GetUID();
/* Unreal will remove all matching bans for us regardless of our internal matching.
Don't use Message(Me) here as certain Unreal versions will always respond with TS-less MODE message. */
}
};
MODULE_INIT(ProtoUnreal)
|