搜索
查看: 4591|回复: 19

[AMXX 带源码] -=惩罚频繁连接者=-

[复制链接]
发表于 2009-4-1 19:19:50 | 显示全部楼层 |阅读模式 来自 安徽合肥
#include <amxmodx>

const TASK_JOINMSG = 100
const TASK_DOCHECKS = 200
#define ID_JOINMSG (taskid-TASK_JOINMSG)

new cvar_flux, cvar_loss, cvar_punishment, cvar_bantime, cvar_immunity
new g_maxflux, g_maxloss, g_immunityflags, g_maxplayers, g_connected[33]
new g_lastping[33], g_fluxcounter[33], g_losscounter[33], g_immune[33]

// I wouldn't recommend lowering these unless
// you wanna pick up a lot of false positives
const Float:CHECK_FREQ = 5.0
const FLUX_TESTS = 12
const LOSS_TESTS = 12

public plugin_init()
{
        register_plugin("Lame Connection Punisher", "1.1b", "MeRcyLeZZ")
        register_dictionary("lame_connection_punisher.txt")
        register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
       
        cvar_flux = register_cvar("lcp_flux_limit", "100")
        cvar_loss = register_cvar("lcp_loss_limit", "10")
        cvar_punishment = register_cvar("lcp_punishment", "0")
        cvar_bantime = register_cvar("lcp_ban_time", "5")
        cvar_immunity = register_cvar("lcp_immunity", "a")
        g_maxplayers = get_maxplayers()
}

public plugin_cfg()
{
        // Cache CVARs after configs are loaded
        set_task(0.5, "event_round_start")
       
        // Start checking players
        set_task(CHECK_FREQ, "do_checks", TASK_DOCHECKS, _, _, "b")
}

public event_round_start()
{
        // Cache CVARs
        new flags[6]
        get_pcvar_string(cvar_immunity, flags, charsmax(flags))
        g_immunityflags = read_flags(flags)
        g_maxflux = get_pcvar_num(cvar_flux)
        g_maxloss = get_pcvar_num(cvar_loss)
       
        // Check flags again for all players
        for (new id = 1; id <= g_maxplayers; id++)
                if (g_connected[id]) check_flags(id)
}

public client_putinserver(id)
{
        set_task(16.0, "join_message", id+TASK_JOINMSG)
        g_connected[id] = true
}

public client_authorized(id)
{
        check_flags(id)
}

public client_infochanged(id)
{
        check_flags(id)
}

public client_disconnect(id)
{
        remove_task(id+TASK_JOINMSG)
        g_fluxcounter[id] = 0
        g_losscounter[id] = 0
        g_lastping[id] = 0
        g_immune[id] = 0
        g_connected[id] = false
}

