Example #1
0
/* Stick a ban/exempt/invite globally or to a chanel. */
static int script_sticksomething(void *type, char *chan_name, char *mask)
{
	struct chanset_t *chan = NULL;

	if (chan_name && chan_name[0]) {
		chan = findchan_by_dname(chan_name);
		if (!chan) return(-1);
	}

	/* If type > 255, then we're unsticking. The mask type is type & 255. */
	return u_setsticky_mask((int)type & 255, chan, mask, ((int)type > 255) ? 0 : 1);
}
Example #2
0
static void cmd_stick_yn(int idx, char *par, int yn)
{
  int i = 0, j;
  struct chanset_t *chan = NULL;
  char *stick_type = NULL, s[UHOSTLEN] = "", chname[81] = "", type = 0, *str_type = NULL;
  maskrec *channel_list = NULL;

  stick_type = newsplit(&par);
  strlcpy(s, newsplit(&par), sizeof s);
  strlcpy(chname, newsplit(&par), sizeof chname);
  if (strcasecmp(stick_type, "exempt") &&
      strcasecmp(stick_type, "invite") &&
      strcasecmp(stick_type, "ban")) {
    strlcpy(chname, s, sizeof chname);
    strlcpy(s, stick_type, sizeof s);
    stick_type = "ban";
  }
  if (!s[0]) {
    dprintf(idx, "Usage: %sstick [ban/exempt/invite] <hostmask or number> [channel]\n", yn ? "" : "un");
    return;
  }
  /* Now deal with exemptions */
  if (!strcasecmp(stick_type, "exempt")) {
    type = 'e';
    str_type = "exempt";
  } else if (!strcasecmp(stick_type, "invite")) {
    type = 'I';
    str_type = "invite";
  } else if (!strcasecmp(stick_type, "ban")) {
    type = 'b';
    str_type = "ban";
  } else
    return;

  if (!chname[0]) {
    channel_list = (type == 'b' ? global_bans : type == 'e' ? global_exempts : global_invites);

    i = u_setsticky_mask(NULL, channel_list, s, (dcc[idx].user->flags & USER_MASTER) ? yn : -1, type);
    if (i > 0) {
      putlog(LOG_CMDS, "*", "#%s# %sstick %s %s", dcc[idx].nick, yn ? "" : "un", str_type, s);
      dprintf(idx, "%stuck %s: %s\n", yn ? "S" : "Uns", str_type, s);

      if (!conf.bot->hub) {
        struct chanset_t *achan = NULL;

        for (achan = chanset; achan != NULL; achan = achan->next)
          check_this_mask(type, achan, s, yn);
      } else
        write_userfile(idx);

      return;
    }
    strlcpy(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  }
  /* Channel-specific mask? */
  if (!(chan = findchan_by_dname(chname))) {
    dprintf(idx, "No such channel.\n");
    return;
  }
  get_user_flagrec(dcc[idx].user, &user, chan->dname);
  if (privchan(user, chan, PRIV_OP)) {
    dprintf(idx, "No such channel.\n");
    return;
  }

  channel_list = (type == 'b' ? chan->bans : type == 'e' ? chan->exempts : chan->invites);

  if (str_isdigit(s)) {
    /* substract the numer of global masks to get the number of the channel masks */
    j = atoi(s);
    j -= count_mask(type == 'b' ? global_bans : type == 'e' ? global_exempts : global_invites);
    simple_snprintf(s, sizeof s, "%d", j);
  }

  j = u_setsticky_mask(chan, channel_list, s, yn, type);
  if (j > 0) {
    putlog(LOG_CMDS, "*", "#%s# %sstick %s %s %s", dcc[idx].nick, yn ? "" : "un", str_type, s, chname);
    dprintf(idx, "%stuck %s %s: %s\n", yn ? "S" : "Uns", chname, str_type, s);
    if (!conf.bot->hub)
      check_this_mask(type, chan, s, yn);
    else
      write_userfile(idx);

    return;
  }
  dprintf(idx, "No such %s.\n", str_type);
}