Corregido mod noclip e variaveis de ambiente (diretrizes)

master
BrunoMine 2016-03-25 14:22:03 -03:00
parent 2dc7247422
commit 4fdd31791b
6 changed files with 299 additions and 42 deletions

48
anti_dug_fast.lua Normal file
View File

@ -0,0 +1,48 @@
--
-- Mod Ant-Cracker
--
-- Ant-Dug-Fast
--
local diretrizes = anti_cracker.diretrizes.anti_dug_fast
local penalizados = {}
local liberar = function(name)
if name and penalizados[name] then
penalizados[name] = false
end
end
minetest.register_on_cheat(function(player, cheat)
if cheat.type == "dug_too_fast"and player then
local name = player:get_player_name()
penalizados[name] = true
minetest.after(diretrizes.tempo_liberar_cavar, liberar, name)
end
end)
local old_node_dig = minetest.node_dig
function minetest.node_dig(pos, node, digger)
if digger then
local name = digger:get_player_name()
if penalizados[name] then
return
end
end
return old_node_dig(pos, node, digger)
end
-- Limpa as variaveis quando o jogador sair do servidor
minetest.register_on_leaveplayer(function(player)
if player then
local name = player:get_player_name()
local Npenalizados = {}
for pname, n in pairs(penalizados) do
if name ~= pname then
Npenalizados[pname] = penalizados[pname]
end
end
penalizados = Npenalizados
end
end)

View File

@ -4,20 +4,61 @@
-- Ant-Fast
--
-- Um jogador anda um maximo de 40 blocos em 10 segundos
local diretrizes = anti_cracker.diretrizes.anti_fast
-- Calculando variaveis
local dist_max_andando = (diretrizes.tempo_att*diretrizes.velocidade_max)
local dist_max_andando_suspeito = (diretrizes.tempo_att_suspeitos*diretrizes.velocidade_max)
local dist_verif_emissor = diretrizes.dist_verif + dist_max_andando
local dist_verif_receptor = diretrizes.dist_verif
local spawn = minetest.setting_get_pos("static_spawnpoint") or {x=0,y=0,z=0}
local blocos_receptor = diretrizes.blocos_tp_livre
local blocos_emissor = diretrizes.blocos_tp_emissor
for i, bloco in ipairs(diretrizes.blocos_tp_livre) do
table.insert(blocos_emissor, bloco)
end
local ultima_pos = {}
local status_tp = {}
local acumulador = {}
local suspeitos = {}
-- Atualiza a posicao do jogador a cada instante
local cancelar_suspeito = function(name)
if name then
local Nsuspeitos = {}
for pname, n in pairs(suspeitos) do
if name ~= pname then
Nsuspeitos[pname] = suspeitos[pname]
end
end
suspeitos = Nsuspeitos
end
end
-- Atualiza a posicao do jogador
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer >= 15 then
if timer >= diretrizes.tempo_att then
timer = 0
for name, n in pairs(ultima_pos) do
local player = minetest.get_player_by_name(name)
if player then
if player and not suspeitos[name] then
ultima_pos[name] = player:getpos()
end
end
end
end)
-- Atualiza a posicao do jogador suspeitos
local timer2 = 0
minetest.register_globalstep(function(dtime)
timer2 = timer2 + dtime
if timer2 >= diretrizes.tempo_att_suspeitos then
timer2 = 0
for name, n in pairs(suspeitos) do
local player = minetest.get_player_by_name(name)
if player and ultima_pos[name] then
ultima_pos[name] = player:getpos()
end
end
@ -26,35 +67,57 @@ end)
local zerar_status_tp = function(name)
if name then
print(dump(status_tp[name]))
status_tp[name] = false
end
end
local zerar_acumulador = function(name)
if name then
acumulador[name] = false
end
end
minetest.register_on_cheat(function(player, cheat)
if player then
local name = player:get_player_name()
if cheat.type == "moved_too_fast" then
if minetest.check_player_privs(name, {teleport=true}) then
return
end
local pos = player:getpos()
if ultima_pos[name].x+40 < pos.x
or ultima_pos[name].x-40 > pos.x
or ultima_pos[name].z+40 < pos.z
or ultima_pos[name].z-40 > pos.z
then
if status_tp[name] == false then
if not minetest.find_node_near(player:getpos(), 20, lista_blocos_tp) then
if minetest.check_player_privs(name, {teleport=true}) ~= true then
local msg = "[Ant-Cracker] Medida 2 | Aparentemente voce correu rapido demais."
tomar_medida(name, 2, msg)
player:setpos(ultima_pos[name])
end
if cheat.type == "moved_too_fast" then
if player then
local name = player:get_player_name()
if acumulador[name] == false and status_tp[name] == false then
acumulador[name] = true
minetest.after(2, zerar_acumulador, name)
if minetest.check_player_privs(name, {teleport=true}) then
return
end
-- Verifica se o jogador esta muito longe de sua ultima posicao gravada
local pos = player:getpos()
local dist = dist_max_andando
if suspeitos[name] then
dist = dist_max_andando_suspeito
end
if ultima_pos[name].x+dist < pos.x
or ultima_pos[name].x-dist > pos.x
or ultima_pos[name].z+dist < pos.z
or ultima_pos[name].z-dist > pos.z
or ultima_pos[name].y+dist < pos.y
then
-- Verifica se tem blocos de legitimem a distancia tao longa como um tp
if not minetest.find_node_near(ultima_pos[name], dist_verif_emissor, blocos_emissor)
or not minetest.find_node_near(player:getpos(), dist_verif_receptor, blocos_receptor)
then
-- O teleport nao foi legitimo (ou o movimento pareceu muito rapido)
anti_cracker.tomar_medida(name, 2, "Aparentemente "..name.." moveu-se rapido demais.")
player:setpos(ultima_pos[name])
else
status_tp = true
-- O teleport foi legitimo
status_tp[name] = true
minetest.after(2, zerar_status_tp, name)
ultima_pos[name] = player:getpos()
end
else
-- O movimento pareceu rapido
if not suspeitos[name] then
suspeitos[name] = true
minetest.after(20, cancelar_suspeito, name)
end
end
end
end
@ -67,22 +130,51 @@ minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
ultima_pos[name] = (player:getpos())
status_tp[name] = false
acumulador[name] = false
end
end)
-- Limpa as variaveis quando o jogador sair do servidor
minetest.register_on_leaveplayer(function(player)
if player then
local name = player:get_player_by_name()
local name = player:get_player_name()
local Nultima_pos = {}
local Nstatus_tp = {}
local Nacumulador = {}
for pname, n in pairs(status_tp) do
if name ~= pname then
Nultima_pos[pname] = ultima_pos[pname]
Nstatus_tp[pname] = status_tp[pname]
Nacumulador[pname] = acumulador[pname]
end
end
acumulador = Nacumulador
ultima_pos = Nultima_pos
status_tp = Nstatus_tp
end
end)
-- Mantem o jogador no lugar do spawn
minetest.register_on_respawnplayer(function(player)
if player then
local pos = player:getpos()
local name = player:get_player_name()
if minetest.find_node_near(pos, dist_verif_receptor, diretrizes.blocos_respawn) then
ultima_pos[name] = pos
status_tp[name] = true
minetest.after(2, zerar_status_tp, name)
else
ultima_pos[name] = spawn
end
end
end)
-- As vezes o jogador nao vai para o spawn
minetest.register_on_dieplayer(function(player)
if player then
local name = player:get_player_name()
ultima_pos[name] = spawn
suspeitos[name] = true
minetest.after(diretrizes.tempo_att, cancelar_suspeito, name)
end
end)

