servmsg.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. #ifdef LEAF
  2. /*
  3. * servmsg.c -- part of server.mod
  4. *
  5. */
  6. #ifdef S_NODELAY
  7. #include <netinet/tcp.h>
  8. #endif
  9. #define msgop CFG_MSGOP.ldata ? CFG_MSGOP.ldata : CFG_MSGOP.gdata ? CFG_MSGOP.gdata : ""
  10. #define msgpass CFG_MSGPASS.ldata ? CFG_MSGPASS.ldata : CFG_MSGPASS.gdata ? CFG_MSGPASS.gdata : ""
  11. #define msginvite CFG_MSGINVITE.ldata ? CFG_MSGINVITE.ldata : CFG_MSGINVITE.gdata ? CFG_MSGINVITE.gdata : ""
  12. #define msgident CFG_MSGIDENT.ldata ? CFG_MSGIDENT.ldata : CFG_MSGIDENT.gdata ? CFG_MSGIDENT.gdata : ""
  13. char cursrvname[120]="";
  14. static time_t last_ctcp = (time_t) 0L;
  15. static int count_ctcp = 0;
  16. static char altnick_char = 0;
  17. /* We try to change to a preferred unique nick here. We always first try the
  18. * specified alternate nick. If that failes, we repeatedly modify the nick
  19. * until it gets accepted.
  20. *
  21. * sent nick:
  22. * "<altnick><c>"
  23. * ^--- additional count character: 1-9^-_\\[]`a-z
  24. * ^--------- given, alternate nick
  25. *
  26. * The last added character is always saved in altnick_char. At the very first
  27. * attempt (were altnick_char is 0), we try the alternate nick without any
  28. * additions.
  29. *
  30. * fixed by guppy (1999/02/24) and Fabian (1999/11/26)
  31. */
  32. int rolls = 0;
  33. static int gotfake433(char *from)
  34. {
  35. int l = strlen(botname) - 1;
  36. int use_chr = 1;
  37. char *altchrs = STR("-_\\`^[]");
  38. /* First run? */
  39. if (altnick_char == 0) {
  40. altnick_char = altchrs[0];
  41. /* the nick is already as long as it can be. */
  42. if (l + 1 == nick_len) {
  43. /* make the last char the altnick_char */
  44. botname[l] = altnick_char;
  45. } else {
  46. /* tack it on to the end */
  47. botname[++l] = altnick_char;
  48. botname[l + 1] = 0;
  49. }
  50. } else {
  51. char *p = strchr(altchrs, altnick_char);
  52. p++;
  53. if (!*p) {
  54. /* fun BX style rolling, WEEEE */
  55. if (rolls < 10) {
  56. char tmp;
  57. if (rolls == 0)
  58. strcpy(botname, origbotname);
  59. tmp = botname[8];
  60. if (strchr(BADNICKCHARS, tmp))
  61. tmp = '_';
  62. altnick_char = 0;
  63. use_chr = 0;
  64. rolls++;
  65. botname[8] = botname[7];
  66. botname[7] = botname[6];
  67. botname[6] = botname[5];
  68. botname[5] = botname[4];
  69. botname[4] = botname[3];
  70. botname[3] = botname[2];
  71. botname[2] = botname[1];
  72. botname[1] = botname[0];
  73. botname[0] = tmp;
  74. } else {
  75. /* when we run out of 'altchrs', then make altnick_char a random alpha */
  76. altnick_char = 'a' + random() % 26;
  77. }
  78. } else {
  79. /* else, make altnick_char the 'oknick' */
  80. altnick_char = (*p);
  81. }
  82. if (use_chr)
  83. botname[l] = altnick_char;
  84. }
  85. putlog(LOG_SERV, "*", IRC_BOTNICKINUSE, botname);
  86. dprintf(DP_SERVER, "NICK %s\n", botname);
  87. return 0;
  88. }
  89. /* Check for tcl-bound msg command, return 1 if found
  90. *
  91. * msg: proc-name <nick> <user@host> <handle> <args...>
  92. */
  93. static int check_msg(char *cmd, char *nick, char *uhost, struct userrec *u, char *args)
  94. {
  95. struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  96. int x;
  97. get_user_flagrec(u, &fr, NULL);
  98. x = check_bind(BT_msg, cmd, &fr, nick, uhost, u, args);
  99. if (x & BIND_RET_LOG) putlog(LOG_CMDS, "*", "in check_msg (%s!%s) !%s! %s %s", nick, uhost, u ? u->handle : "*" , args);
  100. if (x) return(1);
  101. else return(0);
  102. }
  103. #ifdef S_AUTH
  104. static int check_msgc(char *cmd, char *nick, char *from, struct userrec *u, char *args)
  105. {
  106. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  107. int x;
  108. x = check_bind(BT_msgc, cmd, &fr, nick, from, u, args, NULL);
  109. if (x & BIND_RET_LOG)
  110. putlog(LOG_CMDS, "*", " in check_msgc(%s!%s) !%s! %s%s %s", nick, from, u ? u->handle : "*", cmdprefix, cmd, args);
  111. if (x & BIND_RET_BREAK) return(1);
  112. return(0);
  113. }
  114. #endif /* S_AUTH */
  115. /* Return 1 if processed.
  116. */
  117. static int check_raw(char *from, char *code, char *msg)
  118. {
  119. // return check_bind(BT_raw, code, NULL, from, code, msg);
  120. return check_bind(BT_raw, code, NULL, from, msg);
  121. }
  122. static int check_ctcpr(char *nick, char *uhost, struct userrec *u,
  123. char *dest, char *keyword, char *args,
  124. bind_table_t *table)
  125. {
  126. struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  127. get_user_flagrec(u, &fr, NULL);
  128. return check_bind(table, keyword, &fr, nick, uhost, u, dest, keyword, args);
  129. }
  130. static int match_my_nick(char *nick)
  131. {
  132. if (!rfc_casecmp(nick, botname))
  133. return 1;
  134. return 0;
  135. }
  136. /* 001: welcome to IRC (use it to fix the server name)
  137. */
  138. static int got001(char *from, char *msg)
  139. {
  140. struct server_list *x;
  141. int i, servidx = findanyidx(serv);
  142. struct chanset_t *chan;
  143. /* Ok...param #1 of 001 = what server thinks my nick is */
  144. server_online = now;
  145. checked_hostmask = 0;
  146. fixcolon(msg);
  147. strncpyz(botname, msg, NICKLEN);
  148. altnick_char = 0;
  149. strncpyz(cursrvname, from, sizeof(cursrvname));
  150. dprintf(DP_SERVER, "WHOIS %s\n", botname); /* get user@host */
  151. dprintf(DP_SERVER, "MODE %s +iws\n");
  152. x = serverlist;
  153. if (x == NULL)
  154. return 0; /* Uh, no server list */
  155. /* Only join if the IRC module is loaded. */
  156. if (module_find("irc", 0, 0))
  157. for (chan = chanset; chan; chan = chan->next) {
  158. chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
  159. if (shouldjoin(chan))
  160. dprintf(DP_SERVER, "JOIN %s %s\n",
  161. (chan->name[0]) ? chan->name : chan->dname,
  162. chan->channel.key[0] ? chan->channel.key : chan->key_prot);
  163. }
  164. if (egg_strcasecmp(from, dcc[servidx].host)) {
  165. putlog(LOG_MISC, "*", "(%s claims to be %s; updating server list)",
  166. dcc[servidx].host, from);
  167. for (i = curserv; i > 0 && x != NULL; i--)
  168. x = x->next;
  169. if (x == NULL) {
  170. putlog(LOG_MISC, "*", "Invalid server list!");
  171. return 0;
  172. }
  173. if (x->realname)
  174. nfree(x->realname);
  175. if (strict_servernames == 1) {
  176. x->realname = NULL;
  177. if (x->name)
  178. nfree(x->name);
  179. x->name = nmalloc(strlen(from) + 1);
  180. strcpy(x->name, from);
  181. } else {
  182. x->realname = nmalloc(strlen(from) + 1);
  183. strcpy(x->realname, from);
  184. }
  185. }
  186. return 0;
  187. }
  188. /* Got 442: not on channel
  189. */
  190. static int got442(char *from, char *msg)
  191. {
  192. char *chname;
  193. struct chanset_t *chan;
  194. struct server_list *x;
  195. int i;
  196. for (x = serverlist, i = 0; x; x = x->next, i++)
  197. if (i == curserv) {
  198. if (egg_strcasecmp(from, x->realname ? x->realname : x->name))
  199. return 0;
  200. break;
  201. }
  202. newsplit(&msg);
  203. chname = newsplit(&msg);
  204. chan = findchan(chname);
  205. if (chan)
  206. if (shouldjoin(chan)) {
  207. module_entry *me = module_find("channels", 0, 0);
  208. putlog(LOG_MISC, chname, IRC_SERVNOTONCHAN, chname);
  209. if (me && me->funcs)
  210. (me->funcs[CHANNEL_CLEAR])(chan, 1);
  211. chan->status &= ~CHAN_ACTIVE;
  212. dprintf(DP_MODE, "JOIN %s %s\n", chan->name,
  213. chan->channel.key[0] ? chan->channel.key : chan->key_prot);
  214. }
  215. return 0;
  216. }
  217. /* Close the current server connection.
  218. */
  219. static void nuke_server(char *reason)
  220. {
  221. if (serv >= 0) {
  222. int servidx = findanyidx(serv);
  223. if (reason && (servidx > 0))
  224. dprintf(servidx, "QUIT :%s\n", reason);
  225. disconnect_server(servidx);
  226. lostdcc(servidx);
  227. }
  228. }
  229. static char ctcp_reply[1024] = "";
  230. static int lastmsgs[FLOOD_GLOBAL_MAX];
  231. static char lastmsghost[FLOOD_GLOBAL_MAX][81];
  232. static time_t lastmsgtime[FLOOD_GLOBAL_MAX];
  233. /* Do on NICK, PRIVMSG, NOTICE and JOIN.
  234. */
  235. static int detect_flood(char *floodnick, char *floodhost, char *from, int which)
  236. {
  237. char *p, ftype[10], h[1024];
  238. struct userrec *u;
  239. int thr = 0, lapse = 0, atr;
  240. u = get_user_by_host(from);
  241. atr = u ? u->flags : 0;
  242. if (atr & (USER_BOT))
  243. return 0;
  244. #ifdef S_AUTH
  245. if (findauth(floodhost) > -1)
  246. return 0;
  247. #endif /* S_AUTH */
  248. /* Determine how many are necessary to make a flood */
  249. switch (which) {
  250. case FLOOD_PRIVMSG:
  251. case FLOOD_NOTICE:
  252. thr = flud_thr;
  253. lapse = flud_time;
  254. strcpy(ftype, "msg");
  255. break;
  256. case FLOOD_CTCP:
  257. thr = flud_ctcp_thr;
  258. lapse = flud_ctcp_time;
  259. strcpy(ftype, "ctcp");
  260. break;
  261. }
  262. if ((thr == 0) || (lapse == 0))
  263. return 0; /* No flood protection */
  264. /* Okay, make sure i'm not flood-checking myself */
  265. if (match_my_nick(floodnick))
  266. return 0;
  267. if (!egg_strcasecmp(floodhost, botuserhost))
  268. return 0; /* My user@host (?) */
  269. p = strchr(floodhost, '@');
  270. if (p) {
  271. p++;
  272. if (egg_strcasecmp(lastmsghost[which], p)) { /* New */
  273. strcpy(lastmsghost[which], p);
  274. lastmsgtime[which] = now;
  275. lastmsgs[which] = 0;
  276. return 0;
  277. }
  278. } else
  279. return 0; /* Uh... whatever. */
  280. if (lastmsgtime[which] < now - lapse) {
  281. /* Flood timer expired, reset it */
  282. lastmsgtime[which] = now;
  283. lastmsgs[which] = 0;
  284. return 0;
  285. }
  286. lastmsgs[which]++;
  287. if (lastmsgs[which] >= thr) { /* FLOOD */
  288. /* Reset counters */
  289. lastmsgs[which] = 0;
  290. lastmsgtime[which] = 0;
  291. lastmsghost[which][0] = 0;
  292. u = get_user_by_host(from);
  293. /* Private msg */
  294. simple_sprintf(h, "*!*@%s", p);
  295. putlog(LOG_MISC, "*", IRC_FLOODIGNORE1, p);
  296. addignore(h, botnetnick, (which == FLOOD_CTCP) ? "CTCP flood" :
  297. "MSG/NOTICE flood", now + (60 * ignore_time));
  298. }
  299. return 0;
  300. }
  301. /* Check for more than 8 control characters in a line.
  302. * This could indicate: beep flood CTCP avalanche.
  303. */
  304. static int detect_avalanche(char *msg)
  305. {
  306. int count = 0;
  307. unsigned char *p;
  308. for (p = (unsigned char *) msg; (*p) && (count < 8); p++)
  309. if ((*p == 7) || (*p == 1))
  310. count++;
  311. if (count >= 8)
  312. return 1;
  313. else
  314. return 0;
  315. }
  316. /* Got a private message.
  317. */
  318. static int gotmsg(char *from, char *msg)
  319. {
  320. char *to, buf[UHOSTLEN], *nick, ctcpbuf[512], *uhost = buf, *ctcp;
  321. char *p, *p1, *code;
  322. struct userrec *u;
  323. int ctcp_count = 0;
  324. #ifdef S_AUTH
  325. int i = 0;
  326. #endif /* S_AUTH */
  327. int ignoring = 0;
  328. if (msg[0] && ((strchr(CHANMETA, *msg) != NULL) ||
  329. (*msg == '@'))) /* Notice to a channel, not handled here */
  330. return 0;
  331. ignoring = match_ignore(from);
  332. to = newsplit(&msg);
  333. fixcolon(msg);
  334. /* Only check if flood-ctcp is active */
  335. strcpy(uhost, from);
  336. nick = splitnick(&uhost);
  337. if (flud_ctcp_thr && detect_avalanche(msg)) {
  338. if (!ignoring) {
  339. putlog(LOG_MODES, "*", "Avalanche from %s - ignoring", from);
  340. p = strchr(uhost, '@');
  341. if (p != NULL)
  342. p++;
  343. else
  344. p = uhost;
  345. simple_sprintf(ctcpbuf, "*!*@%s", p);
  346. addignore(ctcpbuf, botnetnick, "ctcp avalanche",
  347. now + (60 * ignore_time));
  348. }
  349. }
  350. /* Check for CTCP: */
  351. ctcp_reply[0] = 0;
  352. p = strchr(msg, 1);
  353. while ((p != NULL) && (*p)) {
  354. p++;
  355. p1 = p;
  356. while ((*p != 1) && (*p != 0))
  357. p++;
  358. if (*p == 1) {
  359. *p = 0;
  360. ctcp = strcpy(ctcpbuf, p1);
  361. strcpy(p1 - 1, p + 1);
  362. if (!ignoring)
  363. detect_flood(nick, uhost, from,
  364. strncmp(ctcp, "ACTION ", 7) ? FLOOD_CTCP : FLOOD_PRIVMSG);
  365. /* Respond to the first answer_ctcp */
  366. p = strchr(msg, 1);
  367. if (ctcp_count < answer_ctcp) {
  368. ctcp_count++;
  369. if (ctcp[0] != ' ') {
  370. code = newsplit(&ctcp);
  371. if ((to[0] == '$') || strchr(to, '.')) {
  372. if (!ignoring)
  373. /* Don't interpret */
  374. putlog(LOG_PUBLIC, to, "CTCP %s: %s from %s (%s) to %s",
  375. code, ctcp, nick, uhost, to);
  376. } else {
  377. u = get_user_by_host(from);
  378. if (!ignoring || trigger_on_ignore) {
  379. if (!check_ctcp(nick, uhost, u, to, code, ctcp) &&
  380. !ignoring) {
  381. if ((lowercase_ctcp && !egg_strcasecmp(code, "DCC")) ||
  382. (!lowercase_ctcp && !strcmp(code, "DCC"))) {
  383. /* If it gets this far unhandled, it means that
  384. * the user is totally unknown.
  385. */
  386. code = newsplit(&ctcp);
  387. if (!strcmp(code, "CHAT")) {
  388. if (!quiet_reject) {
  389. if (u)
  390. dprintf(DP_HELP, "NOTICE %s :%s\n", nick,
  391. "I'm not accepting call at the moment.");
  392. else
  393. dprintf(DP_HELP, "NOTICE %s :%s\n",
  394. nick, DCC_NOSTRANGERS);
  395. }
  396. if (!ischanhub())
  397. putlog(LOG_MISC, "*", "%s: %s", DCC_REFUSEDNC, from);
  398. else
  399. putlog(LOG_MISC, "*", "%s: %s", DCC_REFUSED, from);
  400. } else
  401. putlog(LOG_MISC, "*", "Refused DCC %s: %s",
  402. code, from);
  403. }
  404. }
  405. if (!strcmp(code, "ACTION")) {
  406. putlog(LOG_MSGS, "*", "Action to %s: %s %s",
  407. to, nick, ctcp);
  408. } else {
  409. putlog(LOG_MSGS, "*", "CTCP %s: %s from %s (%s)",
  410. code, ctcp, nick, uhost);
  411. } /* I love a good close cascade ;) */
  412. }
  413. }
  414. }
  415. }
  416. }
  417. }
  418. /* Send out possible ctcp responses */
  419. if (ctcp_reply[0]) {
  420. if (ctcp_mode != 2) {
  421. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
  422. } else {
  423. if (now - last_ctcp > flud_ctcp_time) {
  424. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
  425. count_ctcp = 1;
  426. } else if (count_ctcp < flud_ctcp_thr) {
  427. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
  428. count_ctcp++;
  429. }
  430. last_ctcp = now;
  431. }
  432. }
  433. if (msg[0]) {
  434. if ((to[0] == '$') || (strchr(to, '.') != NULL)) {
  435. /* Msg from oper */
  436. if (!ignoring) {
  437. detect_flood(nick, uhost, from, FLOOD_PRIVMSG);
  438. /* Do not interpret as command */
  439. putlog(LOG_MSGS | LOG_SERV, "*", "[%s!%s to %s] %s",nick, uhost, to, msg);
  440. }
  441. } else {
  442. char *code;
  443. struct userrec *u;
  444. detect_flood(nick, uhost, from, FLOOD_PRIVMSG);
  445. u = get_user_by_host(from);
  446. code = newsplit(&msg);
  447. rmspace(msg);
  448. #ifdef S_AUTH
  449. i = findauth(uhost);
  450. /* is it a cmd? */
  451. if (i > -1 && auth[i].authed && code[0] == cmdprefix[0] && code[1]) {
  452. code++;
  453. u = auth[i].user;
  454. if (check_msgc(code, nick, uhost, u, msg))
  455. auth[i].atime = now;
  456. else
  457. putlog(LOG_MSGS, "*", "[%s] %s %s", from, code, msg);
  458. } else if ((code[0] != cmdprefix[0] || !code[1] || i == -1 || !(auth[i].authed))) {
  459. #endif /* S_AUTH */
  460. if (!ignoring) {
  461. int doit = 1, result = 0;
  462. #ifdef S_MSGCMDS
  463. if (!egg_strcasecmp(code, "op") || !egg_strcasecmp(code, "pass") || !egg_strcasecmp(code, "invite")
  464. || !egg_strcasecmp(code, "ident")
  465. || !egg_strcasecmp(code, msgop) || !egg_strcasecmp(code, msgpass)
  466. || !egg_strcasecmp(code, msginvite) || !egg_strcasecmp(code, msgident)) {
  467. /* || !strcmp(code, msgop) || !strcmp(code, msgpass) || !strcmp(code, msgop)) { */
  468. char buf[10];
  469. doit = 0;
  470. buf[0] = 0;
  471. if (!egg_strcasecmp(code, msgop))
  472. sprintf(buf, "op");
  473. else if (!egg_strcasecmp(code, msgpass))
  474. sprintf(buf, "pass");
  475. else if (!egg_strcasecmp(code, msginvite))
  476. sprintf(buf, "invite");
  477. else if (!egg_strcasecmp(code, msgident))
  478. sprintf(buf, "ident");
  479. if (buf[0])
  480. result = check_msg(buf, nick, uhost, u, msg);
  481. }
  482. #endif /* S_MSGCMDS */
  483. if (doit)
  484. result = check_msg(code, nick, uhost, u, msg);
  485. if (!result)
  486. putlog(LOG_MSGS, "*", " in gotmsg [%s] %s %s", from, code, msg);
  487. }
  488. #ifdef S_AUTH
  489. }
  490. #endif /* S_AUTH */
  491. }
  492. }
  493. return 0;
  494. }
  495. /* Got a private notice.
  496. */
  497. static int gotnotice(char *from, char *msg)
  498. {
  499. char *to, *nick, ctcpbuf[512], *p, *p1, buf[512], *uhost = buf, *ctcp;
  500. struct userrec *u;
  501. int ignoring;
  502. if (msg[0] && ((strchr(CHANMETA, *msg) != NULL) ||
  503. (*msg == '@'))) /* Notice to a channel, not handled here */
  504. return 0;
  505. ignoring = match_ignore(from);
  506. to = newsplit(&msg);
  507. fixcolon(msg);
  508. strcpy(uhost, from);
  509. nick = splitnick(&uhost);
  510. if (flud_ctcp_thr && detect_avalanche(msg)) {
  511. /* Discard -- kick user if it was to the channel */
  512. if (!ignoring)
  513. putlog(LOG_MODES, "*", "Avalanche from %s", from);
  514. return 0;
  515. }
  516. /* Check for CTCP: */
  517. p = strchr(msg, 1);
  518. while ((p != NULL) && (*p)) {
  519. p++;
  520. p1 = p;
  521. while ((*p != 1) && (*p != 0))
  522. p++;
  523. if (*p == 1) {
  524. *p = 0;
  525. ctcp = strcpy(ctcpbuf, p1);
  526. strcpy(p1 - 1, p + 1);
  527. if (!ignoring)
  528. detect_flood(nick, uhost, from, FLOOD_CTCP);
  529. p = strchr(msg, 1);
  530. if (ctcp[0] != ' ') {
  531. char *code = newsplit(&ctcp);
  532. if ((to[0] == '$') || strchr(to, '.')) {
  533. if (!ignoring)
  534. putlog(LOG_PUBLIC, "*",
  535. "CTCP reply %s: %s from %s (%s) to %s", code, ctcp,
  536. nick, uhost, to);
  537. } else {
  538. u = get_user_by_host(from);
  539. if (!ignoring || trigger_on_ignore) {
  540. check_ctcr(nick, uhost, u, to, code, ctcp);
  541. if (!ignoring)
  542. /* Who cares? */
  543. putlog(LOG_MSGS, "*",
  544. "CTCP reply %s: %s from %s (%s) to %s",
  545. code, ctcp, nick, uhost, to);
  546. }
  547. }
  548. }
  549. }
  550. }
  551. if (msg[0]) {
  552. if (((to[0] == '$') || strchr(to, '.')) && !ignoring) {
  553. detect_flood(nick, uhost, from, FLOOD_NOTICE);
  554. putlog(LOG_MSGS | LOG_SERV, "*", "-%s (%s) to %s- %s",
  555. nick, uhost, to, msg);
  556. } else {
  557. /* Server notice? */
  558. if ((nick[0] == 0) || (uhost[0] == 0)) {
  559. /* Hidden `250' connection count message from server */
  560. if (strncmp(msg, "Highest connection count:", 25))
  561. putlog(LOG_SERV, "*", "-NOTICE- %s", msg);
  562. } else {
  563. detect_flood(nick, uhost, from, FLOOD_NOTICE);
  564. u = get_user_by_host(from);
  565. if (!ignoring)
  566. putlog(LOG_MSGS, "*", "-%s (%s)- %s", nick, uhost, msg);
  567. }
  568. }
  569. }
  570. return 0;
  571. }
  572. /* WALLOPS: oper's nuisance
  573. */
  574. static int gotwall(char *from, char *msg)
  575. {
  576. char *nick;
  577. fixcolon(msg);
  578. /* Following is not needed at all, but we'll keep it for compatibility sak$
  579. * so not to confuse possible scripts that are parsing log files.
  580. */
  581. if (strchr(from, '!')) {
  582. nick = splitnick(&from);
  583. putlog(LOG_WALL, "*", "!%s(%s)! %s", nick, from, msg);
  584. } else
  585. putlog(LOG_WALL, "*", "!%s! %s", from, msg);
  586. return 0;
  587. }
  588. static void server_10secondly()
  589. {
  590. if (server_online && keepnick) {
  591. /* NOTE: now that botname can but upto NICKLEN bytes long,
  592. * check that it's not just a truncation of the full nick.
  593. */
  594. if (strncmp(botname, origbotname, strlen(botname))) {
  595. /* See if my nickname is in use and if if my nick is right. */
  596. dprintf(DP_SERVER, "ISON :%s %s\n", botname, origbotname);
  597. }
  598. }
  599. }
  600. /* Called once a minute... but if we're the only one on the
  601. * channel, we only wanna send out "lusers" once every 5 mins.
  602. */
  603. static void minutely_checks()
  604. {
  605. /* Only check if we have already successfully logged in. */
  606. if (server_online) {
  607. static int count = 4;
  608. int ok = 0;
  609. struct chanset_t *chan;
  610. for (chan = chanset; chan; chan = chan->next) {
  611. if (channel_active(chan) && chan->channel.members == 1) {
  612. ok = 1;
  613. break;
  614. }
  615. }
  616. if (!ok)
  617. return;
  618. count++;
  619. if (count >= 5) {
  620. dprintf(DP_SERVER, "LUSERS\n");
  621. count = 0;
  622. }
  623. }
  624. }
  625. /* Pong from server.
  626. */
  627. static int gotpong(char *from, char *msg)
  628. {
  629. newsplit(&msg);
  630. fixcolon(msg); /* Scrap server name */
  631. server_lag = now - my_atoul(msg);
  632. if (server_lag > 99999) {
  633. /* IRCnet lagmeter support by drummer */
  634. server_lag = now - lastpingtime;
  635. }
  636. return 0;
  637. }
  638. /* This is a reply on ISON :<current> <orig> [<alt>]
  639. */
  640. static void got303(char *from, char *msg)
  641. {
  642. char *tmp;
  643. int ison_orig = 0;
  644. if (!keepnick ||
  645. !strncmp(botname, origbotname, strlen(botname))) {
  646. return;
  647. }
  648. newsplit(&msg);
  649. fixcolon(msg);
  650. tmp = newsplit(&msg);
  651. if (tmp[0] && !rfc_casecmp(botname, tmp)) {
  652. while ((tmp = newsplit(&msg))[0]) { /* no, it's NOT == */
  653. if (!rfc_casecmp(tmp, origbotname))
  654. ison_orig = 1;
  655. }
  656. if (!ison_orig) {
  657. if (!nick_juped)
  658. putlog(LOG_MISC, "*", IRC_GETORIGNICK, origbotname);
  659. dprintf(DP_SERVER, "NICK %s\n", origbotname);
  660. }
  661. }
  662. }
  663. /* 432 : Bad nickname
  664. */
  665. static int got432(char *from, char *msg)
  666. {
  667. char *erroneus;
  668. newsplit(&msg);
  669. erroneus = newsplit(&msg);
  670. if (server_online)
  671. putlog(LOG_MISC, "*", "NICK IS INVALID: %s (keeping '%s').", erroneus,
  672. botname);
  673. else {
  674. putlog(LOG_MISC, "*", IRC_BADBOTNICK);
  675. if (!keepnick) {
  676. makepass(erroneus);
  677. erroneus[NICKMAX] = 0;
  678. dprintf(DP_MODE, "NICK %s\n", erroneus);
  679. }
  680. return 0;
  681. }
  682. return 0;
  683. }
  684. /* 433 : Nickname in use
  685. * Change nicks till we're acceptable or we give up
  686. */
  687. static int got433(char *from, char *msg)
  688. {
  689. char *tmp;
  690. if (server_online) {
  691. /* We are online and have a nickname, we'll keep it */
  692. newsplit(&msg);
  693. tmp = newsplit(&msg);
  694. putlog(LOG_MISC, "*", "NICK IN USE: %s (keeping '%s').", tmp, botname);
  695. nick_juped = 0;
  696. return 0;
  697. }
  698. gotfake433(from);
  699. return 0;
  700. }
  701. /* 437 : Nickname juped (IRCnet)
  702. */
  703. static int got437(char *from, char *msg)
  704. {
  705. char *s;
  706. struct chanset_t *chan;
  707. newsplit(&msg);
  708. s = newsplit(&msg);
  709. if (s[0] && (strchr(CHANMETA, s[0]) != NULL)) {
  710. chan = findchan(s);
  711. if (chan) {
  712. if (chan->status & CHAN_ACTIVE) {
  713. putlog(LOG_MISC, "*", IRC_CANTCHANGENICK, s);
  714. } else {
  715. if (!channel_juped(chan)) {
  716. putlog(LOG_MISC, "*", IRC_CHANNELJUPED, s);
  717. chan->status |= CHAN_JUPED;
  718. }
  719. }
  720. }
  721. } else if (server_online) {
  722. if (!nick_juped)
  723. putlog(LOG_MISC, "*", "NICK IS JUPED: %s (keeping '%s').", s, botname);
  724. if (!rfc_casecmp(s, origbotname))
  725. nick_juped = 1;
  726. } else {
  727. putlog(LOG_MISC, "*", "%s: %s", IRC_BOTNICKJUPED, s);
  728. gotfake433(from);
  729. }
  730. return 0;
  731. }
  732. /* 438 : Nick change too fast
  733. */
  734. static int got438(char *from, char *msg)
  735. {
  736. newsplit(&msg);
  737. newsplit(&msg);
  738. fixcolon(msg);
  739. putlog(LOG_MISC, "*", "%s", msg);
  740. return 0;
  741. }
  742. static int got451(char *from, char *msg)
  743. {
  744. /* Usually if we get this then we really messed up somewhere
  745. * or this is a non-standard server, so we log it and kill the socket
  746. * hoping the next server will work :) -poptix
  747. */
  748. /* Um, this does occur on a lagged anti-spoof server connection if the
  749. * (minutely) sending of joins occurs before the bot does its ping reply.
  750. * Probably should do something about it some time - beldin
  751. */
  752. putlog(LOG_MISC, "*", IRC_NOTREGISTERED1, from);
  753. nuke_server(IRC_NOTREGISTERED2);
  754. return 0;
  755. }
  756. /* Got error notice
  757. */
  758. static int goterror(char *from, char *msg)
  759. {
  760. /* FIXME: fixcolon doesn't do what we need here, this is a temp fix
  761. * fixcolon(msg);
  762. */
  763. if (msg[0] == ':')
  764. msg++;
  765. putlog(LOG_SERV, "*", "-ERROR from server- %s", msg);
  766. if (serverror_quit) {
  767. putlog(LOG_SERV, "*", "Disconnecting from server.");
  768. nuke_server("Bah, stupid error messages.");
  769. }
  770. return 1;
  771. }
  772. /* Got nick change.
  773. */
  774. static int gotnick(char *from, char *msg)
  775. {
  776. char *nick;
  777. struct userrec *u;
  778. u = get_user_by_host(from);
  779. nick = splitnick(&from);
  780. fixcolon(msg);
  781. check_queues(nick, msg);
  782. if (match_my_nick(nick)) {
  783. /* Regained nick! */
  784. strncpyz(botname, msg, NICKLEN);
  785. altnick_char = 0;
  786. if (!strcmp(msg, origbotname)) {
  787. putlog(LOG_SERV | LOG_MISC, "*", "Regained nickname '%s'.", msg);
  788. nick_juped = 0;
  789. } else if (keepnick && strcmp(nick, msg)) {
  790. putlog(LOG_SERV | LOG_MISC, "*", "Nickname changed to '%s'???", msg);
  791. if (!rfc_casecmp(nick, origbotname)) {
  792. putlog(LOG_MISC, "*", IRC_GETORIGNICK, origbotname);
  793. dprintf(DP_SERVER, "NICK %s\n", origbotname);
  794. }
  795. } else
  796. putlog(LOG_SERV | LOG_MISC, "*", "Nickname changed to '%s'???", msg);
  797. } else if ((keepnick) && (rfc_casecmp(nick, msg))) {
  798. /* Only do the below if there was actual nick change, case doesn't count */
  799. if (!rfc_casecmp(nick, origbotname)) {
  800. putlog(LOG_MISC, "*", IRC_GETORIGNICK, origbotname);
  801. dprintf(DP_SERVER, "NICK %s\n", origbotname);
  802. }
  803. }
  804. return 0;
  805. }
  806. static int gotmode(char *from, char *msg)
  807. {
  808. char *ch;
  809. ch = newsplit(&msg);
  810. /* Usermode changes? */
  811. if (strchr(CHANMETA, ch[0]) == NULL) {
  812. if (match_my_nick(ch) && check_mode_r) {
  813. /* umode +r? - D0H dalnet uses it to mean something different */
  814. fixcolon(msg);
  815. if ((msg[0] == '+') && strchr(msg, 'r')) {
  816. int servidx = findanyidx(serv);
  817. putlog(LOG_MISC | LOG_JOIN, "*",
  818. "%s has me i-lined (jumping)", dcc[servidx].host);
  819. nuke_server("i-lines suck");
  820. }
  821. }
  822. }
  823. return 0;
  824. }
  825. static void disconnect_server(int idx)
  826. {
  827. server_online = 0;
  828. if (dcc[idx].sock >= 0)
  829. killsock(dcc[idx].sock);
  830. dcc[idx].sock = (-1);
  831. serv = (-1);
  832. botuserhost[0] = 0;
  833. }
  834. static void eof_server(int idx)
  835. {
  836. putlog(LOG_SERV, "*", "%s %s", IRC_DISCONNECTED, dcc[idx].host);
  837. #ifdef S_AUTH
  838. {
  839. int i = 0;
  840. if (ischanhub() && auth_total > 0) {
  841. putlog(LOG_DEBUG, "*", "Removing %d auth entries.", auth_total);
  842. for (i = 0; i < auth_total; i++)
  843. removeauth(i);
  844. }
  845. }
  846. #endif /* S_AUTH */
  847. disconnect_server(idx);
  848. lostdcc(idx);
  849. }
  850. static void display_server(int idx, char *buf)
  851. {
  852. sprintf(buf, "%s (lag: %d)", trying_server ? "conn" : "serv",
  853. server_lag);
  854. }
  855. static void connect_server(void);
  856. static void kill_server(int idx, void *x)
  857. {
  858. module_entry *me;
  859. disconnect_server(idx);
  860. if ((me = module_find("channels", 0, 0)) && me->funcs) {
  861. struct chanset_t *chan;
  862. for (chan = chanset; chan; chan = chan->next)
  863. (me->funcs[CHANNEL_CLEAR]) (chan, 1);
  864. }
  865. /* A new server connection will be automatically initiated in
  866. about 2 seconds. */
  867. }
  868. static void timeout_server(int idx)
  869. {
  870. putlog(LOG_SERV, "*", "Timeout: connect to %s", dcc[idx].host);
  871. disconnect_server(idx);
  872. lostdcc(idx);
  873. }
  874. static void server_activity(int idx, char *msg, int len);
  875. static struct dcc_table SERVER_SOCKET =
  876. {
  877. "SERVER",
  878. 0,
  879. eof_server,
  880. server_activity,
  881. NULL,
  882. timeout_server,
  883. display_server,
  884. NULL,
  885. kill_server,
  886. NULL
  887. };
  888. int isop(char *mode)
  889. {
  890. int state = 0,
  891. cnt = 0;
  892. char *p;
  893. p = mode;
  894. while ((*p) && (*p != ' ')) {
  895. if (*p == '-')
  896. state = 1;
  897. else if (*p == '+')
  898. state = 0;
  899. else if ((!state) && (*p == 'o'))
  900. cnt++;
  901. p++;
  902. }
  903. return (cnt >= 1);
  904. }
  905. int ismdop(char *mode)
  906. {
  907. int state = 0,
  908. cnt = 0;
  909. char *p;
  910. p = mode;
  911. while ((*p) && (*p != ' ')) {
  912. if (*p == '-')
  913. state = 1;
  914. else if (*p == '+')
  915. state = 0;
  916. else if ((state) && (*p == 'o'))
  917. cnt++;
  918. p++;
  919. }
  920. return (cnt >= 3);
  921. }
  922. static void server_activity(int idx, char *msg, int len)
  923. {
  924. char *from, *code;
  925. if (trying_server) {
  926. strcpy(dcc[idx].nick, "(server)");
  927. putlog(LOG_SERV, "*", "Connected to %s", dcc[idx].host);
  928. trying_server = 0;
  929. SERVER_SOCKET.timeout_val = 0;
  930. }
  931. waiting_for_awake = 0;
  932. from = "";
  933. if (msg[0] == ':') {
  934. msg++;
  935. from = newsplit(&msg);
  936. }
  937. code = newsplit(&msg);
  938. if (use_console_r) {
  939. if (!strcmp(code, "PRIVMSG") || !strcmp(code, "NOTICE")) {
  940. if (!match_ignore(from))
  941. putlog(LOG_RAW, "@", "[@] %s %s %s", from, code, msg);
  942. } else
  943. putlog(LOG_RAW, "@", "[@] %s %s %s", from, code, msg);
  944. }
  945. /* This has GOT to go into the raw binding table, * merely because this
  946. * is less effecient.
  947. */
  948. check_raw(from, code, msg);
  949. }
  950. static int gotping(char *from, char *msg)
  951. {
  952. fixcolon(msg);
  953. dprintf(DP_MODE, "PONG :%s\n", msg);
  954. return 0;
  955. }
  956. static int gotkick(char *from, char *msg)
  957. {
  958. char *nick;
  959. nick = from;
  960. if (rfc_casecmp(nick, botname))
  961. /* Not my kick, I don't need to bother about it. */
  962. return 0;
  963. if (use_penalties) {
  964. last_time += 2;
  965. if (debug_output)
  966. putlog(LOG_SRVOUT, "*", "adding 2secs penalty (successful kick)");
  967. }
  968. return 0;
  969. }
  970. /* Another sec penalty if bot did a whois on another server.
  971. */
  972. static int whoispenalty(char *from, char *msg)
  973. {
  974. struct server_list *x = serverlist;
  975. int i, ii;
  976. if (x && use_penalties) {
  977. i = ii = 0;
  978. for (; x; x = x->next) {
  979. if (i == curserv) {
  980. if ((strict_servernames == 1) || !x->realname) {
  981. if (strcmp(x->name, from))
  982. ii = 1;
  983. } else {
  984. if (strcmp(x->realname, from))
  985. ii = 1;
  986. }
  987. }
  988. i++;
  989. }
  990. if (ii) {
  991. last_time += 1;
  992. if (debug_output)
  993. putlog(LOG_SRVOUT, "*", "adding 1sec penalty (remote whois)");
  994. }
  995. }
  996. return 0;
  997. }
  998. static int got311(char *from, char *msg)
  999. {
  1000. char *n1, *n2, *u, *h;
  1001. n1 = newsplit(&msg);
  1002. n2 = newsplit(&msg);
  1003. u = newsplit(&msg);
  1004. h = newsplit(&msg);
  1005. if (!n1 || !n2 || !u || !h)
  1006. return 0;
  1007. if (match_my_nick(n2))
  1008. egg_snprintf(botuserhost, sizeof botuserhost, "%s@%s", u, h);
  1009. return 0;
  1010. }
  1011. static cmd_t my_raw_binds[] =
  1012. {
  1013. {"PRIVMSG", "", (Function) gotmsg, NULL},
  1014. {"NOTICE", "", (Function) gotnotice, NULL},
  1015. {"MODE", "", (Function) gotmode, NULL},
  1016. {"PING", "", (Function) gotping, NULL},
  1017. {"PONG", "", (Function) gotpong, NULL},
  1018. {"WALLOPS", "", (Function) gotwall, NULL},
  1019. {"001", "", (Function) got001, NULL},
  1020. {"303", "", (Function) got303, NULL},
  1021. {"432", "", (Function) got432, NULL},
  1022. {"433", "", (Function) got433, NULL},
  1023. {"437", "", (Function) got437, NULL},
  1024. {"438", "", (Function) got438, NULL},
  1025. {"451", "", (Function) got451, NULL},
  1026. {"442", "", (Function) got442, NULL},
  1027. {"NICK", "", (Function) gotnick, NULL},
  1028. {"ERROR", "", (Function) goterror, NULL},
  1029. /* ircu2.10.10 has a bug when a client is throttled ERROR is sent wrong */
  1030. {"ERROR:", "", (Function) goterror, NULL},
  1031. {"KICK", "", (Function) gotkick, NULL},
  1032. {"318", "", (Function) whoispenalty, NULL},
  1033. {"311", "", (Function) got311, NULL},
  1034. {NULL, NULL, NULL, NULL}
  1035. };
  1036. static void server_resolve_success(int);
  1037. static void server_resolve_failure(int);
  1038. /* Hook up to a server
  1039. */
  1040. static void connect_server(void)
  1041. {
  1042. char pass[121], botserver[UHOSTLEN];
  1043. static int oldserv = -1;
  1044. int servidx;
  1045. unsigned int botserverport = 0;
  1046. waiting_for_awake = 0;
  1047. trying_server = now;
  1048. empty_msgq();
  1049. /* Start up the counter (always reset it if "never-give-up" is on) */
  1050. if ((oldserv < 0) || (never_give_up))
  1051. oldserv = curserv;
  1052. if (newserverport) { /* Jump to specified server */
  1053. curserv = (-1); /* Reset server list */
  1054. strcpy(botserver, newserver);
  1055. botserverport = newserverport;
  1056. strcpy(pass, newserverpass);
  1057. newserver[0] = 0;
  1058. newserverport = 0;
  1059. newserverpass[0] = 0;
  1060. oldserv = (-1);
  1061. } else
  1062. pass[0] = 0;
  1063. if (!cycle_time) {
  1064. struct chanset_t *chan;
  1065. struct server_list *x = serverlist;
  1066. if (!x)
  1067. return;
  1068. servidx = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
  1069. if (servidx < 0) {
  1070. putlog(LOG_SERV, "*",
  1071. "NO MORE DCC CONNECTIONS -- Can't create server connection.");
  1072. return;
  1073. }
  1074. next_server(&curserv, botserver, &botserverport, pass);
  1075. putlog(LOG_SERV, "*", "%s %s:%d", IRC_SERVERTRY, botserver, botserverport);
  1076. dcc[servidx].port = botserverport;
  1077. strcpy(dcc[servidx].nick, "(server)");
  1078. strncpyz(dcc[servidx].host, botserver, UHOSTLEN);
  1079. botuserhost[0] = 0;
  1080. nick_juped = 0;
  1081. for (chan = chanset; chan; chan = chan->next)
  1082. chan->status &= ~CHAN_JUPED;
  1083. dcc[servidx].timeval = now;
  1084. dcc[servidx].sock = -1;
  1085. dcc[servidx].u.dns->host = get_data_ptr(strlen(dcc[servidx].host) + 1);
  1086. strcpy(dcc[servidx].u.dns->host, dcc[servidx].host);
  1087. dcc[servidx].u.dns->cbuf = get_data_ptr(strlen(pass) + 1);
  1088. strcpy(dcc[servidx].u.dns->cbuf, pass);
  1089. dcc[servidx].u.dns->dns_success = server_resolve_success;
  1090. dcc[servidx].u.dns->dns_failure = server_resolve_failure;
  1091. dcc[servidx].u.dns->dns_type = RES_IPBYHOST;
  1092. dcc[servidx].u.dns->type = &SERVER_SOCKET;
  1093. if (server_cycle_wait)
  1094. /* Back to 1st server & set wait time.
  1095. * Note: Put it here, just in case the server quits on us quickly
  1096. */
  1097. cycle_time = server_cycle_wait;
  1098. else
  1099. cycle_time = 0;
  1100. /* I'm resolving... don't start another server connect request */
  1101. resolvserv = 1;
  1102. /* Resolve the hostname. */
  1103. #ifdef USE_IPV6
  1104. server_resolve_success(servidx);
  1105. #else
  1106. dcc_dnsipbyhost(dcc[servidx].host);
  1107. #endif /* USE_IPV6 */
  1108. }
  1109. }
  1110. static void server_resolve_failure(int servidx)
  1111. {
  1112. serv = -1;
  1113. resolvserv = 0;
  1114. putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[servidx].host,
  1115. IRC_DNSFAILED);
  1116. lostdcc(servidx);
  1117. }
  1118. static void server_resolve_success(int servidx)
  1119. {
  1120. int oldserv = dcc[servidx].u.dns->ibuf;
  1121. #ifdef S_NODELAY
  1122. int i = 0;
  1123. #endif
  1124. char s[121], pass[121];
  1125. resolvserv = 0;
  1126. dcc[servidx].addr = dcc[servidx].u.dns->ip;
  1127. strcpy(pass, dcc[servidx].u.dns->cbuf);
  1128. changeover_dcc(servidx, &SERVER_SOCKET, 0);
  1129. #ifdef USE_IPV6
  1130. serv = open_telnet(dcc[servidx].host, dcc[servidx].port);
  1131. #else
  1132. serv = open_telnet(iptostr(htonl(dcc[servidx].addr)), dcc[servidx].port);
  1133. #endif /* USE_IPV6 */
  1134. if (serv < 0) {
  1135. neterror(s);
  1136. putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[servidx].host,
  1137. s);
  1138. lostdcc(servidx);
  1139. if (oldserv == curserv && !never_give_up)
  1140. fatal("NO SERVERS WILL ACCEPT MY CONNECTION.", 0);
  1141. } else {
  1142. dcc[servidx].sock = serv;
  1143. #ifdef HAVE_SSL
  1144. if (!ssl_link(dcc[servidx].sock, CONNECT_SSL)) {
  1145. dcc[servidx].ssl = 0;
  1146. putlog(LOG_SERV, "*", "SSL for '%s' failed", dcc[servidx].host);
  1147. } else {
  1148. putlog(LOG_SERV, "*", "SSL for '%s' successful", dcc[servidx].host);
  1149. dcc[servidx].ssl = 1;
  1150. }
  1151. #else
  1152. dcc[servidx].ssl = 0;
  1153. #endif /* HAVE_SSL */
  1154. #ifdef S_NODELAY
  1155. i = 1;
  1156. setsockopt(serv, 6, TCP_NODELAY, &i, sizeof(i));
  1157. #endif /* S_NODELAY */
  1158. /* Queue standard login */
  1159. dcc[servidx].timeval = now;
  1160. SERVER_SOCKET.timeout_val = &server_timeout;
  1161. /* Another server may have truncated it, so use the original */
  1162. strcpy(botname, origbotname);
  1163. /* Start alternate nicks from the beginning */
  1164. altnick_char = 0;
  1165. if (pass[0])
  1166. dprintf(DP_MODE, "PASS %s\n", pass);
  1167. dprintf(DP_MODE, "NICK %s\n", botname);
  1168. dprintf(DP_MODE, "USER %s . . :%s\n", botuser, botrealname);
  1169. /* Wait for async result now */
  1170. }
  1171. }
  1172. #endif /* LEAF */