Пример #1
0
static void got_cpart(char *botnick, char *code, char *par)
{
  if (!par[0])
   return;

  char *chname = newsplit(&par);
  struct chanset_t *chan = NULL;

  if (!(chan = findchan_by_dname(chname)))
   return;

  char *bots = newsplit(&par);
  int match = 0;

  /* if bots is '*' just remove_channel */
  if (!strcmp(bots, "*"))
    match = 0;
  else
    match = parsebots(bots, conf.bot->nick);
 
  if (match)
    do_chanset(NULL, chan, "+inactive", DO_LOCAL);
  else
    remove_channel(chan);

  if (conf.bot->hub)
    write_userfile(-1);
}
Пример #2
0
/* This will close channels if the HUB:leaf count is skewed from config setting */
static void 
check_should_close()
{
  int H = close_threshold.count, L = close_threshold.time;

  if ((H <= 0) || (L <= 0))
    return;

  int hc = 1, lc = 0;
  struct userrec *u = NULL;

  for (tand_t *bot = tandbot; bot; bot = bot->next) {
    if ((u = get_user_by_handle(userlist, bot->bot))) {
      if (bot_hublevel(u) < 999)
        hc++;
      else
        lc++;
    }
  }
  if ((hc >= H) && (lc <= L)) {
    for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
      if (!channel_closed(chan)) {
        do_chanset(NULL, chan, "+closed chanmode +stni", DO_LOCAL | DO_NET);
#ifdef G_BACKUP
        chan->channel.backup_time = now + 30;
#endif /* G_BACKUP */
      }
    }
  }
}
Пример #3
0
static void got_cset(char *botnick, char *code, char *par)
{
  if (!par || !par[0])
   return;

  bool all = 0, isdefault = 0;
  char *chname = NULL;
  struct chanset_t *chan = NULL;

  if (par[0] == '*' && par[1] == ' ') {
    all = 1;
    newsplit(&par);
   } else {
     chname = newsplit(&par);
     if (!strcasecmp(chname, "default"))
       isdefault = 1;
     else if (!strchr(CHANMETA, chname[0])) {
       putlog(LOG_ERROR, "*", "Got bad cset: bot: %s code: %s par: %s %s", botnick, code, chname, par);
       return;
     }
     if (isdefault)
       chan = chanset_default;
     else if (!(chan = findchan_by_dname(chname)))
       return;
   }

  if (all)
   chan = NULL;
  do_chanset(NULL, chan, par, DO_LOCAL);
}
Пример #4
0
static void cmd_cycle(int idx, char *par)
{
  char *chname = NULL;
  int delay = 10;
  struct chanset_t *chan = NULL;

  putlog(LOG_CMDS, "*", "#%s# cycle %s", dcc[idx].nick, par);

  if (!par[0]) {
    dprintf(idx, "Usage: cycle [%s]<channel> [delay]\n", CHANMETA);
    dprintf(idx, "rejoin delay defaults to '10'\n");
    return;
  }

  chname = newsplit(&par);
  chan = findchan_by_dname(chname);
  if (!chan) {
    dprintf(idx, "%s is not a valid channel.\n", chname);
    return;
  }
  if (par[0])
    delay = atoi(newsplit(&par));

  if (conf.bot->hub) {
    char buf2[201] = "";

    simple_snprintf(buf2, sizeof(buf2), "cycle %s %d", chname, delay); /* this just makes the bot PART */
    putallbots(buf2);
  } else {
    do_chanset(NULL, chan, "+inactive", DO_LOCAL);
    dprintf(DP_SERVER, "PART %s\n", chan->name);
    chan->channel.jointime = ((now + delay) - server_lag);
  }
  dprintf(idx, "Cycling %s for %d seconds.\n", chan->dname, delay);
}
Пример #5
0
static void pls_chan(int idx, char *par, char *bot)
{
  char *chname = NULL, result[RESULT_LEN] = "", buf[2048] = "";
  struct chanset_t *chan = NULL;

  if (!bot)
    putlog(LOG_CMDS, "*", "#%s# +chan %s", dcc[idx].nick, par);

  if (!par[0]) {
    dprintf(idx, "Usage: +chan [%s]<channel> [options]\n", CHANMETA);
    return;
  }

  chname = newsplit(&par);
  simple_snprintf(buf, sizeof(buf), "cjoin %s %s", chname, bot ? bot : "*");		/* +chan makes all bots join */
  if (par[0]) {
    strlcat(buf, " ", sizeof(buf));
    strlcat(buf, par, sizeof(buf));
    strlcat(buf, " ", sizeof(buf));
  }
    
  if (!bot && findchan_by_dname(chname)) {
    dprintf(idx, "That channel already exists!\n");
    return;
  } else if ((chan = findchan(chname)) && !bot) {
    dprintf(idx, "That channel already exists as %s!\n", chan->dname);
    return;
  } else if (strchr(CHANMETA, chname[0]) == NULL) {
    dprintf(idx, "Invalid channel prefix.\n");
    return;
  } else if (strchr(chname, ',') != NULL) {
    dprintf(idx, "Invalid channel name.\n");
    return;
  }
  if (!chan && !findchan_by_dname(chname) && channel_add(result, chname, par) == ERROR) {
    dprintf(idx, "Invalid channel or channel options.\n");
    if (result[0])
      dprintf(idx, " %s\n", result);
  } else {
    if ((chan = findchan_by_dname(chname))) {
      char tmp[51] = "";

      simple_snprintf(tmp, sizeof(tmp), "addedby %s addedts %li", dcc[idx].nick, (long) now);
      if (buf[0]) {
        strlcat(buf, " ", sizeof(buf));
        strlcat(buf, tmp, sizeof(buf));
      }
      do_chanset(NULL, chan, buf[0] ? buf : tmp, DO_LOCAL);
      if (!bot) {
        dprintf(idx, "Channel %s added to the botnet.\n", chname);
      } else {
        dprintf(idx, "Channel %s added to the bot: %s\n", chname, bot);
      }
      putallbots(buf);
    }
    if (conf.bot->hub)
      write_userfile(-1);
  }
}
Пример #6
0
void got_kl(char *botnick, char *code, char *par)
{
  killed_bots++;
  if (kill_threshold && (killed_bots == kill_threshold)) {
    for (struct chanset_t *ch = chanset; ch; ch = ch->next)
      do_chanset(NULL, ch, "+closed +bitch +backup", DO_LOCAL | DO_NET);
  /* FIXME: we should randomize nick here ... */
  }
}
Пример #7
0
static void got_cjoin(char *botnick, char *code, char *par)
{
  if (!par[0])
   return;

  char *chname = newsplit(&par), *options = NULL;
  struct chanset_t *chan = findchan_by_dname(chname);
  int match = 0;

  if (conf.bot->hub) {
    newsplit(&par);	/* hubs ignore the botmatch param */
    options = par;
  } else {
    /* ALL hubs should add the channel, leaf should check the list for a match */
    bool inactive = 0;
    char *bots = newsplit(&par);
    match = parsebots(bots, conf.bot->nick);

    if (strstr(par, "+inactive"))
      inactive = 1;

    if (chan && !match)
      return;

    if (!match) {
      size_t size = strlen(par) + 12 + 1;

      options = (char *) my_calloc(1, size);
      simple_snprintf(options, size, "%s +inactive", par);
    } else if (match && chan && !shouldjoin(chan)) {
      if (!inactive)
        do_chanset(NULL, chan, "-inactive", DO_LOCAL);
      return;
    } else
      options = par;
  }

  if (chan)
    return;
sdprintf("OPTIONS: %s", options);
  char result[RESULT_LEN] = "";

  if (channel_add(result, chname, options) == ERROR) /* drummer */
    putlog(LOG_BOTS, "@", "Invalid channel or channel options from %s for %s: %s", botnick, chname, result);
  if (conf.bot->hub)
    write_userfile(-1);
  if (!match && !conf.bot->hub)
    free(options);
}
Пример #8
0
static void got_cycle(char *botnick, char *code, char *par)
{
  if (!par[0])
   return;

  char *chname = newsplit(&par);
  struct chanset_t *chan = NULL;

  if (!(chan = findchan_by_dname(chname)))
   return;

  interval_t delay = 10;

  if (par[0])
    delay = atoi(newsplit(&par));
  
  do_chanset(NULL, chan, "+inactive", DO_LOCAL);
  dprintf(DP_SERVER, "PART %s\n", chan->name);
  chan->channel.jointime = ((now + delay) - server_lag); 		/* rejoin in 10 seconds */
}
Пример #9
0
static void cmd_chanset(int idx, char *par)
{
  char *chname = NULL, result[RESULT_LEN] = "";
  struct chanset_t *chan = NULL;
  int all = 0;

  if (!par[0]) {
    putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
    dprintf(idx, "Usage: chanset [%schannel|*|default] <settings>\n", CHANMETA);
    return;
  }

  // Determine channel name
  if (strchr(CHANMETA, par[0]) || !strncasecmp(par, "default", 7) || !strncmp(par, "*", 1))
    chname = newsplit(&par);
  else {
    if (strncmp(dcc[idx].u.chat->con_chan, "*", 1) && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
      dprintf(idx, "Invalid console channel.\n");
      return;
    }
    chname = dcc[idx].u.chat->con_chan;
  }

  if (chname && chname[0]) {
    if (!strncmp(chname, "*", 1)) {
      all = 1;
      get_user_flagrec(dcc[idx].user, &user, chanset ? chanset->dname : "");
      if (!glob_owner(user)) {
        dprintf(idx, "You need to be a global owner to use '%schanset *'.\n", (dcc[idx].u.chat->channel >= 0) ? settings.dcc_prefix : "");
        return;
      }
    } else if (!strcasecmp(chname, "default")) {
      chan = chanset_default;
    } else
      chan = findchan_by_dname(chname);
  }

  if (!all && !chan && chname && chname[0]) {
    dprintf(idx, "No such channel.\n");
    return;
  }

  if (!par[0]) {
    dprintf(idx, "Usage: chanset [%schannel|*|default] <settings>\n", CHANMETA);
    return;
  }

  if (!all) {
    get_user_flagrec(dcc[idx].user, &user, chan->dname);

    if (privchan(user, chan, PRIV_OP)) {
      dprintf(idx, "No such channel.\n");
      return;
    }

    if (!glob_master(user) && !chan_master(user)) {
      dprintf(idx, "You don't have access to %s. \n", chan->dname);
      return;
    } else if ((strstr(par, "+private") || strstr(par, "-private")) && (!glob_owner(user))) {
      dprintf(idx, "You don't have access to set +/-private on %s (halting command).\n", chan->dname);
      return;
    } else if ((strstr(par, "+backup") || strstr(par, "-backup")) && (!glob_owner(user))) {
      dprintf(idx, "You don't have access to set +/-backup on %s (halting command).\n", chan->dname);
      return;
    } else if ((strstr(par, "+inactive") || strstr(par, "-inactive")) && (!glob_owner(user))) {
      dprintf(idx, "You don't have access to set +/-inactive on %s (halting command).\n", chan->dname);
      return;
    }
  }

  putlog(LOG_CMDS, "*", "#%s# chanset (%s) %s", dcc[idx].nick, all ? "*" : chan->dname, par);
  
  if (do_chanset(result, all ? NULL : chan, par, DO_LOCAL | DO_NET | CMD) == ERROR) {
    dprintf(idx, "Error trying to set { %s } on %s: %s\n", par, all ? "all channels" : chan->dname, result);
    return;
  }

  if (all)
    dprintf(idx, "Successfully set modes { %s } on all channels (Including the default).\n", par);
  else
    dprintf(idx, "Successfully set modes { %s } on %s\n", par, chan->dname);

  if (conf.bot->hub)
    write_userfile(idx);
}