54
anti_noclip.lua Normal file
View File

@ -0,0 +1,54 @@
--
-- Mod Ant-Cracker
--
-- Ant-NoClip
--
local diretrizes = anti_cracker.diretrizes.anti_noclip
local reverificar_noclip = function(pos, name)
if name then
local player = minetest.get_player_by_name(name)
if player then
local node = minetest.get_node(pos)
if node.name == "default:stone"
and table.maxn(minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1}, {x=pos.x+1, y=pos.y+2, z=pos.z+1} , {"default:stone"})) > 34
then
minetest.chat_send_player(name, "Morreste soterrado")
anti_cracker.tomar_medida(name, 1, name.." aparentemente usou noclip em cavernas.")
player:set_hp(0)
end
end
end
end
-- Loop para verificar
verificar_noclip = function(name)
if name then
local player = minetest.get_player_by_name(name)
if player then
local pos = player:getpos()
local node = minetest.get_node(pos)
if node.name == "default:stone"
and table.maxn(minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1}, {x=pos.x+1, y=pos.y+2, z=pos.z+1} , {"default:stone"})) > 34
then
minetest.after(diretrizes.tempo_reverificar_noclip, reverificar_nclip, pos, name)
end
if pos.y < -100 then
minetest.after(diretrizes.tempo_verificar_noclip, verificar_noclip, name)
else
minetest.after(60, verificar_noclip, name)
end
end
end
end
-- Inicia o loop com jogadores que se conectam no servidor
minetest.register_on_joinplayer(function(player)
if player then
local name = player:get_player_name()
if minetest.check_player_privs(name, {noclip=true}) ~= true or 1 == 1 then
minetest.after(diretrizes.tempo_verificar_noclip, verificar_noclip, name)
end
end
end)

View File

