Author:
Tested on: 0.3.6
This code need it:
http://otland.net/f163/lua-c-ping-lib-ping-getping-cid-storage-121183/
Well This script will kick all players how get verry high ping. In case of DDoS all pings will rise up so then auto kick and 0 loses on DDoS attack!
(It will not avoid DDoS attack only protect the players)
Add it on globalevnts.xml
in ddos.lua:
With this script, if the player got the ping higger than like 2 seconds of ping the server will kick him. BUT if the DDoS protection form the script was activate and the server ping avarage get higger or equal to 75% of 2 seconds (defaut config) the server will kick all players and save. :blink:
Tested on: 0.3.6
This code need it:
http://otland.net/f163/lua-c-ping-lib-ping-getping-cid-storage-121183/
Well This script will kick all players how get verry high ping. In case of DDoS all pings will rise up so then auto kick and 0 loses on DDoS attack!
(It will not avoid DDoS attack only protect the players)
Add it on globalevnts.xml
Code:
<globalevent name="ddos_mock" interval="60" event="script" value="ddos.lua"/>
Lua:
---Script by mock the bear
local ping_timeout_ = 2000 -- Equals 2 seconds of non response
local active_anti_ddos = true;
local ping_to_execute_anti_ddos = 0.75 --[[is ping timeout * self.
If helf of this server ping if near this value
the server will auto kick]]
local pingbase = 0;
local pingN = 0;
local block = false;
local player_o = 0;
function onThink(interval, lastExecution) -- MTB
pingbase = 0;
pingN = 0;
block = false;
local pls = getPlayersOnline()
player_o = #pls
for i,cid in pairs(pls) do
ping.getPing(cid,29894,function(cid,_,ping_,i)
if active_anti_ddos then
pingbase = pingbase+ping_
pingN = pingN+1
if (math.floor(player_o/2) > 5) and math.floor(player_o/2) <= pingN then
if pingbase/pingN > ping_timeout_*ping_to_execute_anti_ddos then
broadcastMessage("DDoS attack maby detected! KICKING EVEBODY!", 25)
block = true;
for a,cid in pairs(getPlayersOnline()) do
doRemoveCreature(cid)
end
doSaveServer()
end
end
end
if ping_ > ping_timeout_ and not block then
doRemoveCreature(cid)
end
if i == pls then
print('Ping avarage: '..pingbase/pingN..' ms/player.')
end
end,i)
end
return true
end
With this script, if the player got the ping higger than like 2 seconds of ping the server will kick him. BUT if the DDoS protection form the script was activate and the server ping avarage get higger or equal to 75% of 2 seconds (defaut config) the server will kick all players and save. :blink: