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 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637
|
/*
* HybServ TS Services, Copyright (C) 1998-1999 Patrick Alken
* This program comes with absolutely NO WARRANTY
*
* Should you choose to use and/or modify this source code, please
* do so under the terms of the GNU General Public License under which
* this program is distributed.
*
* $Id: server.c,v 1.3 2001/11/12 09:50:55 asuffield Exp $
*/
#include "defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#endif
#include <assert.h>
#include "alloc.h"
#include "channel.h"
#include "chanserv.h"
#include "client.h"
#include "conf.h"
#include "config.h"
#include "dcc.h"
#include "flood.h"
#include "global.h"
#include "hash.h"
#include "helpserv.h"
#include "hybdefs.h"
#include "init.h"
#include "jupe.h"
#include "log.h"
#include "match.h"
#include "memoserv.h"
#include "misc.h"
#include "mystring.h"
#include "nickserv.h"
#include "operserv.h"
#include "seenserv.h"
#include "server.h"
#include "settings.h"
#include "sock.h"
#include "statserv.h"
#include "timestr.h"
#include "sprintf_irc.h"
#ifdef HAVE_PTHREADS
#include <pthread.h>
#endif
#ifdef STATSERVICES
extern aHashEntry hostTable[HASHCLIENTS];
#endif /* STATSERVICES */
int burst_complete = 0;
/*
* Global - list of network servers
*/
struct Server *ServerList = NULL;
static int ServerCollides = 0;
static time_t ServerCollidesTS = 0;
static void s_pass(int ac, char **av);
static void s_ping(int ac, char **av);
static void s_server(int ac, char **av);
static void s_nick(int ac, char **av);
static void s_squit(int ac, char **av);
static void s_privmsg(int ac, char **av);
static void s_quit(int ac, char **av);
static void s_kill(int ac, char **av);
static void s_kick(int ac, char **av);
static void s_mode(int ac, char **av);
static void s_part(int ac, char **av);
static void s_error(int ac, char **av);
static void s_whois(int ac, char **av);
static void s_trace(int ac, char **av);
static void s_version(int ac, char **av);
static void s_motd(int ac, char **av);
static void s_sethost( int ac, char **av );
static void s_setident( int ac, char **av );
static void s_setname( int ac, char **av );
static void CheckServCollide(struct Server *bad_server);
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
static void s_topic(int ac, char **av);
static void s_stopic(int ac, char **av);
#endif
#ifdef STATSERVICES
static void s_pong(int ac, char **av);
#endif
/*
* Table of commands the hub will send us
*/
static struct ServCommand servtab[] = {
{ "PASS", s_pass },
{ "PING", s_ping },
{ "SERVER", s_server },
{ "NICK", s_nick },
{ "SQUIT", s_squit },
{ "PRIVMSG", s_privmsg },
/* { "NOTICE", s_privmsg }, */
{ "QUIT", s_quit },
{ "KILL", s_kill },
{ "KICK", s_kick },
{ "REMOVE", s_kick },
{ "MODE", s_mode },
{ "SJOIN", s_sjoin },
{ "JOIN", s_sjoin },
{ "PART", s_part },
{ "ERROR", s_error },
{ "WHOIS", s_whois },
{ "TRACE", s_trace },
{ "VERSION", s_version },
{ "MOTD", s_motd },
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
{ "TOPIC", s_topic },
{ "STOPIC", s_stopic },
#endif
#ifdef STATSERVICES
{ "PONG", s_pong },
#endif
{ "SETHOST", s_sethost },
{ "SETIDENT", s_setident },
{ "SETNAME", s_setname },
{ 0, 0 }
};
/*
ProcessInfo()
args: int arc, char **arv
purpose: process string sent by hub server (stored in 'arv')
return: none
*/
void
ProcessInfo(int arc, char **arv)
{
struct ServCommand *stptr;
int index;
if ((arc >= 2) && (*arv[0] == ':'))
index = 1;
else
index = 0;
for (stptr = servtab; stptr->cmd; stptr++)
{
if (!irccmp(arv[index], stptr->cmd))
{
(*stptr->func)(arc, arv);
break;
}
}
} /* ProcessInfo() */
/*
AddServer()
args: int argcnt, char **line
purpose: add server info contained in 'line'
return: pointer to newly created server structure
*/
struct Server *
AddServer(int argcnt, char **line)
{
struct Server *tempserv;
#ifdef BLOCK_ALLOCATION
tempserv = (struct Server *) BlockSubAllocate(ServerHeap);
#else
tempserv = (struct Server *) MyMalloc(sizeof(struct Server));
#endif
memset(tempserv, 0, sizeof(struct Server));
/*
* check if the server is the hub - if so, the format will
* be SERVER server.com .., not :hub SERVER server.com ..
*/
if (argcnt == 4)
{
#ifdef BLOCK_ALLOCATION
strncpy(tempserv->name, line[1], SERVERLEN);
#else
tempserv->name = MyStrdup(line[1]);
#endif
tempserv->flags |= SERV_MYHUB;
if (!Me.hub)
Me.hub = tempserv;
/*
* services won't be in the server list yet, so don't
* increment our hub's server count - it will be set
* to 1 anyway below
*/
}
else
{
if (argcnt < 5)
return (NULL);
#ifdef BLOCK_ALLOCATION
strncpy(tempserv->name, line[2], SERVERLEN);
#else
tempserv->name = MyStrdup(line[2]);
#endif
/*
* If the server we're adding is services itself,
* have "Me.sptr" point to it
*/
if (!Me.sptr)
if (!irccmp(tempserv->name, Me.name))
Me.sptr = tempserv;
/*
* A new server is being added, increment the server count
* of it's hub; if the new server is services itself, don't
* increment our hub's server count because it will already
* be 1 from when it was added
*/
if ((tempserv->uplink = FindServer((line[0][0] == ':') ? line[0] + 1 : line[0])))
{
/*
* Make sure this server doesn't match services
*/
if (tempserv != Me.sptr)
{
tempserv->uplink->numservs++;
#ifdef STATSERVICES
if (tempserv->uplink->numservs > tempserv->uplink->maxservs)
{
tempserv->uplink->maxservs = tempserv->uplink->numservs;
tempserv->uplink->maxservs_ts = current_ts;
}
#endif
}
}
if (SafeConnect)
SendUmode(OPERUMODE_L,
"*** New Server: %s (hub: %s)",
tempserv->name,
tempserv->uplink ? tempserv->uplink->name : "*unknown*");
}
tempserv->connect_ts = current_ts;
tempserv->numservs = 1;
#ifdef STATSERVICES
tempserv->maxservs = 1;
tempserv->maxservs_ts = tempserv->connect_ts;
#endif /* STATSERVICES */
#ifdef SPLIT_INFO
tempserv->split_ts=0;
#endif
tempserv->next = ServerList;
tempserv->prev = NULL;
if (tempserv->next)
tempserv->next->prev = tempserv;
ServerList = tempserv;
(void) HashAddServer(tempserv);
Network->TotalServers++;
#ifdef STATSERVICES
if (Network->TotalServers > Network->MaxServers)
{
Network->MaxServers = Network->TotalServers;
Network->MaxServers_ts = current_ts;
if ((Network->MaxServers % 5) == 0)
{
/* notify of new max server count */
SendUmode(OPERUMODE_Y,
"*** New Max Server Count: %ld",
Network->MaxServers);
}
}
if (Network->TotalServers > Network->MaxServersT)
{
Network->MaxServersT = Network->TotalServers;
Network->MaxServersT_ts = current_ts;
}
#endif
return (tempserv);
} /* AddServer() */
/*
DeleteServer()
args: struct Server *sptr
purpose: delete 'sptr' from server list
return: none
*/
void
DeleteServer(struct Server *sptr)
{
struct Server *tmpserv;
if (!sptr)
return;
#ifdef EXTRA_SPLIT_INFO
/* This could spawn too much messages, even flood on connects/reconnects
* because of severe DoS -kre */
SendUmode(OPERUMODE_L,
"*** Netsplit: %s (hub: %s)",
sptr->name,
sptr->uplink ? sptr->uplink->name : "*unknown*");
#endif
/*
* Delete server from hash table
*/
(void) HashDelServer(sptr);
if (sptr->uplink)
sptr->uplink->numservs--;
/*
* go through server list, and check if any leafs had sptr
* as their hub, if so, nullify uplink
*/
for (tmpserv = ServerList; tmpserv; tmpserv = tmpserv->next)
{
if (tmpserv->uplink == sptr)
tmpserv->uplink = NULL;
}
#ifndef BLOCK_ALLOCATION
MyFree(sptr->name);
#endif
if (sptr->prev)
sptr->prev->next = sptr->next;
else
ServerList = sptr->next;
if (sptr->next)
sptr->next->prev = sptr->prev;
#ifdef BLOCK_ALLOCATION
BlockSubFree(ServerHeap, sptr);
#else
MyFree(sptr);
#endif /* BLOCK_ALLOCATION */
Network->TotalServers--;
} /* DeleteServer() */
/*
do_squit()
SQUIT all servers matching serv
*/
void
do_squit(char *serv, char *reason)
{
struct Server *tempserv, *prev;
for (tempserv = ServerList; tempserv; )
{
/* squit the server */
if (match(serv, tempserv->name))
{
toserv("SQUIT %s :%s\n",
tempserv->name,
reason);
prev = tempserv->next;
DeleteServer(tempserv); /* remove server from list */
tempserv = prev;
}
else
tempserv = tempserv->next;
}
} /* do_squit() */
/*
ClearUsers()
args: none
purpose: clear all users in linked list
return: none
*/
void
ClearUsers()
{
struct Luser *next;
while (ClientList)
{
next = ClientList->next;
DeleteClient(ClientList);
ClientList = next;
}
} /* ClearUsers() */
/*
ClearServs()
args: none
purpose: delete all servers in list
return: none
*/
void
ClearServs()
{
struct Server *next;
while (ServerList)
{
next = ServerList->next;
DeleteServer(ServerList);
ServerList = next;
}
} /* ClearServs() */
/*
ClearChans()
args: none
purpose: delete all channels in list
return: none
*/
void
ClearChans()
{
struct Channel *next;
while (ChannelList)
{
next = ChannelList->next;
DeleteChannel(ChannelList);
ChannelList = next;
}
} /* ClearChans() */
/*
s_pass()
*/
static void
s_pass(int ac, char **av)
{
/* do nothing */
return;
} /* s_pass() */
/*
s_ping()
Respond to a ping request
If a server is requesting a PING
av[0] = "PING"
av[1] = :servername
If a client is requesting a PING
av[0] = :nickname
av[1] = "PING"
av[2] = nickname
av[3] = Me.name
*/
static void
s_ping(int ac, char **av)
{
char *who;
if (ac < 2)
return;
if (!irccmp(av[0], "PING"))
who = av[1];
else
who = av[0];
if (*who == ':')
who++;
toserv(":%s PONG %s :%s\n",
Me.name,
Me.name,
who);
burst_complete = 1;
} /* s_ping() */
/*
s_server()
Process a SERVER statement from hub
If hub is identifying itself:
av[0] = "SERVER"
av[1] = server name
av[2] = hop count
av[3] = description
If its another server:
av[0] = hub name
av[1] = "SERVER"
av[2] = server name
av[3] = hop count
av[4] = description
*/
static void
s_server(int ac, char **av)
{
char sendstr[MAXLINE];
char **line;
struct Server *tempserv;
if (ac < 4)
return;
/*
* make sure av[2] isn't in the server list - one reason it might
* be is if services squit'd it and created a fake server
* in the connect burst, but the hub would send the server line
* to us anyway, before processing our SQUIT
*/
if ((tempserv=FindServer(av[2])))
#ifndef SPLIT_INFO
return;
#else
/* Yeah, this is server that has already been in server list. Now, we
* have 2 cases - either this is juped server or is not. If it is,
* ignore whole split stuff -kre */
{
if ((ac == 5) && !IsJupe(tempserv->name))
{
tempserv->uplink = FindServer(av[0] + 1);
SendUmode(OPERUMODE_Y, "Server %s has connected to %s "
"after %s split time",
av[2], av[0] + 1, timeago(tempserv->split_ts, 0));
tempserv->split_ts = 0;
tempserv->connect_ts = current_ts;
}
return;
}
#endif /* SPLIT_INFO */
tempserv = AddServer(ac, av);
if (tempserv == Me.hub)
{
/*
* it's the SERVER line from the hub in the initial burst
*/
/*
* get the network server name of hub in case it
* doesn't match it's hostname
*/
currenthub->realname = MyStrdup(av[1]);
/*
* add the services (our) server as well
*/
ircsprintf(sendstr, ":%s SERVER %s 1 :%s",
av[1], Me.name, Me.info);
SplitBuf(sendstr, &line);
AddServer(5, line);
MyFree(line);
/*
* Set our hub's uplink as services (we are the hub of our
* uplink)
*/
tempserv->uplink = Me.sptr;
/* initialize service nicks */
InitServs(NULL);
#ifdef ALLOW_JUPES
/* Introduce juped nicks/servers to the network */
InitJupes();
#endif /* ALLOW_JUPES */
}
else
{
#ifdef ALLOW_JUPES
/* a new server connected to network, check if its juped */
CheckJuped(av[2]);
#endif /* ALLOW_JUPES */
#ifdef DEBUGMODE
fprintf(stderr, "Introducing new server %s\n",
av[2]);
#endif /* DEBUGMODE */
}
} /* s_server() */
/*
s_nick()
Process a NICK statement
if new user:
av[1] = nick name
av[2] = hop count
av[3] = TimeStamp
av[4] = usermodes
av[5] = username
av[6] = hostname
av[7] = server
av[8] = real name
if nick change:
av[0] = who
av[1] = "NICK"
av[2] = new nick
av[3] = TS
*/
static void
s_nick(int ac, char **av)
{
struct Luser *lptr,
*serviceptr;
#ifdef NICKSERVICES
struct NickInfo *nptr, *newptr;
#endif
#ifdef RECORD_SPLIT_TS
struct Userlist *uptr;
#endif
#ifdef SEENSERVICES
char oldnick[NICKLEN + 1];
#endif
if (ac == 4)
{
char *who;
#if defined(BLOCK_ALLOCATION) || defined(NICKSERVICES)
char newnick[NICKLEN + 1];
#endif
/* nick change, not new user */
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
lptr = FindClient(who);
if (!lptr)
return;
#if defined(BLOCK_ALLOCATION) || defined(NICKSERVICES)
/*memset(&newnick, 0, NICKLEN + 1);*/
strncpy(newnick, av[2], NICKLEN);
newnick[NICKLEN] = '\0';
#endif
SendUmode(OPERUMODE_N,
"*** Nick Change: %s -> %s",
lptr->nick,
av[2]);
#ifdef NICKSERVICES
nptr = FindNick(lptr->nick);
/* Update lastseen info for old nickname */
if (nptr && (nptr->flags & NS_IDENTIFIED))
nptr->lastseen = current_ts;
newptr = FindNick(newnick);
if (newptr)
{
/*
* Un-Identify the new nickname in case it is registered - it could
* possibly be identified from the flags read from the userfile, if
* no-one has used this nickname yet.
*/
newptr->flags &= ~NS_IDENTIFIED;
}
if (nptr)
{
#ifdef LINKED_NICKNAMES
/*
* One of the features of linked nicknames is if you identify for
* one nick in the link, you are identified for every nick. If
* lptr->nick is changing his/her nick to another nickname in the
* link (and is currently identified), make sure they get correctly
* identified for the new nickname.
*/
if (nptr->flags & NS_IDENTIFIED)
{
if (newptr && IsLinked(nptr, newptr))
{
newptr->flags |= NS_IDENTIFIED;
toserv(":%s MODE %s +e\n", Me.name, newptr->nick);
}
}
#endif /* LINKED_NICKNAMES */
/*
* Un-Identify the old nickname if it is registered
*/
nptr->flags &= ~NS_IDENTIFIED;
} /* if (nptr) */
#endif /* NICKSERVICES */
/*
* If the user is a generic operator who registered themselves
* by sending OperServ a message, remove that flag now -
* This code is here for a very special case scenario: If a
* malicious operator registers him/herself with OperServ,
* by sending a generic operator command, and then changes
* their nickname to one which has administrator privileges
* in hybserv.conf, they will be registered without having
* to give the correct password, or even without having
* to match the correct hostmask. This code removes
* their registration flag to ensure that doesn't happen.
* Execute this code even if OpersHaveAccess is turned
* off, because an operator could have registered with
* OperServ, while it was turned on (before a rehash
* etc) and the operator could get administrator access
* that way.
*/
if (GetUser(1, lptr->nick, lptr->username, lptr->hostname) == GenericOper)
lptr->flags &= ~L_OSREGISTERED;
#ifdef ALLOW_FUCKOVER
/* check if old nick was being flooded */
CheckFuckoverTarget(lptr, av[2]);
#endif
HashDelClient(lptr, 1);
/* Erase old nick, and store new nick in it's position */
#ifdef SEENSERVICES
strncpy(oldnick, lptr->nick, NICKLEN);
#endif /* SEENSERVICES */
#ifdef BLOCK_ALLOCATION
strcpy(lptr->nick, newnick);
#else
MyFree(lptr->nick);
lptr->nick = MyStrdup(av[2]);
#endif /* BLOCK_ALLOCATION */
HashAddClient(lptr, 1);
#ifdef STATSERVICES
lptr->numnicks++;
#endif
#ifdef NICKSERVICES
/*
* Update nick_ts, so if the new nick is registered, we know
* when to do the KILL if they haven't registered within
* 1 minute
*/
lptr->nick_ts = atoi(av[3] + 1);
/*
* check if new nick is stealing someone's nick - but only
* if who != av[2], because the user "aba" might change
* their nick to "aBa", in which case we don't need to
* check
*/
if (irccmp(who, av[2]) != 0)
CheckNick(av[2]);
#endif /* NICKSERVICES */
#ifdef ALLOW_JUPES
CheckJuped(av[2]); /* check if new nick is juped */
#endif
#ifdef SEENSERVICES
es_add(oldnick, lptr->username, lptr->hostname, NULL, current_ts, 2);
#endif /* SEENSERVICES */
#ifdef ADVFLOOD
updateConnectTable(lptr->username, lptr->hostname);
#endif /* ADVFLOOD */
return;
} /* if (ac == 4) */
/* It is a new user */
if (ac < 9)
return;
/*
* Check if someone is nick colliding a service nick
*/
if ((serviceptr = GetService(av[1])))
{
/*
* Make sure it is a valid nick collide before we send a kill. If this
* is the initial hub burst, the hub would not have processed our NICK
* statement yet, so let TS clean everything up
*/
if (IsNickCollide(serviceptr, av))
{
struct Luser *bad_lptr;
toserv(":%s KILL %s :%s\n", Me.name, av[1],
"Attempt to Nick Collide Services");
bad_lptr = FindClient(av[1]);
if (!bad_lptr)
return;
#ifdef SERVICES_FIGHT_FIX
/* Check if services are fighting -kre */
CheckServCollide(bad_lptr->server);
#endif /* SERVICES_FIGHT_FIX */
DeleteClient(bad_lptr);
InitServs(serviceptr);
if (Me.sptr)
Me.sptr->numservkills++;
Network->TotalServKills++;
#ifdef STATSERVICES
if (Network->TotalServKills > Network->ServKillsT)
Network->ServKillsT = Network->TotalServKills;
#endif
}
/*
* Even if it is not a valid nick collide, do not
* add the user to our user list, since TS will
* have the user killed
*/
return;
}
/*
* Send new client connections to opers with a +C usermode
* in the format:
* nick!user@host (server)
*/
if (SafeConnect)
SendUmode(OPERUMODE_CAPC,
"*** Client connection: %s!%s@%s [%s]",
av[1],
av[5],
av[6],
av[7]);
/* Add user to list */
lptr = AddClient(av);
if (!lptr)
{
/*
* Normally lptr will point to the newly created structure
* for av[1]. If it is NULL, one possibility is that
* HashAddClient() killed av[1] due to AutoKillClones, so
* go no furthur.
*/
return;
}
#ifdef GLOBALSERVICES
if (ircncmp(Me.name, lptr->server->name, strlen(lptr->server->name))) {
/*
* Send the motd to the new user
*/
if (Network->LogonNewsFile.Contents)
SendMessageFile(lptr, &Network->LogonNewsFile);
}
#endif /* GLOBALSERVICES */
#ifdef ALLOW_JUPES
CheckJuped(av[1]);
#endif
#ifdef NICKSERVICES
/*
* If the nick is registered, and was IDENTIFY'd at the time
* the userfile was written, the flags will still show they
* were identified, even if hybserv crashed etc, so when a
* new nick is introduced, make sure their flags don't contain
* NS_IDENTIFIED since theres no way they could have identify'd
* yet
*/
if ((nptr = FindNick(av[1])))
{
nptr->flags &= ~(NS_IDENTIFIED | NS_RELEASE);
/* If the user has +e set, mark them as identified */
if (lptr->umodes & UMODE_E)
nptr->flags |= NS_IDENTIFIED;
#ifdef RECORD_SPLIT_TS
/*
* If nptr->split_ts is not 0, then the user QUIT while
* being identified, so if their current TS matches their
* split_ts, then they must have been on a valid netsplit,
* and we can allow them to continue being identified
*/
if (nptr->split_ts)
if (nptr->split_ts == atoi(av[3]))
{
nptr->flags |= NS_IDENTIFIED;
/*
* Only reset nptr->split_ts if a match was made, because
* if services sees someone QUIT during a split, and another
* client comes on services' side with the same nick, when
* the nick collide occurs, the old nick should still be
* able to be recognized with the same TS
*/
nptr->split_ts = nptr->whensplit = 0;
}
#endif /* RECORD_SPLIT_TS */
}
CheckNick(av[1]);
#endif /* NICKSERVICES */
#ifdef RECORD_SPLIT_TS
/*
* Check if they were registered with OperServ during a split,
* if so, re-register them
*/
if ((uptr = GetUser(0, av[1], av[5], av[6])))
{
if (uptr->split_ts && (uptr->split_ts == atoi(av[3])))
{
lptr->flags |= L_OSREGISTERED;
uptr->split_ts = uptr->whensplit = 0;
}
}
#endif /* RECORD_SPLIT_TS */
} /* s_nick() */
/*
s_privmsg()
Process a PRIVMSG statement
av[0] = who
av[1] = "PRIVMSG"
av[2] = destination
av[3] = actual message
*/
static void
s_privmsg(int ac, char **av)
{
char *who, /* nick who gave privmsg */
*command, /* contains the /msg that 'who' gave */
*tmp;
struct Luser *lptr,
/*
* if it was sent to a service nick as opposed to a
* juped nick etc
*/
*serviceptr;
if (ac < 4)
return;
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
if (!(lptr = FindClient(who)))
return;
/* remove the leading ":" from the command string
I moved this code from below for smoother source tweak -kre */
command = av[3] + 1;
/* Obviously, this code down strips '%'. But what if some valid string
contains regular '%' and it should _not_ be stripped, ie. passwd
string? So, I'll add search for IDENTIFY string. -kre */
if (ircncmp(command, "IDENTIFY", 8))
stripformatsymbols(av[3]);
if (RestrictedAccess)
{
/*
* Check if the user has an "o" flag - if not, don't allow
* the command
*/
if (!IsOper(GetUser(0, lptr->nick, lptr->username, lptr->hostname)))
return;
}
#ifndef EXTREMEDEBUG
if (IgnoreList)
{
char chkstr[MAXLINE];
if (lptr)
{
ircsprintf(chkstr, "*!%s@%s", lptr->username, lptr->hostname);
if (OnIgnoreList(chkstr))
return;
}
}
#endif /* !EXTREMEDEBUG */
if ((tmp = strchr(av[2], '@')))
{
if (!irccmp(tmp + 1, Me.name))
*tmp = '\0';
}
serviceptr = GetService(av[2]);
if (FloodProtection && serviceptr)
{
if (!IsValidAdmin(lptr))
{
lptr->messages++;
if (!lptr->msgs_ts[0])
lptr->msgs_ts[0] = current_ts;
else
{
lptr->msgs_ts[1] = current_ts;
if (lptr->messages == FloodCount)
{
lptr->messages = 0;
if ((lptr->msgs_ts[1] - lptr->msgs_ts[0]) <= FloodTime)
{
char *mask = HostToMask(lptr->username, lptr->hostname);
/*
* they sent too many messages in too little time
*/
lptr->flood_trigger++;
if (lptr->flood_trigger >= IgnoreOffenses)
{
AddIgnore(mask, 0);
notice(n_OperServ, lptr->nick,
"Maximum flood offenses reached, you are on permanent ignore");
putlog(LOG2,
"PRIVMSG flood from %s!%s@%s (permanent ignore)",
lptr->nick,
lptr->username,
lptr->hostname);
SendUmode(OPERUMODE_Y,
"*** Detected flood from %s!%s@%s (permanent ignore)",
lptr->nick,
lptr->username,
lptr->hostname);
}
else
{
AddIgnore(mask, IgnoreTime);
notice(n_OperServ, lptr->nick,
"Received %d+ messages in <= %d seconds, you are being ignored for %s",
FloodCount,
FloodTime,
timeago(IgnoreTime, 3));
putlog(LOG2,
"PRIVMSG flood from %s!%s@%s (%s ignore)",
lptr->nick,
lptr->username,
lptr->hostname,
timeago(IgnoreTime, 2));
SendUmode(OPERUMODE_Y,
"*** Detected flood from %s!%s@%s (%s ignore)",
lptr->nick,
lptr->username,
lptr->hostname,
timeago(IgnoreTime, 2));
}
MyFree(mask);
return;
}
else
{
lptr->messages = 1;
lptr->msgs_ts[0] = current_ts;
}
}
else
{
if ((lptr->msgs_ts[1] - lptr->msgs_ts[0]) > FloodTime)
{
/*
* FloodTime seconds has passed since their last message,
* reset everything
*/
lptr->messages = 1;
lptr->msgs_ts[0] = current_ts;
}
}
}
} /* if (!IsValidAdmin(lptr)) */
} /* if (FloodProtection && GetService(av[2])) */
if (!serviceptr && (*command == '\001'))
{
struct Channel *chptr;
chptr = FindChannel(av[2]);
if (IsChannelMember(chptr, Me.osptr))
{
/* its a ctcp request to a channel that n_OperServ is on */
onctcp(who, n_OperServ, command);
}
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
if (IsChannelMember(chptr, Me.csptr))
{
/* its a ctcp request to a channel that n_ChanServ is on */
onctcp(who, n_ChanServ, command);
}
#endif /* defined(NICKSERVICES) && defined(CHANNELSERVICES) */
return;
}
if (serviceptr && (command[0] == '\001'))
{
/* process ctcp request */
onctcp(who, serviceptr->nick, command);
return;
}
if (serviceptr == Me.osptr)
os_process(who, command, NODCC);
#ifdef NICKSERVICES
else if (serviceptr == Me.nsptr)
ns_process(who, command);
#ifdef CHANNELSERVICES
else if (serviceptr == Me.csptr)
cs_process(who, command);
#endif
#ifdef MEMOSERVICES
else if (serviceptr == Me.msptr)
ms_process(who, command);
#endif
#endif /* NICKSERVICES */
#ifdef STATSERVICES
else if (serviceptr == Me.ssptr)
ss_process(who, command);
#endif /* STATSERVICES */
#ifdef HELPSERVICES
else if (serviceptr == Me.hsptr)
hs_process(who, command);
#endif /* HELPSERVICES */
#ifdef GLOBALSERVICES
else if (serviceptr == Me.gsptr)
gs_process(who, command);
#endif /* GLOBALSERVICES */
#ifdef SEENSERVICES
else if (serviceptr == Me.esptr)
es_process(who, command);
#endif /* SEENSERVICES */
} /* s_privmsg() */
/*
s_squit()
Process an SQUIT statement
av[0] = "SQUIT"
av[1] = server name
av[2] = reason
or:
av[0] = who
av[1] = "SQUIT"
av[2] = server name
av[3] = reason
*/
static void
s_squit(int ac, char **av)
{
struct Server *sptr;
#ifdef SPLIT_INFO
struct Server *tmpserv;
#endif
if (ac == 3)
sptr = FindServer(av[1]);
else if (ac == 4)
sptr = FindServer(av[2]);
else
sptr = NULL;
/* If we defined more info on split, we will not delete
* non-intentionally splitted servers from hash -kre */
#ifndef SPLIT_INFO
DeleteServer(sptr); /* delete server from list */
#else
/* Iterate all server list. Enter split_ts for both splitted hub and his
* leaves. NULLify uplinks for splitted leaves if there are any -kre */
for (tmpserv=ServerList; tmpserv; tmpserv=tmpserv->next)
{
if (tmpserv->uplink==sptr || tmpserv==sptr)
{
#ifdef EXTRA_SPLIT_INFO
/* This could spawn too much messages -kre */
SendUmode(OPERUMODE_L,
"*** Netsplit: %s (hub: %s)", tmpserv->name,
tmpserv->uplink ? tmpserv->uplink->name : "*unknown*");
#endif
tmpserv->uplink = NULL;
tmpserv->split_ts = current_ts;
tmpserv->connect_ts = 0;
}
}
#endif
} /* s_squit() */
/*
s_quit()
Process a QUIT statement
av[0] = who
av[1] = "QUIT"
av[2] = message
*/
static void
s_quit(int ac, char **av)
{
struct Luser *lptr;
#ifdef NICKSERVICES
struct NickInfo *nptr;
#endif
if (ac < 3)
return;
if (av[0][0] == ':')
lptr = FindClient(av[0] + 1);
else
lptr = FindClient(av[0]);
if (!lptr)
{
putlog(LOG1,
"DEBUG: s_quit(): Unable to locate client [%s]",
av[0] + 1);
return;
}
#ifdef NICKSERVICES
if (LastSeenInfo && (nptr = FindNick(lptr->nick)))
{
if (nptr->flags & NS_IDENTIFIED)
{
if (nptr->lastqmsg)
MyFree(nptr->lastqmsg);
nptr->lastqmsg = MyStrdup(av[2] + 1);
nptr->lastseen = current_ts;
}
}
#endif /* NICKSERVICES */
#ifdef SEENSERVICES
es_add(lptr->nick, lptr->username, lptr->hostname, av[2] + 1,
current_ts, 1);
#endif /* SEENSERVICES */
#ifdef ADVFLOOD
#if 0
if (lptr->server != Me.sptr)
#endif
updateConnectTable(lptr->username, lptr->hostname);
#endif /* ADVFLOOD */
DeleteClient(lptr); /* delete user */
} /* s_quit() */
/*
s_kill()
Process a KILL statement
av[0] = who
av[1] = "KILL"
av[2] = victim
av[3] = message
*/
static void
s_kill(int ac, char **av)
{
struct Luser *kuser,
*lptr,
*serviceptr;
struct Server *sptr;
char *who;
if (ac < 4)
return;
kuser = FindClient(av[2]);
if (!kuser)
return;
DeleteClient(kuser);
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
lptr = FindClient(who);
if (lptr)
{
SendUmode(OPERUMODE_CAPO,
"*** Operator Kill: [%s] by %s!%s@%s (%s)",
av[2],
lptr->nick,
lptr->username,
lptr->hostname,
av[3] + 1);
}
else
{
SendUmode(OPERUMODE_CAPS,
"*** Server Kill: [%s] by %s (%s)",
av[2],
who,
av[3] + 1);
}
if (match("*.*", who))
{
sptr = FindServer(who);
if (sptr)
sptr->numservkills++;
Network->TotalServKills++;
#ifdef STATSERVICES
if (Network->TotalServKills > Network->ServKillsT)
Network->ServKillsT = Network->TotalServKills;
#endif
}
else
{
if (lptr)
{
if (lptr->server)
++lptr->server->numoperkills;
#ifdef STATSERVICES
++lptr->numkills;
#endif
}
++Network->TotalOperKills;
#ifdef STATSERVICES
if (Network->TotalOperKills > Network->OperKillsT)
Network->OperKillsT = Network->TotalOperKills;
#endif
}
if ((serviceptr = GetService(av[2])))
{
/* a service nick was killed - reintroduce them to the network */
/*
* NOTE: serviceptr should ONLY be used for it's pointer value
* now, since the Luser structure it points to has been
* deleted by DeleteClient()
*/
if (lptr)
{
putlog(LOG1, "%s was killed by %s!%s@%s, re-initializing", av[2],
lptr->nick, lptr->username, lptr->hostname);
#ifdef SERVICES_FIGHT_FIX
CheckServCollide(lptr->server);
#endif /* SERVICES_FIGHT_FIX */
}
else
{
putlog(LOG1,
"%s was killed by %s (nick collide), re-initializing",
av[2], who);
toserv(":%s KILL %s :%s\n",
Me.name, av[2],
"Attempt to Nick Collide Services");
if (Me.sptr)
++Me.sptr->numservkills;
++Network->TotalServKills;
#ifdef STATSERVICES
if (Network->TotalServKills > Network->ServKillsT)
Network->ServKillsT = Network->TotalServKills;
#endif
}
/* re-introduce the killed *Serv to the network */
InitServs(serviceptr);
/*
* We can't do: if (serviceptr == Me.osptr) here, because
* if OperServ was killed, InitServs() would have given
* Me.osptr a new value, where serviceptr would be
* the old value
*/
if (!irccmp(av[2], n_OperServ))
{
struct Chanlist *tempchan;
struct Channel *chptr;
/*
* have OperServ rejoin all its chans, if other
* users are in them
*/
for (tempchan = ChanList; tempchan; tempchan = tempchan->next)
if ((chptr = FindChannel(tempchan->name)))
os_join(chptr);
}
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
/*
* If ChanServ was killed, rejoin all it's channels
*/
else if (!irccmp(av[2], n_ChanServ))
cs_RejoinChannels();
#endif
}
} /* s_kill() */
/*
s_kick()
Process a KICK statement
av[0] = who
av[1] = "KICK"
av[2] = channel
av[3] = nickname
av[4] = reason
*/
static void
s_kick(int ac, char **av)
{
char *who;
struct Luser *lptr,
*kptr;
struct Channel *chptr;
if (ac < 5)
return;
if (!(kptr = FindClient(av[3])))
return;
if (!(chptr = FindChannel(av[2])))
return;
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
lptr = FindClient(who);
RemoveFromChannel(chptr, kptr);
if (FindService(kptr))
FloodCheck(chptr, lptr, kptr, 1);
#ifdef STATSERVICES
if (lptr)
lptr->numkicks++;
#endif
if (lptr)
{
putlog(LOG3, "%s: %s!%s@%s kicked %s [%s]",
av[2],
lptr->nick,
lptr->username,
lptr->hostname,
av[3],
av[4] + 1);
SendUmode(OPERUMODE_K,
"*** %s: Kick [%s] by %s!%s@%s (%s)",
av[2],
av[3],
lptr->nick,
lptr->username,
lptr->hostname,
av[4] + 1);
}
else
{
putlog(LOG3, "%s: %s kicked %s [%s]",
av[2],
who,
av[3],
av[4] + 1);
SendUmode(OPERUMODE_K,
"*** %s: Kick [%s] by %s (%s)",
av[2],
av[3],
who,
av[4] + 1);
}
} /* s_kick() */
/*
s_mode()
Process MODE statement
av[0] = who
av[1] = "MODE"
av[2] = channel
av[3] = modes
av[4]- = optional args
*/
static void
s_mode(int ac, char **av)
{
char *who,
*modes;
struct Luser *lptr;
struct Channel *chptr;
if (ac < 4)
return;
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
lptr = FindClient(who);
modes = GetString(ac - 3, av + 3);
/* How on earth does this happen? Handle it anyway...
* -- asuffield
*/
if (!modes)
return;
if (!IsChanPrefix(*av[2]) && lptr)
{
/* it was a umode change, not channel mode */
UpdateUserModes(lptr, (*modes == ':') ? modes + 1 : modes);
MyFree(modes);
return;
}
if (!(chptr = FindChannel(av[2])))
{
MyFree(modes);
return;
}
/* update modes field in chan structure */
UpdateChanModes(lptr, who, chptr, modes);
MyFree(modes);
} /* s_mode() */
/*
s_sjoin()
Process an SJOIN statement
av[0] = server name
av[1] = "SJOIN"
av[2] = channel TS
av[3] = channel
av[4] = channel modes
av[5] = nicks
*/
void
s_sjoin(int ac, char **av)
{
char sendstr[MAXLINE],
/* new modes if the SJOIN TS is lower than the
* current TS
*/
modes[MAXLINE];
char **line,
**nicks, /* array of SJOINing nicknames */
*oldnick;
time_t CurrTime; /* current TS if its a new channel */
struct Channel *cptr, *oldptr;
int ncnt, /* number of SJOINing nicks */
mcnt;
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
struct ChanInfo *ci;
char *currnick;
int ii;
#endif
if (!irccmp(av[1], "JOIN"))
{
char *chan;
if (ac < 3)
return;
chan = (*av[2] == ':') ? av[2] + 1 : av[2];
CurrTime = current_ts;
/* kludge for older ircds that don't use SJOIN */
ircsprintf(sendstr, ":%s SJOIN %ld %s + :%s",
currenthub->realname, (long) CurrTime, chan, av[0]);
SplitBuf(sendstr, &line);
SplitBuf(av[0], &nicks);
cptr = AddChannel(line, 1, nicks);
/*
* If the channel has a C: line, have OperServ join it
*/
if (cptr)
if (IsChannel(cptr->name) && !IsChannelMember(cptr, Me.osptr))
os_join(cptr);
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
#ifdef HYBRID_ONLY
/*
* Since HYBRID_ONLY is defined, ChanServ won't join
* the channel from this call, but will call cs_CheckChan()
* on it
*/
if (cptr && (cptr->numusers <= 1))
cs_join(FindChan(chan));
#else
if (cptr)
if ((ci = FindChan(chan)) && !IsChannelMember(cptr, Me.csptr))
if (!(ci->flags & CS_FORGET))
cs_join(FindChan(chan));
#endif /* HYBRID_ONLY */
#endif
MyFree(line);
MyFree(nicks);
return;
}
/*
* It is an SJOIN
*/
if (ac < 6)
return;
mcnt = 5; /* default position for channel nicks, if no limit/key */
strcpy(modes, av[4]);
/*
* names list *should* start with a :, if it doesn't, there's a
* limit and/or key
*/
if (av[mcnt][0] != ':')
{
strcat(modes, " ");
strcat(modes, av[mcnt]);
mcnt++;
if (av[mcnt][0] != ':') /* XXX - same code, rewrite it! -kre */
{
strcat(modes, " ");
strcat(modes, av[mcnt]);
mcnt++;
}
}
ncnt = SplitBuf(av[mcnt] + 1, &nicks);
/* Safety check - if we got no nicknames, that is non-valid blank SJOIN
* and we should silently ignore it kre */
if (!ncnt)
return;
/*
* when a user joins the channel "0", they get parted from all their
* channels
*/
if (*av[3] == '0')
{
struct Luser *lptr;
struct UserChannel *tempc;
if (!(lptr = FindClient(nicks[0])))
return;
while (lptr->firstchan)
{
tempc = lptr->firstchan->next;
RemoveFromChannel(lptr->firstchan->chptr, lptr);
lptr->firstchan = tempc;
}
MyFree(nicks);
return;
} /* if (*av[3] == '0') */
oldptr = FindChannel(av[3]);
oldnick = GetNick(nicks[0]);
assert(oldnick != NULL); /* We should always know at least _first_
nickname from list, since there would be no
sjoin otherwise -kre */
if (SafeConnect)
{
if (!oldptr)
{
/*
* It is a new channel - notify all +j users
*/
SendUmode(OPERUMODE_J,
"*** New channel: %s (created by %s)",
av[3],
oldnick);
} /* if (!oldptr) */
else
SendUmode(OPERUMODE_J,
"*** Channel join: %s (%s)",
oldnick,
oldptr->name);
}
cptr = AddChannel(av, ncnt, nicks);
if (!cptr)
return; /* should never happen */
/*
* If oldptr is valid, it was an existing channel,
* so check TSora stuff to keep synched.
* Otherwise, it's a new channel, so check if
* OperServ should be monitoring it.
*/
if (oldptr)
{
if (atoi(av[2]) < cptr->since)
{
struct ChannelUser *tempuser;
struct UserChannel *tempchan;
struct ChannelBan *nextban;
#ifdef GECOSBANS
struct ChannelGecosBan *nextgecosban;
#endif /* GECOSBANS */
/*
* if the TS given in the SJOIN is less than the recorded
* channelTS, everyone in the channel except the SJOIN'ing
* nick(s) is deoped/devoiced, all previous modes are replaced
* with the new modes, and all previous bans are unset
*/
cptr->since = atoi(av[2]); /* keep the older TS */
/* keep older modes */
cptr->modes = 0;
UpdateChanModes(0, av[0] + 1, cptr, modes);
/* clear all bans */
while (cptr->firstban)
{
nextban = cptr->firstban->next;
if (cptr->firstban->who)
MyFree(cptr->firstban->who);
MyFree(cptr->firstban->mask);
MyFree(cptr->firstban);
cptr->firstban = nextban;
}
#ifdef GECOSBANS
/* clear all gecos bans */
while (cptr->firstgecosban)
{
nextgecosban = cptr->firstgecosban->next;
if (cptr->firstgecosban->who)
MyFree(cptr->firstgecosban->who);
MyFree(cptr->firstgecosban->mask);
MyFree(cptr->firstgecosban);
cptr->firstgecosban = nextgecosban;
}
#endif /* GECOSBANS */
for (tempuser = cptr->firstuser; tempuser; tempuser = tempuser->next)
{
/* don't deop the nicks who just SJOIN'd */
if (IsInNickArray(ncnt, nicks, tempuser->lptr->nick))
continue;
if (tempuser->flags & CH_OPPED)
{
tempuser->flags &= ~CH_OPPED;
tempchan = FindChannelByUser(tempuser->lptr, cptr);
if (tempchan)
tempchan->flags &= ~CH_OPPED;
}
#ifdef HYBRID7
/* Yeps, do same for halfops -Janus */
if (tempuser->flags & CH_HOPPED)
{
tempuser->flags &= ~CH_HOPPED;
tempchan = FindChannelByUser(tempuser->lptr, cptr);
if (tempchan)
tempchan->flags &= ~CH_HOPPED;
}
#endif /* HYBRID7 */
if (tempuser->flags & CH_VOICED)
{
tempuser->flags &= ~CH_VOICED;
tempchan = FindChannelByUser(tempuser->lptr, cptr);
if (tempchan)
tempchan->flags &= ~CH_VOICED;
}
} /* for (tempuser .. ) */
if (IsChannelMember(cptr, Me.osptr) &&
!IsChannelOp(cptr, Me.osptr))
{
/* n_OperServ was deoped in the sjoin, must reop it */
#ifdef SAVE_TS
os_part(cptr);
os_join(cptr);
#else
toserv(":%s MODE %s +o %s\n",
Me.name,
cptr->name,
n_OperServ);
#endif
putlog(LOG2, "%s: %s attempted to deop %s", cptr->name, av[0] + 1, n_OperServ);
}
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
if (IsChannelMember(cptr, Me.csptr) &&
!IsChannelOp(cptr, Me.csptr))
{
/* n_ChanServ was deoped in the sjoin, must reop it */
#ifdef SAVE_TS
cs_part(cptr);
cs_join(FindChan(cptr->name));
#else
toserv(":%s MODE %s +o %s\n",
Me.name,
cptr->name,
n_ChanServ);
#endif
putlog(LOG2, "%s: %s attempted to deop %s",
cptr->name,
av[0] + 1,
n_ChanServ);
}
#endif
} /* if (atoi(av[2]) < cptr->since) */
} /* if (oldptr) */
else
{
/*
* It is a new channel - check if OperServ should be
* monitoring it
*/
if (IsChannel(cptr->name) && !IsChannelMember(cptr, Me.osptr))
os_join(cptr);
} /* !oldptr */
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
ci = FindChan(cptr->name);
if (ci)
{
/*
* Call cs_CheckSjoin() to check if any of the SJOINing
* nicks should be deopped. If oldptr is NULL,
* the channel did not exist before, so pass an arguement
* of 1 to cs_CheckSjoin()'s "newchan" parameter indicating
* the channel is brand new.
*/
cs_CheckSjoin(cptr, ci, ncnt, nicks, oldptr ? 0 : 1);
for (ii = 0; ii < ncnt; ii++)
{
currnick = GetNick(nicks[ii]);
if (!currnick)
continue;
/*
* Check if nick is on the AKICK list for chname
*/
cs_CheckJoin(cptr, ci, currnick);
/*
* Check if nick has AutoOp access on channel, if so, op them
*/
cs_CheckOp(cptr, ci, currnick);
}
} /* if (ci) */
#endif /* defined(NICKSERVICES) && defined(CHANNELSERVICES) */
MyFree(nicks);
} /* s_sjoin() */
/*
s_part()
Process a PART statement
av[0] = who
av[1] = "PART"
av[2] = channel
*/
static void
s_part(int ac, char **av)
{
char *who;
if (ac < 3)
return;
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
RemoveFromChannel(FindChannel(av[2]), FindClient(who));
} /* s_part() */
/*
s_error()
Log the error that the hub sends
*/
static void
s_error(int ac, char **av)
{
char *serror;
if (ac >= 3)
serror = av[2] + 1;
else if (ac >= 2)
serror = av[1] + 1;
else
serror = "";
putlog(LOG1, "Server Error: %s", serror);
} /* s_error() */
/*
s_whois()
Reply to a remote whois query
av[0] = who
av[1] = "WHOIS"
av[2] = nickname
av[3] = nickname
*/
static void
s_whois(int ac, char **av)
{
char *who, *target, *isoper;
struct Luser *serviceptr;
if (ac < 4)
return;
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
if (av[3][0] == ':')
target = av[3] + 1;
else
target = av[3];
if (!(serviceptr = GetService(target)))
return;
SendUmode(OPERUMODE_Y,
"*** Remote whois [%s] requested by %s",
serviceptr->nick,
who);
isoper = strchr(ServiceUmodes, 'o');
toserv(":%s 311 %s %s %s %s * :%s\n",
Me.name,
who,
serviceptr->nick,
serviceptr->username,
Me.name,
serviceptr->realname);
toserv(":%s 312 %s %s %s :%s\n",
Me.name,
who,
serviceptr->nick,
Me.name,
Me.info);
if (isoper)
{
toserv(":%s 313 %s %s :is Network Service daemon\n",
Me.name,
who,
serviceptr->nick);
}
toserv(":%s 317 %s %s 0 %ld :seconds idle, signon time\n",
Me.name,
who,
serviceptr->nick,
TimeStarted);
toserv(":%s 318 %s %s :End of /WHOIS list.\n",
Me.name,
who,
serviceptr->nick);
} /* s_whois() */
/*
s_trace()
Reply to a remote trace query
av[0] = who
av[1] = "TRACE"
av[2] = server name
*/
static void
s_trace(int ac, char **av)
{
char *who, *isoper;
struct aService *sptr;
if (ac < 3)
return;
if (irccmp(av[2] + 1, Me.name) != 0)
return;
isoper = strchr(ServiceUmodes, 'o');
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
SendUmode(OPERUMODE_Y,
"*** Remote trace query requested by %s",
who);
for (sptr = ServiceBots; sptr->name; ++sptr)
{
toserv(":%s %d %s %s %d :%s[%s@%s]\n",
Me.name,
isoper ? 204 : 205,
who,
isoper ? "Oper" : "User",
isoper ? 5 : 1,
*(sptr->name),
*(sptr->ident),
Me.name);
}
toserv(":%s 206 %s Serv 10 %1.0fS %1.0fC %s :AutoConn.!*@%s\n",
Me.name,
who,
Network->TotalServers,
Network->TotalUsers,
currenthub->realname ? currenthub->realname : currenthub->hostname,
Me.name);
toserv(":%s 262 %s %s :End of TRACE\n",
Me.name,
who,
Me.name);
} /* s_trace() */
/*
s_version()
Reply to a remote version query
av[0] = who
av[1] = "VERSION"
av[2] = server name
*/
static void
s_version(int ac, char **av)
{
char *who;
if (ac < 3)
return;
if ((irccmp("*", (av[2][0] == ':') ? av[2] + 1 : av[2]) != 0) &&
(irccmp(Me.name, (av[2][0] == ':') ? av[2] + 1 : av[2]) != 0))
return;
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
SendUmode(OPERUMODE_Y,
"*** Remote version query requested by %s",
who);
toserv(":%s 351 %s dancer-services-%s. %s :dncrTS/v4\n",
Me.name,
who,
hVersion,
Me.name);
} /* s_version() */
/*
s_motd()
Send global motd to av[0]
av[0] = who
av[1] = "MOTD"
av[2] = server name
*/
static void
s_motd(int ac, char **av)
{
char *who, *final;
char line[MAXLINE];
FILE *fp;
if (ac < 3)
return;
if (irccmp(Me.name, (av[2][0] == ':') ? av[2] + 1 : av[2]) != 0)
return;
if (av[0][0] == ':')
who = av[0] + 1;
else
who = av[0];
SendUmode(OPERUMODE_Y,
"*** Remote motd query requested by %s",
who);
if (!(fp = fopen(MotdFile, "r")))
{
toserv(":%s 422 %s :MOTD File is missing\n",
Me.name,
who);
return;
}
toserv(":%s 375 %s :- %s Message of the Day -\n",
Me.name,
who,
Me.name);
while (fgets(line, MAXLINE - 1, fp))
{
if (IsEOL(*line))
{
toserv(":%s 372 %s :- \n",
Me.name,
who);
continue;
}
final = Substitute(NULL, line, NODCC);
if (final && (final != (char *) -1))
{
toserv(":%s 372 %s :- %s\n",
Me.name,
who,
final);
MyFree(final);
}
}
toserv(":%s 376 %s :End of /MOTD command\n",
Me.name,
who);
fclose(fp);
} /* s_motd() */
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
/*
s_topic()
Check if topic change conflicts with a locked topic on channel
av[2]
av[0] = who
av[1] = "TOPIC"
av[2] = channel
av[3] = new topic
*/
static void
s_topic(int ac, char **av)
{
if (ac < 4)
return;
SendUmode(OPERUMODE_T,
"*** %s: Topic by %s (%s)",
av[2],
av[0] + 1,
av[3] + 1);
cs_CheckTopic(av[0] + 1, av[2], av[3] + 1, current_ts);
} /* s_topic() */
/*
s_stopic()
Check if topic change conflicts with a locked topic on channel
av[2]
av[0] = who
av[1] = "STOPIC"
av[2] = channel
av[3] = topic nick
av[4] = topic ts
av[5] = channel ts
av[6] = new topic
*/
static void
s_stopic(int ac, char **av)
{
if (ac < 4)
return;
SendUmode(OPERUMODE_T,
"*** %s: STopic from %s by %s (%s) at %s",
av[2],
av[0] + 1,
av[3], av[6] + 1, av[4]);
cs_CheckTopic(av[3], av[2], av[6] + 1, strtoul(av[4], NULL, 0));
} /* s_topic() */
#endif
#ifdef STATSERVICES
/*
s_pong()
Process a server PONG
av[0] = :servername
av[1] = "PONG"
av[2] = servername
av[3] = Me.name
*/
static void
s_pong(int ac, char **av)
{
struct timeval pong_t;
time_t currts;
long deltasec, deltausec;
struct Server *servptr;
char *who;
who = av[0];
if (*who == ':')
who++;
if (!(servptr = FindServer(who)))
return; /* server doesn't exist */
/*
* If servptr->lastping_* is 0, we never pinged them, so
* they shouldn't be PONGing us
*/
if (!servptr->lastping_sec || !servptr->lastping_usec)
return;
GetTime(&pong_t);
currts = current_ts;
/*
* Now set delta variables to the delta given by
* pong_t->tv_{u}sec - servptr->lastping_{u}sec.
* That will represent how much time has passed since we
* sent the ping requests.
*/
deltasec = pong_t.tv_sec - servptr->lastping_sec;
deltausec = pong_t.tv_usec - servptr->lastping_usec;
/*
* Finally, set the current ping variable to the float number:
* "deltasec.deltausec".
* Of course, we must divide the microseconds by one million
* since a microsecond is 10^-6 seconds.
*/
servptr->ping = (float) (deltasec + (deltausec / 1000000.0));
/*
* Now determine if this current ping reply is the highest
* or lowest we've received from this server.
*/
if (servptr->ping > servptr->maxping)
{
servptr->maxping = servptr->ping;
servptr->maxping_ts = currts;
}
if ((servptr->minping == 0.0) || (servptr->ping < servptr->minping))
{
servptr->minping = servptr->ping;
servptr->minping_ts = currts;
}
/*
* Now reset the lastping fields so we can ping the server
* again in the future.
*/
servptr->lastping_sec = servptr->lastping_usec = 0;
if (MaxPing)
{
/*
* Make sure servptr is our current hub. Our hub's uplink
* field will ALWAYS match services, even though we are
* not the actual hub of our hub.
*/
if ((servptr->uplink == Me.sptr) && (servptr->ping > (float) MaxPing))
{
/*
* servptr matches our current hub server, and it's ping
* reply is greater than MaxPing - attempt to switch
* hubs - make sure there's at least 1 other hub to
* switch to.
*/
if (HubCount > 1)
{
SendUmode(OPERUMODE_Y,
"*** Ping response time from hub (%s) has exceeded [%s], rerouting",
servptr->name,
timeago(MaxPing, 3));
#if 0
toserv("SQUIT %s :ReRouting (current lag: %5.4f seconds)\n",
servptr->name,
servptr->ping);
#endif
toserv(":%s ERROR :Rerouting (lag: %5.4f seconds)\n",
Me.name, servptr->ping);
toserv(":%s QUIT\n", Me.name);
close(HubSock);
ClearUsers();
ClearChans();
ClearServs();
ClearHashes(0);
HubSock = NOSOCKET;
/*
* Now, try to cycle through server list for a new
* hub
*/
CycleServers();
}
}
} /* if (MaxPing) */
} /* s_pong() */
#endif /* STATSERVICES */
static void
s_sethost( int ac, char **av )
{
struct Luser *lptr = NULL;
char *who = NULL,
*newhost = NULL;
if ( ac != 4 )
return;
who = av[2];
newhost = av[3];
if ( who[0] == ':' )
who++;
if ( newhost[0] == ':' )
newhost++;
lptr = FindClient(who);
if (!lptr)
return;
#ifdef BLOCK_ALLOCATION
strncpy(lptr->hostname, newhost, HOSTLEN);
#else
MyFree(lptr->hostname);
lptr->hostname = MyStrdup(newhost);
#endif /* BLOCK_ALLOCATION */
#ifdef SEENSERVICES
es_add(lptr->nick, lptr->username, lptr->hostname, NULL, time(NULL), 2);
#endif /* SEENSERVICES */
}
static void
s_setident( int ac, char **av )
{
struct Luser *lptr;
char *who = NULL,
*newuser = NULL;
if ( ac != 4 )
return;
who = av[2];
newuser = av[3];
if ( who[0] == ':' )
who++;
if ( newuser[0] == ':' )
newuser++;
lptr = FindClient(who);
if (!lptr)
return;
#ifdef BLOCK_ALLOCATION
strncpy(lptr->username, newuser, USERLEN);
#else
MyFree(lptr->username);
lptr->username = MyStrdup(newuser);
#endif /* BLOCK_ALLOCATION */
#ifdef SEENSERVICES
es_add(lptr->nick, lptr->username, lptr->hostname, NULL, time(NULL), 2);
#endif /* SEENSERVICES */
}
static void
s_setname( int ac, char **av )
{
struct Luser *lptr;
char *who = NULL,
*newname = NULL;
if ( ac != 4 )
return;
who = av[2];
newname = av[3];
if ( who[0] == ':' )
who++;
if ( newname[0] == ':' )
newname++;
lptr = FindClient(who);
if (!lptr)
return;
#ifdef BLOCK_ALLOCATION
strncpy(lptr->realname, newname, REALLEN);
#else
MyFree(lptr->realname);
lptr->realname = MyStrdup(newname);
#endif /* BLOCK_ALLOCATION */
#ifdef SEENSERVICES
es_add(lptr->nick, lptr->username, lptr->hostname, NULL, time(NULL), 2);
#endif /* SEENSERVICES */
}
#ifdef SERVICES_FIGHT_FIX
/* This is preliminary version of the code, I will work on this later. It
* will probably have jupe/etc.. options -kre */
static void CheckServCollide(struct Server *bad_server)
{
/* Check if those two options are set at all */
if (MaxServerCollides && MinServerCollidesDelta)
{
/* If this is first collide TS */
if (!ServerCollidesTS)
{
ServerCollidesTS = current_ts;
return;
}
/* Check if collides went over top */
if (ServerCollides >= MaxServerCollides)
{
/* When was first collide? */
if (current_ts - ServerCollidesTS < MinServerCollidesDelta)
{
char note1[] = "Detected services fight from %s";
char *reason = MyMalloc(sizeof(note1) + sizeof(bad_server->name));
ircsprintf(reason, note1, bad_server->name);
SendUmode(OPERUMODE_Y, reason);
DoShutdown(NULL, reason);
}
else
{
/* We had some collides but they are slower than expected, so
* reset counter and timestamp */
ServerCollides = 0;
ServerCollidesTS = current_ts;
return;
}
}
ServerCollides++;
}
}
#endif /* SERVICES_FIGHT_FIX */
|