@ -4,16 +4,65 @@
-- Diretrizes
--
-- Ferramentas do Anti-Cracker
ANTI_NOHUP = true
ANTI_FAST = true
-- Tempo em segundos para verificar se o jogador esta
-- atravessando as paredes de uma caverna
tempo_verificar_nohup = 5
-- Ferramenta ANTI NOCLIP
local ANTI_NOCLIP = true
-- Tempo em segundos para verificar noclip em cavernas
local tempo_verificar_noclip = 8
-- Tempo para reverificar noclip (para caso de latencia alta do jogador)
local tempo_reverificar_noclip = 8
-- Lista de blocos permitidos para tp
-- (esses blocos devem sempre estar no maximo 20 blocos
-- de distancia do jogador quando ele chegar num lugar
-- por teleport legitimo)
lista_blocos_tp = {"default:dirt"}
-- Ferramenta ANTI FAST
local ANTI_FAST = true
-- Tempo (em segundos) para o servidor atualizar a posicao de todos os jogadores
local tempo_att = 15
-- Tempo (em segundos) para o servidor atualizar a posicao de todos os jogadores suspeitos
local tempo_att_suspeitos = 3
-- Velocidade maxima de um jogador andando (em blocos por segundo)
local velocidade_max = 7.1
-- Distancia maxima de um bloco de tp
local dist_verif = 15
-- Lista de blocos presentes para livre tp (opicional)
local blocos_tp_livre = {"portais:bilheteria", "telecasa:mapa"}
-- Lista de blocos presentes apenas para emitir jogadores (opicional)
local blocos_tp_emissor = {}
-- Lista de blocos presentes para respawn privado (exemplo a cama) (opicional)
local blocos_respawn = {}
-- Ferramenta ANTI DUG FAST (cavar muito rapido)
local ANTI_DUG_FAST = true
-- Tempo para liberar escavacao apos ter colocado cavado muito rapido
local tempo_liberar_cavar = 1
--
-- Ajustando dados globais
-- (Desenvolvimento)
--
anti_cracker.diretrizes = {}
if ANTI_NOCLIP then
anti_cracker.diretrizes.anti_noclip = {
tempo_verificar_noclip = tempo_verificar_noclip,
tempo_reverificar_noclip = tempo_reverificar_noclip
}
end
if ANTI_FAST then
anti_cracker.diretrizes.anti_fast = {
tempo_att = tempo_att,
tempo_att_suspeitos = tempo_att_suspeitos,
velocidade_max = velocidade_max,
dist_verif = dist_verif,
blocos_tp_livre = blocos_tp_livre,
blocos_tp_emissor = blocos_tp_emissor,
blocos_respawn = blocos_respawn
}
end
if ANTI_DUG_FAST then
anti_cracker.diretrizes.anti_dug_fast = {
tempo_liberar_cavar = tempo_liberar_cavar
}
end

View File

@ -13,14 +13,28 @@ end
local modpath = minetest.get_modpath("anti_cracker")
-- Variavel global
anti_cracker = {}
local d_anticheat = minetest.setting_getbool("disable_anticheat")
if not d_anticheat then
d_anticheat = false
end
-- Carregar scripts
notificar("Carregando scripts...")
dofile(modpath.."/diretrizes.lua")
dofile(modpath.."/metodos.lua")
if ANTI_NOHUP == true then
dofile(modpath.."/anti_nohup.lua")
if anti_cracker.diretrizes.anti_noclip then
dofile(modpath.."/anti_noclip.lua")
end
if ANTI_FAST == true then
if anti_cracker.diretrizes.anti_fast and d_anticheat == false then
dofile(modpath.."/anti_fast.lua")
end
if anti_cracker.diretrizes.anti_dug_fast and d_anticheat == false then
dofile(modpath.."/anti_dug_fast.lua")
end
notificar("OK")
if d_anticheat then
minetest.log("error", "[ANTI_CRACKER]: Alguns recursos do anti_cracker foram desabilitados porque o anti_cheat padrao foi desabilitado")
end

View File

@ -26,7 +26,7 @@ local retirar_kick = function(name)
kickados = Nkickados
end
-- Kickar jogador
kickar = function(name, numero, msg, tempo)
local kickar = function(name, numero, msg, tempo)
if not name or not msg or not tonumber(tempo) or not tonumber(numero) then return end
minetest.kick_player(name, "[Ant-Cracker] Medida "..numero.." | "..msg)
kickados[name] = numero
@ -40,7 +40,7 @@ minetest.register_on_prejoinplayer(function(name)
end)
-- Tomar medidas
tomar_medida = function(name, numero, msg, kick, tempo)
anti_cracker.tomar_medida = function(name, numero, msg, kick, tempo)
if not name or not tonumber(numero) or not msg then return end
local player = minetest.get_player_by_name(name)
if not player then return end