servmsg.c 33 KB

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