• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

GlobalEvent Auto kick lagged players + DDoS protection

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
Author:
bearpaw.png

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"/>
in 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:
 
@Bogart

You just a TROLL.

@Topic

Ok,im gonna test
 
@Bogart

You just a TROLL.

@Topic

Ok,im gonna test

are you even serious?

you are the one that didn't even read before posting, it says >>>tested<<< so its' tested, and it should be working, and if it's tested and doesn't work, why would mock release it?
 
no, the 'Tested on: 0.3.6' was just a decoration.

SOKAOSKAOSKOAKSOAKSOAKSOAKSOAKSOAKSOAKSOAKS'
I'm laughing too much!

---
Nice stuff mock. Oo'
Just need change this 'english error' here:
DDoS attack maby detected! KICKING EVEBODY!

DDoS attack was detected! KICKING EVERYBODY!

Or, if you prefer the google's translation:
Ataque DDoS foi detectado! RODAPÉ TODOS! :p

Cya!
 
What happens if player X-logs? Will he get kicked in 2 seconds or it'll work properly?
 
the function getPlayerPing will return String 'Disconected' and the ping.loop will stop.
 
Code:
[09/03/2011 16:16:54] [Error - GlobalEvent Interface] 
[09/03/2011 16:16:54] data/globalevents/scripts/ddos.lua:onThink
[09/03/2011 16:16:54] Description: 
[09/03/2011 16:16:54] data/lib/123-pinglib.lua:37: attempt to call global 'CheckPing' (a nil value)
[09/03/2011 16:16:54] stack traceback:
[09/03/2011 16:16:54] 	data/lib/123-pinglib.lua:37: in function 'loop'
[09/03/2011 16:16:54] 	data/lib/123-pinglib.lua:55: in function 'getPing'
[09/03/2011 16:16:54] 	data/globalevents/scripts/ddos.lua:19: in function <data/globalevents/scripts/ddos.lua:12>
[09/03/2011 16:16:54] [Error - GlobalEvents::think] Couldn't execute event: ddos_mock[/QUOTE]

 (:
 
Code:
[09/03/2011 16:16:54] [Error - GlobalEvent Interface] 
[09/03/2011 16:16:54] data/globalevents/scripts/ddos.lua:onThink
[09/03/2011 16:16:54] Description: 
[09/03/2011 16:16:54] data/lib/123-pinglib.lua:37: attempt to call global 'CheckPing' (a nil value)
[09/03/2011 16:16:54] stack traceback:
[09/03/2011 16:16:54] 	data/lib/123-pinglib.lua:37: in function 'loop'
[09/03/2011 16:16:54] 	data/lib/123-pinglib.lua:55: in function 'getPing'
[09/03/2011 16:16:54] 	data/globalevents/scripts/ddos.lua:19: in function <data/globalevents/scripts/ddos.lua:12>
[09/03/2011 16:16:54] [Error - GlobalEvents::think] Couldn't execute event: ddos_mock[/QUOTE]

 (:[/QUOTE]
...
read all theread.
 
What happens if your from new zealand, my ping is too shit to even move someone by pushing them... does this mean whatever server uses this means i can't play that server? my ping will kick me >.>
 
Back
Top