Пример #1
0
void check_ctcp_ban_flood(char *channel, char *nick)
{
NickList *Nick = NULL;
ChannelList *chan = NULL;
	for (chan = get_server_channels(from_server); chan; chan = chan->next)
		if ((Nick = find_nicklist_in_channellist(nick, chan, 0)))
			break;
	if (chan && chan->have_op && get_cset_int_var(chan->csets, CTCP_FLOOD_BAN_CSET) && Nick)
	{
		if (!Nick->userlist || (Nick->userlist && !(Nick->userlist->flags & ADD_FLOOD)))
		{
			if (!nick_isop(Nick) || get_cset_int_var(chan->csets, KICK_OPS_CSET))
			{
				char *ban, *u, *h;
				u = alloca(strlen(Nick->host)+1);
				strcpy(u, Nick->host);
				h = strchr(u, '@');
				*h++ = 0;
				ban = ban_it(Nick->nick, u, h, Nick->ip);
				if (!ban_is_on_channel(ban, chan) && !eban_is_on_channel(ban, chan))
					send_to_server("MODE %s +b %s", chan->channel, ban);
			}
		}
	}
}
Пример #2
0
int real_check_auto (void *arg, char *sub)
{
	char *nick, *host, *channel;
	char *p = (char *)arg;
	char *args = (char *)arg;
	char *serv_num = NULL;
	int  this_server = from_server;	

	
	
	channel = next_arg(args, &args);
	nick = next_arg(args, &args);
	host = next_arg(args, &args);
	if ((serv_num = next_arg(args, &args)))
		from_server = my_atol(serv_num);
	
	if (channel && *channel && nick && *nick && host && *host)
	{
		ChannelList *chan;
		if ((chan = lookup_channel(channel, from_server, CHAN_NOUNLINK)))
			check_auto(channel, find_nicklist_in_channellist(nick, chan, 0), NULL);
	}
	this_server = from_server;
	new_free(&p);
	return 0;
}
Пример #3
0
void check_auto_invite(char *nick, char *userhost)
{
#ifdef WANT_USERLIST
ChannelList *chan = NULL;
UserList *tmp = NULL;
	for (chan = get_server_channels(from_server); chan; chan = chan->next)
	{
		if ((tmp = lookup_userlevelc("*", userhost, chan->channel, NULL)))
		{
			NickList *n = NULL;
			n = find_nicklist_in_channellist(nick, chan, 0);
			if (!n && chan->have_op && get_cset_int_var(chan->csets, AINV_CSET) && (tmp->flags & ADD_INVITE) && get_cset_int_var(chan->csets, AINV_CSET))
			{
				bitchsay("Auto-inviting %s to %s", nick, chan->channel);
				send_to_server("NOTICE %s :Auto-invite from %s", nick, get_server_nickname(from_server));
				send_to_server("INVITE %s %s%s%s", nick, chan->channel, chan->key?space:empty_string, chan->key?chan->key:empty_string);
			}
		}
		tmp = NULL;
	}
#endif
}
Пример #4
0
void parse_notice(char *from, char **Args)
{
	int	type;
	char	*to,
		*high = empty_string,
		*target,
		*line;

	NickList *nick = NULL;	
	ChannelList *tmpc = NULL;
	char *newline = NULL;

		
	PasteArgs(Args, 1);
	to = Args[0];
	line = Args[1];
	if (!to || !line)
		return;
	if (!*to)
	{
		put_it("*** obsolete notice recieved. [%s]", line+1);
		return;
	}

	if (!from || !*from || !strcmp(get_server_itsname(from_server), from))
	{
		parse_server_notice(from, line);
		return;
	}


	
	if (is_channel(to))
	{
		target = to;
		type = PUBLIC_NOTICE_LIST;
		if ((tmpc = lookup_channel(to, from_server, CHAN_NOUNLINK)))
			nick = find_nicklist_in_channellist(from, tmpc, 0);
	}
	else
	{
		target = from;
		type = NOTICE_LIST;
	}

	update_stats(NOTICELIST, to, nick, tmpc, 0);		

	set_display_target(target, LOG_NOTICE);
	doing_notice = 1;

	if ((check_ignore_notice(from, to, IGNORE_NOTICES, line, &high) == IGNORED))
		goto notice_cleanup;

	if (!check_flooding(from, NOTICE_FLOOD, line, NULL))
		goto notice_cleanup;

	if (!strchr(from, '.'))
	{
		notify_mark(from, FromUserHost, 1, 0);
		line = do_notice_ctcp(from, to, line);
		if (!*line)
			goto notice_cleanup;
	}
		
	if (sed && !do_hook(ENCRYPTED_NOTICE_LIST, "%s %s %s", from, to, line))
	{
#if 0
		put_it("%s", convert_output_format(fget_string_var(FORMAT_ENCRYPTED_NOTICE_FSET), "%s %s %s %s", update_clock(GET_TIME), from, FromUserHost, line));
#endif
		sed = 0;
		goto notice_cleanup;
	}

	
	{
		char *free_me = NULL;
		char *s;
		free_me = newline = stripansi(line);
		if (wild_match("[*Wall*", line))
		{
			char *channel = NULL, *p, *q;
			q = p = next_arg(newline, &newline);
			if ((p = strchr(p, '/')))
			{
				p++;
				if (*p && *p == '\002')
					p++;
				channel = m_strdup(p);
				if ((p = strchr(channel, ']')))
					*p++ = 0;
				q = channel;
				if (*q && q[strlen(q)-1] == '\002')
					q[strlen(q)-1] = 0;
			} 
			if (channel && *channel)
				set_display_target(channel, LOG_WALL);
			else
				set_display_target(target, LOG_WALL);
			if (do_hook(type, "%s %s", from, line))
			{
				s = convert_output_format(fget_string_var(FORMAT_BWALL_FSET), "%s %s %s %s %s", update_clock(GET_TIME), q, from, FromUserHost, newline);
				if (tmpc)
					add_to_log(tmpc->msglog_fp, now, s, logfile_line_mangler);
				put_it("%s", s);
			}
			add_last_type(&last_wall[0], 1, from, FromUserHost, NULL, line);
			logmsg(LOG_WALL, from, 0, "%s", line);
/*			addtabkey(from, "wall", 0);*/
			new_free(&channel);
		}
		else
		{
			if (type == PUBLIC_NOTICE_LIST)
			{
				s = convert_output_format(fget_string_var(check_auto_reply(line)?FORMAT_PUBLIC_NOTICE_AR_FSET:FORMAT_PUBLIC_NOTICE_FSET), "%s %s %s %s %s", update_clock(GET_TIME), from, FromUserHost, to, newline);
				if (do_hook(type, "%s %s %s", from, to, line))
					put_it("%s", s);
			}
			else
			{
				s = convert_output_format(fget_string_var(FORMAT_NOTICE_FSET), "%s %s %s %s", update_clock(GET_TIME), from, FromUserHost, newline);
				if (do_hook(type, "%s %s", from, line))
					put_it("%s", s);

			}
			if (tmpc)
				add_to_log(tmpc->msglog_fp, now, s, logfile_line_mangler);
			logmsg(LOG_NOTICE, from, 0, "%s", line);
			add_last_type(&last_notice[0], MAX_LAST_MSG, from, FromUserHost, to, line);
		}
		new_free(&free_me);
	}

 notice_cleanup:
	if (beep_on_level & LOG_NOTICE)
		beep_em(1);
	reset_display_target();
	doing_notice = 0;
}
Пример #5
0
int BX_flood_prot (char *nick, char *userhost, char *type, int ctcp_type, int ignoretime, char *channel)
{
ChannelList *chan;
NickList *Nick;
char tmp[BIG_BUFFER_SIZE+1];
char *uh;
int	old_window_display;
int	kick_on_flood = 1;

	if ((ctcp_type == CDCC_FLOOD || ctcp_type == CTCP_FLOOD || ctcp_type == CTCP_ACTION_FLOOD) && !get_int_var(CTCP_FLOOD_PROTECTION_VAR))
		return 0;
	else if (!get_int_var(FLOOD_PROTECTION_VAR))
		return 0;
	else if (!my_stricmp(nick, get_server_nickname(from_server)))
		return 0;
	switch (ctcp_type)
	{
		case WALL_FLOOD:
		case MSG_FLOOD:
			break;
		case NOTICE_FLOOD:
			break;
		case PUBLIC_FLOOD:
			if (channel)
			{
				if ((chan = lookup_channel(channel, from_server, 0)))
				{
					kick_on_flood = get_cset_int_var(chan->csets, PUBFLOOD_CSET);
					if (kick_on_flood && (Nick = find_nicklist_in_channellist(nick, chan, 0)))
					{
						if (chan->have_op && (!Nick->userlist || (Nick->userlist && !(Nick->userlist->flags & ADD_FLOOD))))
							if (!nick_isop(Nick) || get_cset_int_var(chan->csets, KICK_OPS_CSET))
								send_to_server("KICK %s %s :\002%s\002 flooder", chan->channel, nick, type);
					} 
				}
			}
			break;
		case CTCP_FLOOD:
		case CTCP_ACTION_FLOOD:
			check_ctcp_ban_flood(channel, nick);
		default:
			if (get_int_var(FLOOD_KICK_VAR) && kick_on_flood && channel)
			{
				for (chan = get_server_channels(from_server); chan; chan = chan->next)
				{
					if (chan->have_op && (Nick = find_nicklist_in_channellist(nick, chan, 0)))
					{
						if ((!Nick->userlist || (Nick->userlist && !(Nick->userlist->flags & ADD_FLOOD))))
							if (!nick_isop(Nick) || get_cset_int_var(chan->csets, KICK_OPS_CSET))
								send_to_server("KICK %s %s :\002%s\002 flooder", chan->channel, nick, type);
					}
				}
			}
	}
	if (!ignoretime)
		return 0;
	uh = clear_server_flags(userhost);
	sprintf(tmp, "*!*%s", uh);
	old_window_display = window_display;
	window_display = 0;
	ignore_nickname(tmp, ignore_type(type, strlen(type)), 0);
	window_display = old_window_display;
	sprintf(tmp, "%d ^IGNORE *!*%s NONE", ignoretime, uh);
	timercmd("TIMER", tmp, NULL, NULL);
	bitchsay("Auto-ignoring %s for %d minutes [\002%s\002 flood]", nick, ignoretime/60, type);
	return 1;
}
Пример #6
0
void userhost_ban(UserhostItem *stuff, char *nick1, char *args)
{
	char *temp;
	char *str= NULL;
	char *channel;
	ChannelList *c = NULL;
	NickList *n = NULL;

	char *ob = "-o+b";
	char *b = "+b";

	char *host = NULL, *nick = NULL, *user = NULL, *chan = NULL;
	WhowasList *whowas = NULL;
		
	int f**k = 0;
	int set_ignore = 0;
	
	
	channel = next_arg(args, &args);
	temp = next_arg(args, &args);

	f**k = !my_stricmp("F**K", args);
	set_ignore = !my_stricmp("BKI", args);
	
	if (!stuff || !stuff->nick || !nick1 || !strcmp(stuff->user, "<UNKNOWN>") || my_stricmp(stuff->nick, nick1))
	{
		if (nick1 && channel && (whowas = check_whowas_nick_buffer(nick1, channel, 0)))
		{
			nick = whowas->nicklist->nick;
			user = m_strdup(clear_server_flags(whowas->nicklist->host));
			host = strchr(user, '@');
			*host++ = 0;
			bitchsay("Using WhoWas info for ban of %s ", nick1);
			n = whowas->nicklist;
		}
		else if (nick1)
		{
			bitchsay("No match for the %s of %s on %s", f**k ? "F**k":"Ban", nick1, channel);
			return;
		}
	} 
	else
	{
		nick = stuff->nick;
		user = m_strdup(clear_server_flags(stuff->user));
		host = stuff->host;
	}

	if (!(my_stricmp(nick, get_server_nickname(from_server))))
	{
		bitchsay("Try to kick yourself again!!");
		new_free(&user);
		return;
	}

	if (is_on_channel(channel, from_server, nick))
		chan = channel;
	c = lookup_channel(channel, from_server, 0);
	if (c && !n)
		n = find_nicklist_in_channellist(nick, c, 0);
	send_to_server("MODE %s %s %s %s", channel, chan ? ob : b, chan?nick:empty_string, ban_it(nick, user, host, (n && n->ip)?n->ip:NULL));
	if (f**k)
	{
		malloc_sprintf(&str, "%s!*%s@%s %s 3 Auto-Shit", nick, user, host, channel);
#ifdef WANT_USERLIST
		add_shit(NULL, str, NULL, NULL);
#endif
		new_free(&str);
	} else if (set_ignore)
		ignore_nickname(ban_it("*", user, host, NULL)	, IGNORE_ALL, 0);
	new_free(&user);
}
Пример #7
0
void userhost_unban(UserhostItem *stuff, char *nick1, char *args)
{
char *tmp;
ChannelList *chan;
char *channel = NULL;
BanList *bans;

char *host = NULL;
char *ip_str = NULL;
WhowasList *whowas = NULL;
NickList *n = NULL;
int count = 0;
int old_server = from_server;

	
	if (!stuff || !stuff->nick || !nick1 || 
		!strcmp(stuff->user, "<UNKNOWN>") || 
		my_stricmp(stuff->nick, nick1))
	{
		if (nick1 && (whowas = check_whowas_nick_buffer(nick1, args, 0)))
		{
			malloc_sprintf(&host, "%s!%s", whowas->nicklist->nick, whowas->nicklist->host);
			bitchsay("Using WhoWas info for unban of %s ", nick1);
			n = whowas->nicklist;
		}
		else if (nick1)
		{
			bitchsay("No match for the unban of %s on %s", nick1, args);
			return;
		}
		if (!nick1)
			return;
	}
	else
	{
		tmp = clear_server_flags(stuff->user);
		malloc_sprintf(&host, "%s!%s@%s",stuff->nick, tmp, stuff->host); 
	}

	channel = next_arg(args, &args);
	if (args && *args)
		from_server = atoi(args);
	if (!(chan = prepare_command(&from_server, channel, NEED_OP)))
	{
		new_free(&host);
		return;
	}
	if (!n)
		n = find_nicklist_in_channellist(stuff->nick, chan, 0);

	if (n && n->ip)
	{
		size_t len = strlen(n->nick)+strlen(n->host)+strlen(n->ip)+10;
		ip_str = alloca(len); 
		*ip_str = 0;
		strmopencat(ip_str, len, stuff->nick, "!", stuff->user, "@", n->ip, NULL);
	}
	for (bans = chan->bans; bans; bans = bans->next)
	{
		if (!bans->sent_unban && (wild_match(bans->ban, host) || (ip_str && wild_match(bans->ban, ip_str))) )
		{
			add_mode(chan, "b", 0, bans->ban, NULL, get_int_var(NUM_BANMODES_VAR));
			bans->sent_unban++;
			count++;
		}			
	}	

	flush_mode_all(chan);
	if (!count)
		bitchsay("No match for Unban of %s on %s", nick1, args);
	new_free(&host);
	from_server = old_server;
}
Пример #8
0
static void p_kick(char *from, char **ArgList)
{
    char *channel, *who, *comment;
    char *chankey = NULL;
    struct channel *chan = NULL;
    struct nick_list *tmpnick = NULL;
    int t = 0;

    channel = ArgList[0];
    who = ArgList[1];
    comment = ArgList[2] ? ArgList[2] : "(no comment)";

    if ((chan = lookup_channel(channel, from_server, CHAN_NOUNLINK)))
	tmpnick = find_nicklist_in_channellist(from, chan, 0);
    message_from(channel, LOG_CRAP);
    if (channel && who && chan) {
	if (!my_stricmp(who, get_server_nickname(from_server))) {
	    Window *window = chan->window;

	    if (chan->key)
		malloc_strcpy(&chankey, chan->key);
	    if (get_int_var(AUTO_REJOIN_VAR)) {
		send_to_server(SERVER(from_server), "JOIN %s %s", channel, chankey ? chankey : empty_str);
		add_to_join_list(channel, from_server, window ? window->refnum : 0);
	    }
	    new_free(&chankey);
	    remove_channel(channel, from_server);
	    update_all_status(curr_scr_win, NULL, 0);
	    update_input(UPDATE_ALL);
	    if (do_hook(KICK_LIST, "%s %s %s %s", who, from, channel, comment ? comment : empty_str))
		put_it("%s",
		       convert_output_format(get_format(FORMAT_KICK_USER_FSET), "%s %s %s %s %s", update_clock(GET_TIME), from,
					     channel, who, comment));
	} else {
	    int itsme = 0;

	    itsme = !my_stricmp(get_server_nickname(from_server), from) ? 1 : 0;

	    if ((check_ignore(from, FromUserHost, channel, IGNORE_KICKS | IGNORE_CRAP, NULL) != IGNORED) &&
		do_hook(KICK_LIST, "%s %s %s %s", who, from, channel, comment))
		put_it("%s",
		       convert_output_format(get_format(FORMAT_KICK_FSET), "%s %s %s %s %s", update_clock(GET_TIME), from, channel,
					     who, comment));
	    if (!itsme) {
		struct nick_list *f_nick = NULL;

		f_nick = find_nicklist_in_channellist(who, chan, 0);
		if (chan->chop && tmpnick && is_other_flood(chan, tmpnick, KICK_FLOOD, &t)) {
		    if (get_int_var(KICK_ON_KICKFLOOD_VAR) > get_int_var(DEOP_ON_KICKFLOOD_VAR))
			send_to_server(SERVER(from_server), "MODE %s -o %s", chan->channel, from);
		    else if (!f_nick->kickcount++)
			send_to_server(SERVER(from_server), "KICK %s %s :\002Mass kick detected - (%d kicks in %dsec%s)\002",
				       chan->channel, from, get_int_var(KICK_ON_KICKFLOOD_VAR), t, plural(t));
		}
	    }
	    remove_from_channel(channel, who, from_server, 0, NULL);
	}

    }
    update_all_status(curr_scr_win, NULL, 0);
    message_from(NULL, LOG_CRAP);
}
Пример #9
0
static void p_privmsg(char *from, char **Args)
{
    int level, list_type, flood_type, log_type, no_flood = 1, do_beep = 1;

    unsigned char ignore_type;
    char *ptr = NULL, *to;
    char *high;
    struct channel *channel = NULL;
    struct nick_list *tmpnick = NULL;

    if (!from)
	return;
    PasteArgs(Args, 1);
    to = Args[0];
    ptr = Args[1];
    if (!to || !ptr) {
	fake();
	return;
    }
    doing_privmsg = 1;

    if (is_channel(to) && im_on_channel(to)) {
	message_from(to, LOG_MSG);
	malloc_strcpy(&public_nick, from);
	log_type = LOG_PUBLIC;
	ignore_type = IGNORE_PUBLIC;
	flood_type = PUBLIC_FLOOD;

	if (!is_on_channel(to, from_server, from))
	    list_type = PUBLIC_MSG_LIST;
	else {
	    if (is_current_channel(to, from_server, 0))
		list_type = PUBLIC_LIST;
	    else
		list_type = PUBLIC_OTHER_LIST;
	    channel = lookup_channel(to, from_server, CHAN_NOUNLINK);
	    if (channel)
		tmpnick = find_nicklist_in_channellist(from, channel, 0);
	}
    } else {
	message_from(from, LOG_MSG);
	flood_type = MSG_FLOOD;
	if (my_stricmp(to, get_server_nickname(from_server))) {
	    log_type = LOG_WALL;
	    ignore_type = IGNORE_WALLS;
	    list_type = MSG_GROUP_LIST;
	} else {
	    log_type = LOG_MSG;
	    ignore_type = IGNORE_MSGS;
	    list_type = MSG_LIST;
	}
    }
    switch (check_ignore(from, FromUserHost, to, ignore_type, ptr)) {
    case IGNORED:
	if ((list_type == MSG_LIST) && get_int_var(SEND_IGNORE_MSG_VAR))
	    send_to_server(SERVER(from_server), "NOTICE %s :%s is ignoring you", from, get_server_nickname(from_server));
	doing_privmsg = 0;
	return;
    case HIGHLIGHTED:
	high = highlight_char;
	break;
    case CHANNEL_GREP:
	high = highlight_char;
	break;
    default:
	high = empty_str;
	break;
    }

    ptr = do_ctcp(from, to, ptr);
    if (!ptr || !*ptr) {
	doing_privmsg = 0;
	return;
    }

    level = set_lastlog_msg_level(log_type);
    if (flood_type == PUBLIC_FLOOD) {
	int blah = 0;

	if (is_other_flood(channel, tmpnick, PUBLIC_FLOOD, &blah)) {
	    no_flood = 0;
	    flood_prot(tmpnick->nick, FromUserHost, "PUBLIC", flood_type, get_int_var(PUBFLOOD_TIME_VAR), channel->channel);
	}
    } else
	no_flood = check_flooding(from, flood_type, ptr, NULL);

    {
	switch (list_type) {
	case PUBLIC_MSG_LIST:
	    logmsg(LOG_PUBLIC, from, ptr, 0);
	    if (no_flood && do_hook(list_type, "%s %s %s", from, to, ptr))
		put_it("%s",
		       convert_output_format(get_format(FORMAT_PUBLIC_MSG_FSET), "%s %s %s %s %s", update_clock(GET_TIME), from,
					     FromUserHost, to, get_int_var(MIRCS_VAR) ? mircansi(ptr) : ptr));
	    break;
	case MSG_GROUP_LIST:
	    logmsg(LOG_PUBLIC, from, ptr, 0);
	    if (no_flood && do_hook(list_type, "%s %s %s", from, to, ptr))
		put_it("%s",
		       convert_output_format(get_format(FORMAT_MSG_GROUP_FSET), "%s %s %s %s", update_clock(GET_TIME), from, to,
					     get_int_var(MIRCS_VAR) ? mircansi(ptr) : ptr));
	    break;
	case MSG_LIST:
	    {
		if (!no_flood)
		    break;
		malloc_strcpy(&recv_nick, from);
		if (away_set) {
		    do_beep = 0;
		    beep_em(get_int_var(BEEP_WHEN_AWAY_VAR));
		    set_int_var(MSGCOUNT_VAR, get_int_var(MSGCOUNT_VAR) + 1);
		}
		logmsg(LOG_MSG, from, ptr, 0);
		addtabkey(from, "msg");

		if (do_hook(list_type, "%s %s", from, ptr))
		    put_it("%s",
			   convert_output_format(get_format(FORMAT_MSG_FSET), "%s %s %s %s", update_clock(GET_TIME), from,
						 FromUserHost, get_int_var(MIRCS_VAR) ? mircansi(ptr) : ptr));

		if (from_server > -1 && get_server_away(from_server) && get_int_var(SEND_AWAY_MSG_VAR)) {
		    send_to_server(SERVER(from_server), "NOTICE %s :%s", from,
				   stripansicodes(convert_output_format
						  (get_format(FORMAT_SEND_AWAY_FSET), "%l %l %s", time(NULL),
						   server_list[from_server].awaytime, get_int_var(MSGLOG_VAR) ? "On" : "Off")));
		}
		break;
	    }
	case PUBLIC_LIST:{
		logmsg(LOG_PUBLIC, from, ptr, 0);
		if (no_flood && do_hook(list_type, "%s %s %s", from, to, ptr))
		    put_it("%s",
			   convert_output_format(get_format(FORMAT_PUBLIC_FSET), "%s %s %s %s", update_clock(GET_TIME), from, to,
						 get_int_var(MIRCS_VAR) ? mircansi(ptr) : ptr));
		break;
	    }
	case PUBLIC_OTHER_LIST:{
		logmsg(LOG_PUBLIC, from, ptr, 0);
		if (no_flood && do_hook(list_type, "%s %s %s", from, to, ptr))
		    put_it("%s",
			   convert_output_format(get_format(FORMAT_PUBLIC_OTHER_FSET), "%s %s %s %s", update_clock(GET_TIME), from, to,
						 get_int_var(MIRCS_VAR) ? mircansi(ptr) : ptr));
		break;
	    }			/* case */
	}			/* switch */
    }
    if (beep_on_level & log_type && do_beep)
	beep_em(1);
    set_lastlog_msg_level(level);
    message_from(NULL, LOG_CRAP);
    doing_privmsg = 0;
}
Пример #10
0
/*
 *  Protection levels
 *  1 Reop if de-oped
 *  2 De-op offender
 *  3 Kick  offender
 *  4 KickBan offender
 */
