⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m_tkl.c

📁 Unreal irc 服务器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	{		struct irc_netmask tmp;		if ((tmp.type = parse_netmask(nl->hostmask, &tmp)) != HM_HOST)		{			nl->ptr.netmask = MyMallocEx(sizeof(struct irc_netmask));			bcopy(&tmp, nl->ptr.netmask, sizeof(struct irc_netmask));		}	}	index = tkl_hash(tkl_typetochar(type));	AddListItem(nl, tklines[index]);	return nl;}aTKline *_tkl_del_line(aTKline *tkl){	aTKline *p, *q;	int index = tkl_hash(tkl_typetochar(tkl->type));	for (p = tklines[index]; p; p = p->next)	{		if (p == tkl)		{			q = p->next;			MyFree(p->hostmask);			MyFree(p->reason);			MyFree(p->setby);			if (p->type & TKL_SPAMF && p->ptr.spamf)			{				regfree(&p->ptr.spamf->expr);				if (p->ptr.spamf->tkl_reason)					MyFree(p->ptr.spamf->tkl_reason);				MyFree(p->ptr.spamf);			}			if ((p->type & TKL_KILL || p->type & TKL_ZAP || p->type & TKL_SHUN)			     && p->ptr.netmask)				MyFree(p->ptr.netmask);			DelListItem(p, tklines[index]);			MyFree(p);			return q;		}	}	return NULL;}/* * tkl_check_local_remove_shun: * removes shun from currently connected users affected by tmp. */void _tkl_check_local_remove_shun(aTKline *tmp){long i1, i;char *chost, *cname, *cip;int  is_ip;aClient *acptr;	for (i1 = 0; i1 <= 5; i1++)	{		/* winlocal		for (i = 0; i <= (MAXCONNECTIONS - 1); i++)		*/		for (i = 0; i <= LastSlot; ++i)		{			if ((acptr = local[i]))				if (MyClient(acptr) && IsShunned(acptr))				{					chost = acptr->sockhost;					cname = acptr->user->username;						cip = GetIP(acptr);					if ((*tmp->hostmask >= '0') && (*tmp->hostmask <= '9'))						is_ip = 1;					else						is_ip = 0;					if (is_ip == 0 ?					    (!match(tmp->hostmask, chost) && !match(tmp->usermask, cname)) : 					    (!match(tmp->hostmask, chost) || !match(tmp->hostmask, cip))					    && !match(tmp->usermask, cname))					{						ClearShunned(acptr);#ifdef SHUN_NOTICES						sendto_one(acptr,						    ":%s NOTICE %s :*** You are no longer shunned",						    me.name,						    acptr->name);#endif					}				}		}	}}aTKline *_tkl_expire(aTKline * tmp){	char whattype[512];	if (!tmp)		return NULL;	whattype[0] = 0;	if ((tmp->expire_at == 0) || (tmp->expire_at > TStime()))	{		sendto_ops		    ("tkl_expire(): expire for not-yet-expired tkline %s@%s",		    tmp->usermask, tmp->hostmask);		return (tmp->next);	}	/* Using strlcpy here is wasteful, we know it is < 512 */	if (tmp->type & TKL_GLOBAL)	{		if (tmp->type & TKL_KILL)			strcpy(whattype, "G:Line");		else if (tmp->type & TKL_ZAP)			strcpy(whattype, "Global Z:Line");		else if (tmp->type & TKL_SHUN)			strcpy(whattype, "Shun");		else if (tmp->type & TKL_NICK)			strcpy(whattype, "Global Q:line");	}	else	{		if (tmp->type & TKL_KILL)			strcpy(whattype, "K:Line");		else if (tmp->type & TKL_ZAP)			strcpy(whattype, "Z:Line");		else if (tmp->type & TKL_SHUN)			strcpy(whattype, "Local Shun");		else if (tmp->type & TKL_NICK)			strcpy(whattype, "Q:line");	}	if (!(tmp->type & TKL_NICK))	{		sendto_snomask(SNO_TKL,		    "*** Expiring %s (%s@%s) made by %s (Reason: %s) set %li seconds ago",		    whattype, tmp->usermask, tmp->hostmask, tmp->setby, tmp->reason,		    TStime() - tmp->set_at);		ircd_log		    (LOG_TKL, "Expiring %s (%s@%s) made by %s (Reason: %s) set %li seconds ago",		    whattype, tmp->usermask, tmp->hostmask, tmp->setby, tmp->reason,		    TStime() - tmp->set_at);	}	else if (!(*tmp->usermask == 'H')) /* Q:line but not a hold */	{		sendto_snomask(SNO_TKL,			"*** Expiring %s (%s) made by %s (Reason: %s) set %li seconds ago",			whattype, tmp->hostmask, tmp->setby, tmp->reason, 			TStime() - tmp->set_at);		ircd_log			(LOG_TKL, "Expiring %s (%s) made by %s (Reason: %s) set %li seconds ago",			whattype, tmp->hostmask, tmp->setby, tmp->reason, TStime() - tmp->set_at);	}	if (tmp->type & TKL_SHUN)		tkl_check_local_remove_shun(tmp);	RunHook5(HOOKTYPE_TKL_DEL, NULL, NULL, tmp, 0, NULL);	return (tkl_del_line(tmp));}EVENT(_tkl_check_expire){	aTKline *gp, *next;	TS   nowtime;	int index;		nowtime = TStime();	for (index = 0; index < TKLISTLEN; index++)		for (gp = tklines[index]; gp; gp = next)		{			next = gp->next;			if (gp->expire_at <= nowtime && !(gp->expire_at == 0))			{				tkl_expire(gp);			}		}}/*	returns <0 if client exists (banned)	returns 1 if it is excepted*/int  _find_tkline_match(aClient *cptr, int xx){	aTKline *lp;	char *chost, *cname, *cip;	TS   nowtime;	char msge[1024];	int	points = 0;	ConfigItem_except *excepts;	char host[NICKLEN+USERLEN+HOSTLEN+6], host2[NICKLEN+USERLEN+HOSTLEN+6];	int match_type = 0;	int index;	Hook *tmphook;	if (IsServer(cptr) || IsMe(cptr))		return -1;	nowtime = TStime();	chost = cptr->sockhost;	cname = cptr->user ? cptr->user->username : "unknown";	cip = GetIP(cptr);	points = 0;	for (index = 0; index < TKLISTLEN; index++)	{		for (lp = tklines[index]; lp; lp = lp->next)		{			if ((lp->type & TKL_SHUN) || (lp->type & TKL_SPAMF) || (lp->type & TKL_NICK))				continue;			/* If it's tangy and brown, you're in CIDR town! */			if (lp->ptr.netmask)			{				if (match_ip(cptr->ip, NULL, NULL, lp->ptr.netmask) && 				    !match(lp->usermask, cname))				{					points = 1;					break;				}				continue;			}			if (!match(lp->usermask, cname) && !match(lp->hostmask, chost))			{				points = 1;				break;			}			if (!match(lp->usermask, cname) && !match(lp->hostmask, cip))			{				points = 1;				break;			}		}		if (points)			break;	}	if (points != 1)		return 1;	strcpy(host, make_user_host(cname, chost));	strcpy(host2, make_user_host(cname, cip));	if (((lp->type & TKL_KILL) || (lp->type & TKL_ZAP)) && !(lp->type & TKL_GLOBAL))		match_type = CONF_EXCEPT_BAN;	else		match_type = CONF_EXCEPT_TKL;	for (excepts = conf_except; excepts; excepts = (ConfigItem_except *)excepts->next) {		if (excepts->flag.type != match_type || (match_type == CONF_EXCEPT_TKL && 		    excepts->type != lp->type))			continue;		if (excepts->netmask)		{			if (match_ip(cptr->ip, host2, excepts->mask, excepts->netmask))				return 1;				} else		if (!match(excepts->mask, host) || !match(excepts->mask, host2))			return 1;			}	for (tmphook = Hooks[HOOKTYPE_TKL_EXCEPT]; tmphook; tmphook = tmphook->next)		if (tmphook->func.intfunc(cptr, lp) > 0)			return 1;		if ((lp->type & TKL_KILL) && (xx != 2))	{		if (lp->type & TKL_GLOBAL)		{			ircstp->is_ref++;			if (GLINE_ADDRESS)				sendto_one(cptr, ":%s NOTICE %s :*** You are %s from %s (%s)"					   " Email %s for more information.",					   me.name, cptr->name,					   (lp->expire_at ? "banned" : "permanently banned"),					   ircnetwork, lp->reason, GLINE_ADDRESS);			else				sendto_one(cptr, ":%s NOTICE %s :*** You are %s from %s (%s)",					   me.name, cptr->name,					   (lp->expire_at ? "banned" : "permanently banned"),					   ircnetwork, lp->reason);			ircsprintf(msge, "User has been %s from %s (%s)",				   (lp->expire_at ? "banned" : "permanently banned"),				   ircnetwork, lp->reason);			return (exit_client(cptr, cptr, &me, msge));		}		else		{			ircstp->is_ref++;			sendto_one(cptr, ":%s NOTICE %s :*** You are %s from %s (%s)"				   " Email %s for more information.",				   me.name, cptr->name,				   (lp->expire_at ? "banned" : "permanently banned"),				   me.name, lp->reason, KLINE_ADDRESS);			ircsprintf(msge, "User is %s (%s)",				   (lp->expire_at ? "banned" : "permanently banned"),				   lp->reason);			return (exit_client(cptr, cptr, &me, msge));		}	}	if (lp->type & TKL_ZAP)	{		ircstp->is_ref++;		ircsprintf(msge, "Z:lined (%s)",lp->reason);		return exit_client(cptr, cptr, &me, msge);	}	return 3;}int  _find_shun(aClient *cptr){	aTKline *lp;	char *chost, *cname, *cip;	TS   nowtime;	int	points = 0;	ConfigItem_except *excepts;	char host[NICKLEN+USERLEN+HOSTLEN+6], host2[NICKLEN+USERLEN+HOSTLEN+6];	int match_type = 0;	if (IsServer(cptr) || IsMe(cptr))		return -1;	if (IsShunned(cptr))		return 1;	if (IsAdmin(cptr))		return 1;	nowtime = TStime();	chost = cptr->sockhost;	cname = cptr->user ? cptr->user->username : "unknown";	cip = GetIP(cptr);	for (lp = tklines[tkl_hash('s')]; lp; lp = lp->next)	{		points = 0;				if (!(lp->type & TKL_SHUN))			continue;		/* CIDR */		if (lp->ptr.netmask)		{			if (match_ip(cptr->ip, NULL, NULL, lp->ptr.netmask) && 			    !match(lp->usermask, cname))			{				points = 1;				break;			}			continue;		}		if (!match(lp->usermask, cname) && !match(lp->hostmask, chost))		{			points = 1;			break;		}		if (!match(lp->usermask, cname) && !match(lp->hostmask, cip))		{			points = 1;			break;		}		else			points = 0;	}	if (points != 1)		return 1;	strcpy(host, make_user_host(cname, chost));	strcpy(host2, make_user_host(cname, cip));		match_type = CONF_EXCEPT_TKL;	for (excepts = conf_except; excepts; excepts = (ConfigItem_except *)excepts->next) {		if (excepts->flag.type != match_type || (match_type == CONF_EXCEPT_TKL && 		    excepts->type != lp->type))			continue;		if (excepts->netmask)		{			if (match_ip(cptr->ip, NULL, NULL, excepts->netmask))				return 1;				}		else if (!match(excepts->mask, host) || !match(excepts->mask, host2))			return 1;			}		SetShunned(cptr);	return 2;}char *SpamfilterMagicHost(char *i){static char buf[256];	if (!strchr(i, ':'))		return i;		/* otherwise, it's IPv6.. prepend it with [ and append a ] */	ircsprintf(buf, "[%s]", i);	return buf;}void _spamfilter_build_user_string(char *buf, char *nick, aClient *acptr){	ircsprintf(buf, "%s!%s@%s:%s",		nick, acptr->user->username, SpamfilterMagicHost(acptr->user->realhost), acptr->info);}/** Checks if the user matches a spamfilter of type 'u' (user, * nick!user@host:realname ban). * Written by: Syzop * Assumes: only call for clients, possible assume on local clients [?] * Return values: see dospamfilter() */int _find_spamfilter_user(aClient *sptr, int flags){char spamfilter_user[NICKLEN + USERLEN + HOSTLEN + REALLEN + 64]; /* n!u@h:r */	if (IsAnOper(sptr))		return 0;	spamfilter_build_user_string(spamfilter_user, sptr->name, sptr);	return dospamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, flags, NULL);}int spamfilter_check_users(aTKline *tk){char spamfilter_user[NICKLEN + USERLEN + HOSTLEN + REALLEN + 64]; /* n!u@h:r */char buf[1024];int i, matches = 0;aClient *acptr;	for (i = LastSlot; i >= 0; i--)		if ((acptr = local[i]) && MyClient(acptr))		{			spamfilter_build_user_string(spamfilter_user, acptr->name, acptr);			if (regexec(&tk->ptr.spamf->expr, spamfilter_user, 0, NULL, 0))				continue; /* No match */			/* matched! */			ircsprintf(buf, "[Spamfilter] %s!%s@%s matches filter '%s': [%s: '%s'] [%s]",				acptr->name, acptr->user->username, acptr->user->realhost,				tk->reason,				"user", spamfilter_user,				unreal_decodespace(tk->ptr.spamf->tkl_reason));			sendto_snomask(SNO_SPAMF, "%s", buf);			sendto_serv_butone_token(NULL, me.name, MSG_SENDSNO, TOK_SENDSNO, "S :%s", buf);			ircd_log(LOG_SPAMFILTER, "%s", buf);			RunHook6(HOOKTYPE_LOCAL_SPAMFILTER, acptr, spamfilter_user, spamfilter_user, SPAMF_USER, NULL, tk);			matches++;		}			return matches;}int spamfilter_check_all_users(aClient *from, aTKline *tk){char spamfilter_user[NICKLEN + USERLEN + HOSTLEN + REALLEN + 64]; /* n!u@h:r */char buf[1024];int i, matches = 0;aClient *acptr;	for (acptr = client; acptr; acptr = acptr->next)		if (IsPerson(acptr))		{			spamfilter_build_user_string(spamfilter_user, acptr->name, acptr);			if (regexec(&tk->ptr.spamf->expr, spamfilter_user, 0, NULL, 0))				continue; /* No match */			/* matched! */			sendnotice(from, "[Spamfilter] %s!%s@%s matches filter '%s': [%s: '%s'] [%s]",				acptr->name, acptr->user->username, acptr->user->realhost,				tk->reason,				"user", spamfilter_user,				unreal_decodespace(tk->ptr.spamf->tkl_reason));			matches++;		}		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -