示例#1
0
static int script_newsomething(void *type, char *chan_name, char *mask, char *creator, char *comment, char *lifetime, char *options)
{
	time_t expire_time;
	struct chanset_t *chan = NULL;
	int sticky = 0;
	int r;
	module_entry *me;

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

	if (lifetime) {
		expire_time = atoi(lifetime);
		if (expire_time) expire_time = expire_time * 60 + now;
	}
	expire_time = now + (60 * (((int) type == 'b') ?
			    ((chan->ban_time == 0) ? 0L : chan->ban_time) :
			    (((int) type == 'e') ? ((chan->exempt_time == 0) ?
			    0L : chan->exempt_time) :
			    ((chan->invite_time == 0) ?
			    0L : chan->invite_time))));

	if (options && !strcasecmp(options, "sticky")) sticky = 1;

	r = u_addmask((int) type, chan, mask, creator, comment, expire_time, sticky);
	if (chan && !r) return(-1);

	if ((int) type == 'b') {
		me = module_find("irc", 0, 0);
		if (me) {
			if (chan) (me->funcs[IRC_CHECK_THIS_BAN])(chan, mask, sticky);
			else for (chan = chanset; chan; chan = chan->next) {
				(me->funcs[IRC_CHECK_THIS_BAN])(chan, mask, sticky);
			}
		}
		return(0);
	}

	if (chan) add_mode(chan, '+', (int) type, mask);
	else {
		for (chan = chanset; chan; chan = chan->next) {
			add_mode(chan, '+', (int) type, mask);
		}
	}
	return(0);
}
示例#2
0
文件: cmdschan.c 项目: kirune/wraith
static void cmd_pls_mask(const char type, int idx, char *par)
{
  const char *cmd = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");

  if (!par[0]) {
usage:
    dprintf(idx, "Usage: +%s <hostmask> [channel] [%%<XdXhXm>] [reason]\n", cmd);
    return;
  }

  char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
  unsigned long int expire_time = 0, expire_foo;
  int sticky = 0;
  struct chanset_t *chan = NULL;

  who = newsplit(&par);
  if (par[0] && strchr(CHANMETA, par[0]))
    chname = newsplit(&par);

  /* Did they mix up the two params? */
  if (!chname && strchr(CHANMETA, who[0])) {
    if (par[0]) {
      chname = who;
      who = newsplit(&par);
    } else {
      goto usage;
    }
  }

  if (chname || !(dcc[idx].user->flags & USER_MASTER)) {
    if (!chname)
      chname = dcc[idx].u.chat->con_chan;
    get_user_flagrec(dcc[idx].user, &user, chname);
    chan = findchan_by_dname(chname);
    /* *shrug* ??? (guppy:10Feb1999) */
    if (!chan || (chan && privchan(user, chan, PRIV_OP))) {
      dprintf(idx, "No such channel.\n");
      return;
    } else if (!chk_op(user, chan)) {
      dprintf(idx, "You don't have access to set %ss on %s.\n", cmd, chname);
      return;
    }
  } else
    chan = 0;
  /* Added by Q and Solal -- Requested by Arty2, special thanx :) */
  if (par[0] == '%') {
    p = newsplit(&par);
    p_expire = p + 1;
    while (*(++p) != 0) {
      switch (tolower(*p)) {
	case 'd':
	  *p = 0;
	  expire_foo = strtol(p_expire, NULL, 10);
	  if (expire_foo > 365)
	    expire_foo = 365;
	  expire_time += 86400 * expire_foo;
	  p_expire = p + 1;
	  break;
	case 'h':
	  *p = 0;
	  expire_foo = strtol(p_expire, NULL, 10);
	  if (expire_foo > 8760)
	    expire_foo = 8760;
	  expire_time += 3600 * expire_foo;
	  p_expire = p + 1;
	  break;
	case 'm':
	  *p = 0;
	  expire_foo = strtol(p_expire, NULL, 10);
	  if (expire_foo > 525600)
	    expire_foo = 525600;
	  expire_time += 60 * expire_foo;
	  p_expire = p + 1;
	}
    }
  }
  if (!par[0])
    par = "requested";
  else if (strlen(par) > MASKREASON_MAX)
    par[MASKREASON_MAX] = 0;
  if (strlen(who) > UHOSTMAX - 4)
    who[UHOSTMAX - 4] = 0;
  /* Fix missing ! or @ BEFORE checking against myself */
  if (!strchr(who, '!')) {
    if (!strchr(who, '@'))
      simple_snprintf(s, sizeof s, "%s!*@*", who);	/* Lame nick ban */
    else
      simple_snprintf(s, sizeof s, "*!%s", who);
  } else if (!strchr(who, '@'))
    simple_snprintf(s, sizeof s, "%s@*", who);	/* brain-dead? */
  else
    strlcpy(s, who, sizeof s);
    if (conf.bot->hub)
      simple_snprintf(s1, sizeof s1, "%s!%s@%s", origbotname, botuser, conf.bot->net.host);
    else
      simple_snprintf(s1, sizeof s1, "%s!%s", botname, botuserhost);
  if (type == 'b' && s1[0] && wild_match(s, s1)) {
    dprintf(idx, "I'm not going to ban myself.\n");
    putlog(LOG_CMDS, "*", "#%s# attempted +ban %s", dcc[idx].nick, s);
    return;
  }
  /* IRC can't understand bans longer than 70 characters */
  if (strlen(s) > 70) {
    s[69] = '*';
    s[70] = 0;
  }
  if (chan) {
    u_addmask(type, chan, s, dcc[idx].nick, par, expire_time ? now + expire_time : 0, 0);
    if (par[0] == '*') {
      sticky = 1;
      par++;
      putlog(LOG_CMDS, "*", "#%s# (%s) +%s %s %s (%s) (sticky)", dcc[idx].nick, dcc[idx].u.chat->con_chan, cmd, s, chan->dname, par);
      dprintf(idx, "New %s sticky %s: %s (%s)\n", chan->dname, cmd, s, par);
    } else {
      putlog(LOG_CMDS, "*", "#%s# (%s) +%s %s %s (%s)", dcc[idx].nick, dcc[idx].u.chat->con_chan, cmd, s, chan->dname, par);
      dprintf(idx, "New %s %s: %s (%s)\n", chan->dname, cmd, s, par);
    }
    if (!conf.bot->hub) {
      if (type == 'e' || type == 'I')
        add_mode(chan, '+', type, s);
      /* Avoid unnesessary modes if you got +dynamicbans
       */
      else
        check_this_ban(chan, s, sticky);
    } else
      write_userfile(idx);
  } else {
    u_addmask(type, NULL, s, dcc[idx].nick, par, expire_time ? now + expire_time : 0, 0);
    if (par[0] == '*') {
      sticky = 1;
      par++;
      putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +%s %s (%s) (sticky)", dcc[idx].nick, cmd, s, par);
      dprintf(idx, "New sticky %s: %s (%s)\n", cmd, s, par);
    } else {
      putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +%s %s (%s)", dcc[idx].nick, cmd, s, par);
      dprintf(idx, "New %s: %s (%s)\n", cmd, s, par);
    }
    if (!conf.bot->hub) {
      for (chan = chanset; chan != NULL; chan = chan->next) {
        if (type == 'b')
          check_this_ban(chan, s, sticky);
        else
          add_mode(chan, '+', type, s);
      }
    } else
      write_userfile(idx);
  }
}