int check_prot(char *from, char *person, ChannelList *chan, BanList *thisban, NickList *n)
{
NickList *tmp = NULL;
NickList *kicker;
char *tmp_ban = NULL;
char *nick = NULL, *userhost = NULL, *p;

	
	if (!from || !*from || !person || !*person || !chan)
		return 0;

	if (!my_stricmp(person, from))
		return 0;

	tmp_ban = LOCAL_COPY(person);
	if ((p = strchr(tmp_ban, '!')))
	{
		nick = tmp_ban;
		*p++ = 0;
		userhost  = p;
	} else nick = person;

	if (!n)
	{
		if (!(tmp = find_nicklist_in_channellist(person, chan, 0)))
		{
			for (tmp = next_nicklist(chan, NULL); tmp; tmp = next_nicklist(chan, tmp))
			{
				if (wild_match(nick, tmp->nick) && wild_match(userhost, tmp->host) && tmp->userlist)
				{
					n = tmp;
					break;
				}
			}
		}
	}

	if (get_cset_int_var(chan->csets, USERLIST_CSET) && chan->chop && ((n && n->userlist) || 
		(tmp && tmp->userlist)))
	{
		UserList *user = NULL;		
		time_t current = now;
		if (n)
			user = n->userlist;
		else
			user = tmp->userlist;
		if (!user || (user && !check_channel_match(user->channels, chan->channel)))
			return 0;
		if (!(kicker = find_nicklist_in_channellist(from, chan, 0)))
			return 0;
		if ((user->flags & (PROT_DEOP | PROT_INVITE | PROT_BAN | PROT_KICK | PROT_REOP)))
		{
			int do_reop = 0;
			if (user->flags & PROT_DEOP)
			{
				if (!kicker->sent_deop)
				{
					if (!kicker->userlist || 
						(kicker->userlist && !(kicker->userlist->flags & PROT_DEOP)))
						send_to_server("MODE %s -o %s", chan->channel, from);
					kicker->sent_deop++;
				}
				do_reop = 1;
			}

			if (user->flags & PROT_INVITE)
			{
				
				if (thisban && !thisban->sent_unban)
				{
					thisban->sent_unban++;
					thisban->sent_unban_time = current;
					send_to_server("MODE %s -b %s", chan->channel, thisban->ban);
					send_to_server("INVITE %s %s", n?n->nick:tmp->nick, chan->channel);  
				}
			}
			if (user->flags & PROT_BAN)
			{
/*				do_reop = 1; */
				if (kicker->userlist)
					send_to_server("MODE %s -o %s", chan->channel, from);
				else 
				{
					char *h, *u;
					u = LOCAL_COPY(kicker->host);
					h = strchr(u, '@');
					*h++ = 0;
					send_to_server("MODE %s -o+b %s %s", chan->channel, kicker->nick, ban_it(kicker->nick, u, h, kicker->ip));
					if (get_int_var(AUTO_UNBAN_VAR))
						add_timer(0, empty_string, get_int_var(AUTO_UNBAN_VAR) * 1000, 1, timer_unban, m_sprintf("%d %s %s", from_server, chan->channel, ban_it(kicker->nick, u, h, kicker->ip)), NULL, -1, "auto-unban");
				}
			}
			if (user->flags & PROT_KICK)
			{
				if (kicker && (!kicker->userlist || (kicker->userlist && !(kicker->userlist->flags & PROT_KICK))))
					send_to_server("KICK %s %s :\002BitchX\002 Protected User", chan->channel, kicker->nick);
			}
			if ((user->flags & PROT_REOP) || do_reop)
			{
				/* added by Sergs [email protected] */
			        if (thisban)
				{
					if (thisban->sent_unban_time - current > 30)
					{
						thisban->sent_unban++;
						thisban->sent_unban_time = current;
						send_to_server("MODE %s -b %s", chan->channel, thisban->ban);
					} 
					else if (thisban->sent_unban < 3)
					{
						thisban->sent_unban++;
						thisban->sent_unban_time = current;
						send_to_server("MODE %s -b %s", chan->channel, thisban->ban);
					}
				}
				if (n && (!n->sent_reop || (n->sent_reop_time && (current - n->sent_reop_time > 60))))
				{
					char *u = NULL;
					malloc_sprintf(&u, "%s %s %s %s %d", chan->channel, n->nick, n->host, "o", from_server);
					add_timer(0, empty_string, 10 * 1000, 1, delay_opz, u, NULL, -1, "delay-ops");
					n->sent_reop++;
					n->sent_reop_time = current;
				}
			}
		}
		if ((user->flags & USER_FLAG_PROT) && (p = get_string_var(USER_FLAG_PROT_VAR)))
			run_user_flag("USER_FLAG_PROT", p, n, kicker);
		return 1;
	}
	return 0;
}