Esempio n. 1
0
File: ctcp.c Progetto: vap0r/wraith
static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
{

  if (!ischanhub()) 
    return BIND_RET_LOG;

    if (u_pass_match(u, "-")) {
      strlcat(ctcp_reply, "\001ERROR no password set\001", sizeof(ctcp_reply));
      return BIND_RET_BREAK;
    }

    int ix = -1, i = 0;

    for (i = 0; i < dcc_total; i++) {
      if (dcc[i].type && (dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)")))
        ix = i;
    }
    if (!iptolong(getmyip())) {
      simple_snprintf(&ctcp_reply[strlen(ctcp_reply)], sizeof(ctcp_reply) - strlen(ctcp_reply), "\001ERROR no ipv4 ip defined. Use /dcc chat %s\001", botname);
    } else if (dcc_total == max_dcc || (ix < 0 && (ix = listen_all(0, 0, 0)) < 0))
      strlcat(ctcp_reply, "\001ERROR no telnet port\001", sizeof(ctcp_reply));
    else {
      if (listen_time <= 2)
        listen_time++;
      /* do me a favour and don't change this back to a CTCP reply,
       * CTCP replies are NOTICE's this has to be a PRIVMSG
       * -poptix 5/1/1997 */
      bd::String msg;
      msg = bd::String::printf("\001DCC CHAT chat %lu %u\001", iptolong(getmyip()), dcc[ix].port);
      privmsg(nick, msg.c_str(), DP_SERVER);
    }
    return BIND_RET_BREAK;
}
Esempio n. 2
0
void rehash_ip() {
  /* cache our ip on load instead of every 30 seconds */
  char *ip4 = NULL, *ip6 = NULL;

  if (cached_ip) {
    ip4 = strdup(myipstr(AF_INET));
    ip6 = strdup(myipstr(AF_INET6));
  }

  cache_my_ip();
  sdprintf("ip4: %s", myipstr(AF_INET));
  sdprintf("ip6: %s", myipstr(AF_INET6));

  /* Check if our ip changed during a rehash */
  if (ip4) {
    if (strcmp(ip4, myipstr(AF_INET)) || strcmp(ip6, myipstr(AF_INET6))) {
      if (tands > 0) {
        botnet_send_chat(-1, conf.bot->nick, "IP changed.");
        botnet_send_bye("IP changed.");
      }
      fatal("brb", 1);
    }

    free(ip4);
    free(ip6);
  }

  if (conf.bot->hub) {
    struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, conf.bot->u);
    listen_all(bi->telnet_port, 0, 1);
    my_port = bi->telnet_port;
  } else if (conf.bot->localhub) {
    // If not listening on the domain socket, open it up
    bool listening = 0;
    for (int i = 0; i < dcc_total; i++) {
      if (dcc[i].type && (dcc[i].type == &DCC_TELNET) && (!strcmp(dcc[i].host, conf.localhub_socket)) && (!strcmp(dcc[i].nick, "(unix_domain"))) {
        listening = 1;
        break;
      }
    }
    if (!listening) {
      // Listen on the unix domain socket
      port_t port;
      int i = open_listen_addr_by_af(conf.localhub_socket, &port, AF_UNIX);
      if (i < 0) {
        putlog(LOG_ERRORS, "*", "Can't listen on %s - %s", conf.localhub_socket, i == -1 ? "it's taken." : "couldn't assign file.");
      } else {
        /* now setup dcc entry */
        int idx = new_dcc(&DCC_TELNET, 0);
        dcc[idx].addr = 0L;
        strlcpy(dcc[idx].host, conf.localhub_socket, sizeof(dcc[idx].host));
        dcc[idx].port = 0;
        dcc[idx].sock = i;
        dcc[idx].timeval = now;
        strlcpy(dcc[idx].nick, "(unix_domain)", sizeof(dcc[idx].nick));
        putlog(LOG_DEBUG, "*", "Listening on telnet %s", conf.localhub_socket);
      }
    }
  }
}
Esempio n. 3
0
File: ctcp.c Progetto: vap0r/wraith
static void ctcp_minutely()
{
  if (irc_autoaway && server_online) {
    if ((cloak_awaytime == 0) && (cloak_heretime == 0)) {
      cloak_heretime = now;
      dprintf(DP_HELP, "AWAY :\n");
      return;
    }

    if (cloak_awaytime == 0) {
      if (!randint(AVGHERETIME)) {
        cloak_heretime = 0;
        cloak_awaytime = now - 600 - randint(60);
        sendaway();
      }
    } else {
      if (!randint(AVGAWAYTIME)) {
        cloak_awaytime = 0;
        cloak_heretime = now;
        dprintf(DP_HELP, "AWAY :\n");
      } else
        sendaway();
    }
  }

  if (listen_time <= 0) {
    for (int i = 0; i < dcc_total; i++) {
      if (dcc[i].type && (dcc[i].type->flags & DCT_LISTEN) && !strcmp(dcc[i].nick, "(telnet)"))
        listen_all(0, 1, 0);
    }
  } else
    listen_time--;
}