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

📄 m_tkl.c

📁 Unreal irc 服务器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* *   Unreal Internet Relay Chat Daemon, src/modules/m_tkl.c *   TKL Commands and TKL Layer *   (C) 1999-2006 The UnrealIRCd Team * *   See file AUTHORS in IRC package for additional names of *   the programmers. * *   This program is free software; you can redistribute it and/or modify *   it under the terms of the GNU General Public License as published by *   the Free Software Foundation; either version 1, or (at your option) *   any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "config.h"#include "struct.h"#include "common.h"#include "sys.h"#include "numeric.h"#include "msg.h"#include "channel.h"#include <time.h>#include <sys/stat.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#ifdef _WIN32#include <io.h>#else#include <sys/socket.h>#endif#include <fcntl.h>#include "inet.h"#include "h.h"#include "proto.h"#ifdef STRIPBADWORDS#include "badwords.h"#endif#ifdef _WIN32#include "version.h"#endifDLLFUNC int m_gline(aClient *cptr, aClient *sptr, int parc, char *parv[]);DLLFUNC int m_shun(aClient *cptr, aClient *sptr, int parc, char *parv[]);DLLFUNC int m_tempshun(aClient *cptr, aClient *sptr, int parc, char *parv[]);DLLFUNC int m_gzline(aClient *cptr, aClient *sptr, int parc, char *parv[]);DLLFUNC int m_tkline(aClient *cptr, aClient *sptr, int parc, char *parv[]);DLLFUNC int m_tzline(aClient *cptr, aClient *sptr, int parc, char *parv[]);DLLFUNC int m_tkl_line(aClient *cptr, aClient *sptr, int parc, char *parv[], char* type);DLLFUNC int m_spamfilter(aClient *cptr, aClient *sptr, int parc, char *parv[]);int _tkl_hash(unsigned int c);char _tkl_typetochar(int type);aTKline *_tkl_add_line(int type, char *usermask, char *hostmask, char *reason, char *setby,    TS expire_at, TS set_at, TS spamf_tkl_duration, char *spamf_tkl_reason);aTKline *_tkl_del_line(aTKline *tkl);static void _tkl_check_local_remove_shun(aTKline *tmp);aTKline *_tkl_expire(aTKline * tmp);EVENT(_tkl_check_expire);int _find_tkline_match(aClient *cptr, int xx);int _find_shun(aClient *cptr);int _find_spamfilter_user(aClient *sptr, int flags);aTKline *_find_qline(aClient *cptr, char *nick, int *ishold);int _find_tkline_match_zap(aClient *cptr);int _find_tkline_match_zap_ex(aClient *cptr, aTKline **rettk);void _tkl_stats(aClient *cptr, int type, char *para);void _tkl_synch(aClient *sptr);int _m_tkl(aClient *cptr, aClient *sptr, int parc, char *parv[]);int _place_host_ban(aClient *sptr, int action, char *reason, long duration);int _dospamfilter(aClient *sptr, char *str_in, int type, char *target, int flags, aTKline **rettk);int _dospamfilter_viruschan(aClient *sptr, aTKline *tk, int type);void _spamfilter_build_user_string(char *buf, char *nick, aClient *acptr);extern MODVAR char zlinebuf[BUFSIZE];extern MODVAR aTKline *tklines[TKLISTLEN];extern int MODVAR spamf_ugly_vchanoverride;/* Place includes here */#define MSG_GLINE "GLINE"#define TOK_GLINE "}"#define MSG_SHUN "SHUN"#define TOK_SHUN "BL"#define MSG_GZLINE "GZLINE"#define MSG_KLINE "KLINE"#define MSG_ZLINE "ZLINE"#define MSG_SPAMFILTER	"SPAMFILTER"#define TOK_NONE ""#define MSG_TEMPSHUN "TEMPSHUN"#define TOK_TEMPSHUN "Tz"ModuleInfo *TklModInfo;ModuleHeader MOD_HEADER(m_tkl)  = {	"tkl",	/* Name of module */	"$Id: m_tkl.c,v 1.1.6.10 2006/12/22 21:10:33 syzop Exp $", /* Version */	"commands /gline etc", /* Short description of module */	"3.2-b8-1",	NULL     };DLLFUNC int MOD_TEST(m_tkl)(ModuleInfo *modinfo){	MARK_AS_OFFICIAL_MODULE(modinfo);	TklModInfo = modinfo;	EfunctionAdd(modinfo->handle, EFUNC_TKL_HASH, _tkl_hash);	EfunctionAdd(modinfo->handle, EFUNC_TKL_TYPETOCHAR, TO_INTFUNC(_tkl_typetochar));	EfunctionAddPVoid(modinfo->handle, EFUNC_TKL_ADD_LINE, TO_PVOIDFUNC(_tkl_add_line));	EfunctionAddPVoid(modinfo->handle, EFUNC_TKL_DEL_LINE, TO_PVOIDFUNC(_tkl_del_line));	EfunctionAddVoid(modinfo->handle, EFUNC_TKL_CHECK_LOCAL_REMOVE_SHUN, _tkl_check_local_remove_shun);	EfunctionAddPVoid(modinfo->handle, EFUNC_TKL_EXPIRE, TO_PVOIDFUNC(_tkl_expire));	EfunctionAddVoid(modinfo->handle, EFUNC_TKL_CHECK_EXPIRE, _tkl_check_expire);	EfunctionAdd(modinfo->handle, EFUNC_FIND_TKLINE_MATCH, _find_tkline_match);	EfunctionAdd(modinfo->handle, EFUNC_FIND_SHUN, _find_shun);	EfunctionAdd(modinfo->handle, EFUNC_FIND_SPAMFILTER_USER, _find_spamfilter_user);	EfunctionAddPVoid(modinfo->handle, EFUNC_FIND_QLINE, TO_PVOIDFUNC(_find_qline));	EfunctionAdd(modinfo->handle, EFUNC_FIND_TKLINE_MATCH_ZAP, _find_tkline_match_zap);	EfunctionAdd(modinfo->handle, EFUNC_FIND_TKLINE_MATCH_ZAP_EX, _find_tkline_match_zap_ex);	EfunctionAddVoid(modinfo->handle, EFUNC_TKL_STATS, _tkl_stats);	EfunctionAddVoid(modinfo->handle, EFUNC_TKL_SYNCH, _tkl_synch);	EfunctionAdd(modinfo->handle, EFUNC_M_TKL, _m_tkl);	EfunctionAdd(modinfo->handle, EFUNC_PLACE_HOST_BAN, _place_host_ban);	EfunctionAdd(modinfo->handle, EFUNC_DOSPAMFILTER, _dospamfilter);	EfunctionAdd(modinfo->handle, EFUNC_DOSPAMFILTER_VIRUSCHAN, _dospamfilter_viruschan);	EfunctionAddVoid(modinfo->handle, EFUNC_SPAMFILTER_BUILD_USER_STRING, _spamfilter_build_user_string);	return MOD_SUCCESS;}/* This is called on module init, before Server Ready */DLLFUNC int MOD_INIT(m_tkl)(ModuleInfo *modinfo){	MARK_AS_OFFICIAL_MODULE(modinfo);	/*	 * We call our add_Command crap here	*/	add_Command(MSG_GLINE, TOK_GLINE, m_gline, 3);	add_Command(MSG_SHUN, TOK_SHUN, m_shun, 3);	add_Command(MSG_TEMPSHUN, TOK_TEMPSHUN, m_tempshun, 2);	add_Command(MSG_ZLINE, TOK_NONE, m_tzline, 3);	add_Command(MSG_KLINE, TOK_NONE, m_tkline, 3);	add_Command(MSG_GZLINE, TOK_NONE, m_gzline, 3);	add_Command(MSG_SPAMFILTER, TOK_NONE, m_spamfilter, 6);	add_Command(MSG_TKL, TOK_TKL, _m_tkl, MAXPARA);	MARK_AS_OFFICIAL_MODULE(modinfo);	return MOD_SUCCESS;}/* Is first run when server is 100% ready */DLLFUNC int MOD_LOAD(m_tkl)(int module_load){	EventAddEx(TklModInfo->handle, "tklexpire", 5, 0, tkl_check_expire, NULL);	return MOD_SUCCESS;}/* Called when module is unloaded */DLLFUNC int MOD_UNLOAD(m_tkl)(int module_unload){	if ((del_Command(MSG_GLINE, TOK_GLINE, m_gline) < 0) ||	    (del_Command(MSG_SHUN, TOK_SHUN, m_shun) < 0 ) ||	    (del_Command(MSG_ZLINE, TOK_NONE, m_tzline) < 0) ||	    (del_Command(MSG_GZLINE, TOK_NONE, m_gzline) < 0) ||	    (del_Command(MSG_KLINE, TOK_NONE, m_tkline) < 0) ||	    (del_Command(MSG_SPAMFILTER, TOK_NONE, m_spamfilter) < 0) ||	    (del_Command(MSG_TEMPSHUN, TOK_TEMPSHUN, m_tempshun) < 0) ||	    (del_Command(MSG_TKL, TOK_TKL, _m_tkl) < 0))	{		sendto_realops("Failed to delete commands when unloading %s",				MOD_HEADER(m_tkl).name);	}	return MOD_SUCCESS;}/*** m_gline (oper function - /TKL takes care of distribution)** /gline [+|-]u@h mask time :reason**** parv[0] = sender** parv[1] = [+|-]u@h mask** parv[2] = for how long** parv[3] = reason*/DLLFUNC int m_gline(aClient *cptr, aClient *sptr, int parc, char *parv[]){	if (IsServer(sptr))		return 0;	if (!OPCanTKL(sptr) || !IsOper(sptr))	{		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,		sptr->name);		return 0;	}	if (parc == 1)	{		tkl_stats(sptr, TKL_KILL|TKL_GLOBAL, NULL);		tkl_stats(sptr, TKL_ZAP|TKL_GLOBAL, NULL);		sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, sptr->name, 'g');		return 0;	}	return m_tkl_line(cptr, sptr, parc, parv, "G");}DLLFUNC int m_gzline(aClient *cptr, aClient *sptr, int parc, char *parv[]){	if (IsServer(sptr))		return 0;	if (!OPCanGZL(sptr) || !IsOper(sptr))	{		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,		sptr->name);		return 0;	}	if (parc == 1)	{		tkl_stats(sptr, TKL_GLOBAL|TKL_KILL, NULL);		tkl_stats(sptr, TKL_GLOBAL|TKL_ZAP, NULL);		sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, sptr->name, 'g');		return 0;	}	return m_tkl_line(cptr, sptr, parc, parv, "Z");}DLLFUNC int m_shun(aClient *cptr, aClient *sptr, int parc, char *parv[]){	if (IsServer(sptr))		return 0;	if (!OPCanTKL(sptr) || !IsOper(sptr))	{		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,		sptr->name);		return 0;	}	if (parc == 1)	{		tkl_stats(sptr, TKL_GLOBAL|TKL_SHUN, NULL);		sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, sptr->name, 's');		return 0;	}	return m_tkl_line(cptr, sptr, parc, parv, "s");}DLLFUNC int m_tempshun(aClient *cptr, aClient *sptr, int parc, char *parv[]){aClient *acptr;char *comment = ((parc > 2) && !BadPtr(parv[2])) ? parv[2] : "no reason";char *name;int remove = 0;	if (MyClient(sptr) && (!OPCanTKL(sptr) || !IsOper(sptr)))	{		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,		sptr->name);		return 0;	}	if ((parc < 2) || BadPtr(parv[1]))	{		sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, sptr->name, "TEMPSHUN");		return 0;	}	if (parv[1][0] == '+')		name = parv[1]+1;	else if (parv[1][0] == '-')	{		name = parv[1]+1;		remove = 1;	} else		name = parv[1];	acptr = find_person(name, NULL);	if (!acptr)	{		sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, sptr->name, name);		return 0;	}	if (!MyClient(acptr))	{		sendto_one(acptr->from, ":%s %s %s :%s",			sptr->name, IsToken(acptr->from) ? TOK_TEMPSHUN : MSG_TEMPSHUN,			parv[1], comment);	} else {		char buf[1024];		if (!remove)		{			if (IsShunned(acptr))			{				sendnotice(sptr, "User '%s' already shunned", acptr->name);			} else if (IsAnOper(acptr))			{				sendnotice(sptr, "You cannot tempshun '%s' because (s)he is an oper", acptr->name);			} else			{				SetShunned(acptr);				ircsprintf(buf, "Temporary shun added on user %s (%s@%s) by %s [%s]",					acptr->name, acptr->user->username, acptr->user->realhost,					sptr->name, comment);				sendto_snomask(SNO_TKL, "%s", buf);				sendto_serv_butone_token(NULL, me.name, MSG_SENDSNO, TOK_SENDSNO, "G :%s", buf);			}		} else {			if (!IsShunned(acptr))			{				sendnotice(sptr, "User '%s' is not shunned", acptr->name);			} else {				ClearShunned(acptr);				ircsprintf(buf, "Removed temporary shun on user %s (%s@%s) by %s",					acptr->name, acptr->user->username, acptr->user->realhost,					sptr->name);				sendto_snomask(SNO_TKL, "%s", buf);				sendto_serv_butone_token(NULL, me.name, MSG_SENDSNO, TOK_SENDSNO, "G :%s", buf);			}		}	}	return 0;}DLLFUNC int m_tkline(aClient *cptr, aClient *sptr, int parc, char *parv[]){	if (IsServer(sptr))		return 0;	if (!OPCanKline(sptr) || !IsAnOper(sptr))	{		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,		sptr->name);		return 0;	}	if (parc == 1)	{		/* Emulate /stats k */		ConfigItem_ban *bans;		ConfigItem_except *excepts;		char type[2];  		for (bans = conf_ban; bans; bans = (ConfigItem_ban *)bans->next) 		{			if (bans->flag.type == CONF_BAN_USER) 			{				if (bans->flag.type2 == CONF_BAN_TYPE_CONF)					type[0] = 'K';				type[1] = '\0';				sendto_one(sptr, rpl_str(RPL_STATSKLINE),			 		me.name, sptr->name, type, bans->mask, bans->reason					? bans->reason : "<no reason>");			}			else if (bans->flag.type == CONF_BAN_IP) 			{				if (bans->flag.type2 == CONF_BAN_TYPE_CONF)					type[0] = 'Z';				else if (bans->flag.type2 == CONF_BAN_TYPE_TEMPORARY)					type[0] = 'z';				type[1] = '\0';				sendto_one(sptr, rpl_str(RPL_STATSKLINE),					me.name, sptr->name, type, bans->mask, bans->reason 					? bans->reason : "<no reason>");			}		}				tkl_stats(sptr, TKL_KILL, NULL);		tkl_stats(sptr, TKL_ZAP, NULL);		for (excepts = conf_except; excepts; excepts = (ConfigItem_except *)excepts->next) 		{			if (excepts->flag.type == 1)				sendto_one(sptr, rpl_str(RPL_STATSKLINE),					me.name, sptr->name, "E", excepts->mask, "");		}		sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, sptr->name, 'k');		return 0;	}	if (!OPCanUnKline(sptr) && *parv[1] == '-')	{		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);		return 0;	}	return m_tkl_line(cptr, sptr, parc, parv, "k");}DLLFUNC int m_tzline(aClient *cptr, aClient *sptr, int parc, char *parv[]){	if (IsServer(sptr))		return 0;	if (!OPCanZline(sptr) || !IsAnOper(sptr))	{		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,		sptr->name);		return 0;	}	if (parc == 1)	{		/* Emulate /stats k */		ConfigItem_ban *bans;		ConfigItem_except *excepts;		char type[2];  		for (bans = conf_ban; bans; bans = (ConfigItem_ban *)bans->next) 		{			if (bans->flag.type == CONF_BAN_USER) 			{				if (bans->flag.type2 == CONF_BAN_TYPE_CONF)					type[0] = 'K';				type[1] = '\0';				sendto_one(sptr, rpl_str(RPL_STATSKLINE),			 		me.name, sptr->name, type, bans->mask, bans->reason					? bans->reason : "<no reason>");			}			else if (bans->flag.type == CONF_BAN_IP) 			{				if (bans->flag.type2 == CONF_BAN_TYPE_CONF)					type[0] = 'Z';				else if (bans->flag.type2 == CONF_BAN_TYPE_TEMPORARY)					type[0] = 'z';				type[1] = '\0';				sendto_one(sptr, rpl_str(RPL_STATSKLINE),					me.name, sptr->name, type, bans->mask, bans->reason 					? bans->reason : "<no reason>");			}		}				tkl_stats(sptr, TKL_KILL, NULL);		tkl_stats(sptr, TKL_ZAP, NULL);		for (excepts = conf_except; excepts; excepts = (ConfigItem_except *)excepts->next) 		{			if (excepts->flag.type == 1)				sendto_one(sptr, rpl_str(RPL_STATSKLINE),					me.name, sptr->name, "E", excepts->mask, "");		}		sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, sptr->name, 'k');		return 0;	}	return m_tkl_line(cptr, sptr, parc, parv, "z");}/*** m_tkl_line (oper function - /TKL takes care of distribution)** /gline [+|-]u@h mask time :reason**** parv[0] = sender** parv[1] = [+|-]u@h mask** parv[2] = for how long** parv[3] = reason*/DLLFUNC int  m_tkl_line(aClient *cptr, aClient *sptr, int parc, char *parv[], char* type) {	TS   secs;	int  whattodo = 0;	/* 0 = add  1 = del */	TS  i;	aClient *acptr = NULL;	char *mask = NULL;	char mo[1024], mo2[1024];	char *p, *usermask, *hostmask;	char *tkllayer[9] = {		me.name,	/*0  server.name */		NULL,		/*1  +|- */		NULL,		/*2  G   */		NULL,		/*3  user */		NULL,		/*4  host */		NULL,		/*5  setby */		"0",		/*6  expire_at */		NULL,		/*7  set_at */

⌨️ 快捷键说明

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