public do_checks()
{
        static id, ping, loss, name[32], auth[32], userid, minutes
       
        for (id = 1; id <= g_maxplayers; id++)
        {
                if (!g_connected[id] || g_immune[id])
                        continue;
               
                get_user_ping(id, ping, loss)
               
                if (loss > g_maxloss)
                        g_losscounter[id]++
                else if (g_losscounter[id] > 0)
                        g_losscounter[id]--
               
                if (g_losscounter[id] >= LOSS_TESTS)
                {
                        get_user_name(id, name , sizeof name - 1)
                        userid = get_user_userid(id)
                       
                        switch (get_pcvar_num(cvar_punishment))
                        {
                                case 1:
                                {
                                        get_user_authid(id, auth, sizeof auth - 1)
                                        minutes = get_pcvar_num(cvar_bantime)
                                       
                                        if (minutes > 0)
                                        {
                                                client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_BAN", name, minutes)
                                                log_amx("%L", LANG_SERVER, "MSG_ALL_BAN", name, minutes)
                                                server_cmd("kick #%d ^"%L^";wait;banid %d ^"%s^";wait;writeid", userid, id, "MSG_TARGET_LOSS", minutes, auth)
                                        }
                                        else
                                        {
                                                client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_PBAN", name)
                                                log_amx("%L", LANG_SERVER, "MSG_ALL_PBAN", name)
                                                server_cmd("kick #%d ^"%L^";wait;banid 0 ^"%s^";wait;writeid", userid, id, "MSG_TARGET_LOSS", auth)
                                        }
                                }
                                case 2:
                                {
                                        get_user_ip(id, auth, sizeof auth - 1, 1)
                                        minutes = get_pcvar_num(cvar_bantime)
                                       
                                        if (minutes > 0)
                                        {
                                                client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_BAN", name, minutes)
                                                log_amx("%L", LANG_SERVER, "MSG_ALL_BAN", name, minutes)
                                                server_cmd("kick #%d ^"%L^";wait;addip %d ^"%s^";wait;writeip", userid, id, "MSG_TARGET_LOSS", minutes, auth)
                                        }
                                        else
                                        {
                                                client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_PBAN", name)
                                                log_amx("%L", LANG_SERVER, "MSG_ALL_PBAN", name)
                                                server_cmd("kick #%d ^"%L^";wait;addip 0 ^"%s^";wait;writeip", userid, id, "MSG_TARGET_LOSS", auth)
                                        }
                                }
                                default:
                                {
                                        client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_KICK", name)
                                        log_amx("%L", LANG_SERVER, "MSG_ALL_KICK", name)
                                        server_cmd("kick #%d ^"%L^"", userid, id, "MSG_TARGET_LOSS")
                                }
                        }
                        continue;
                }
               
                if (abs(ping - g_lastping[id]) > g_maxflux)
                        g_fluxcounter[id]++
                else if (g_fluxcounter[id] > 0)
                        g_fluxcounter[id]--
               
                if (g_fluxcounter[id] >= FLUX_TESTS)
                {
                        get_user_name(id, name , sizeof name - 1)
                        userid = get_user_userid(id)
                       
                        switch (get_pcvar_num(cvar_punishment))
                        {
                                case 1:
                                {
                                        get_user_authid(id, auth, sizeof auth - 1)
                                        minutes = get_pcvar_num(cvar_bantime)
                                       
                                        if (minutes > 0)
                                        {
                                                client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_BAN", name, minutes)
                                                log_amx("%L", LANG_SERVER, "MSG_ALL_BAN", name, minutes)
                                                server_cmd("kick #%d ^"%L^";wait;banid %d ^"%s^";wait;writeid", userid, id, "MSG_TARGET_FLUX", minutes, auth)
                                        }
                                        else
                                        {
                                                client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_PBAN", name)
                                                log_amx("%L", LANG_SERVER, "MSG_ALL_PBAN", name)
                                                server_cmd("kick #%d ^"%L^";wait;banid 0 ^"%s^";wait;writeid", userid, id, "MSG_TARGET_FLUX", auth)
                                        }
                                }
                                case 2:
                                {
                                        get_user_ip(id, auth, sizeof auth - 1, 1)
                                        minutes = get_pcvar_num(cvar_bantime)
                                       
                                        if (minutes > 0)
                                        {
                                                client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_BAN", name, minutes)
                                                log_amx("%L", LANG_SERVER, "MSG_ALL_BAN", name, minutes)
                                                server_cmd("kick #%d ^"%L^";wait;addip %d ^"%s^";wait;writeip", userid, id, "MSG_TARGET_FLUX", minutes, auth)
                                        }
                                        else
                                        {
                                                client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_PBAN", name)
                                                log_amx("%L", LANG_SERVER, "MSG_ALL_PBAN", name)
                                                server_cmd("kick #%d ^"%L^";wait;addip 0 ^"%s^";wait;writeip", userid, id, "MSG_TARGET_FLUX", auth)
                                        }
                                }
                                default:
                                {
                                        client_print(0, print_chat, "[AMXX] %L", LANG_PLAYER, "MSG_ALL_KICK", name)
                                        log_amx("%L", LANG_SERVER, "MSG_ALL_KICK", name)
                                        server_cmd("kick #%d ^"%L^"", userid, id, "MSG_TARGET_FLUX")
                                }
                        }
                        continue;
                }
               
                g_lastping[id] = ping
        }
}

public join_message(taskid)
{
        client_print(ID_JOINMSG, print_chat, "[AMXX] %L", ID_JOINMSG, "JOIN_MSG", g_maxflux, g_maxloss)
}

check_flags(id)
{
        g_immune[id] = get_user_flags(id) & g_immunityflags
}

语言数据
lame_connection_punisher.txt
[cn]
JOIN_MSG = 玩家重入都將受到懲罰(平流量限制: %d ,限制: %d )。
MSG_ALL_KICK = %s 已踢出因重入本伺服器
MSG_ALL_BAN = %s 已禁止 %d 分鐘因重入本伺服器
MSG_ALL_PBAN = %s 被永久禁止因重入本伺服器。
MSG_TARGET_LOSS = 您因重入本伺服器而失去很多數據包
MSG_TARGET_FLUX = 您的廷遲不太穩定.
发表于 2009-4-1 22:31:11 | 显示全部楼层 来自 安徽六安
hebe!!!!!!!!!!!!!!!!!!!!
回复

使用道具 举报

发表于 2009-4-1 23:31:31 | 显示全部楼层 来自 河南南阳
:victory:                  。。。。。。。。
回复

使用道具 举报

发表于 2009-4-1 23:47:39 | 显示全部楼层 来自 广东深圳
:D
有个reme的插件可以达到这个功能
还可以刷新分数不用重进服务器
回复

使用道具 举报

 楼主| 发表于 2009-4-2 00:54:51 | 显示全部楼层 来自 安徽合肥
我只是发现这个插件源码!故发到这里供大家研究随便赚点值
回复

使用道具 举报

发表于 2009-4-2 14:20:35 | 显示全部楼层 来自 山西晋城
没有玩家连接次数过于频繁会提示"连接过于频繁,稍候重试"这种的...不是retry 这种的
回复

使用道具 举报

发表于 2009-4-2 15:53:39 | 显示全部楼层 来自 安徽六安
没有玩家连接次数过于频繁会提示"连接过于频繁,稍候重试"这种的...不是retry 这种的
小白 发表于 2009-4-2 14:20

官网上好像看到过这种插件。
回复

使用道具 举报

发表于 2009-4-2 16:18:01 | 显示全部楼层 来自 广西防城港
作用不大。。
回复

使用道具 举报

发表于 2009-4-3 09:48:06 | 显示全部楼层 来自 辽宁本溪
没什么意思
回复

使用道具 举报

发表于 2010-2-8 17:25:33 | 显示全部楼层 来自 山东枣庄
晕 直接把源码弄上来了。。。
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表