problem with script
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

problem with script

Started by Kastor, 23 March, 2007, 20:42:04

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Kastor

this script works with lua 5.1??? thanks....



This script detects when a dumbass is dos attacking your hub using the P2P ConnectToMe exploit. It gives stats on
how many attacks happen each minute\hour and has an average hour attack count.

I left out a few features that track the users back to the hub that is allowing the attack to take place because i couldnt
be bothered translating all the script back to PtokaX and alot of ediots will just attack them back if the script tells them
where the attacks source from.


Code:
Code: lua
-- Converted from cSlave 1.0 for PtokaX by Corayzon

cSlave = {}
cSlave.FloodDetection = {}
cSlave.FloodDetection.iMinCount = 0
cSlave.FloodDetection.iHourCounter = 0
cSlave.FloodDetection.iHourCount = 0
cSlave.FloodDetection.Adverage = 0
sBotName = frmHub:GetHubBotName()

Main = function()

	-- Start cSlave timer api
	SetTimer = 60
	StartTimer()

end

UnknownArrival = function(User, sData)

	-- Get command
	local _,_, sCommand, sArguments = string.find(sData, "(%S+)")

	if sCommand == "$MyNick" then

		-- Add count to flood counter
		cSlave.FloodDetection.iMinCount = cSlave.FloodDetection.iMinCount + 1
		cSlave.FloodDetection.iHourCount = cSlave.FloodDetection.iHourCount + 1
	end
end

OnTimer = function()

	-- Increment hour counter one minute
	cSlave.FloodDetection.iHourCounter = cSlave.FloodDetection.iHourCounter + 1

	-- Check if a hour has been reached
	if cSlave.FloodDetection.iHourCounter == 60 then

		-- Check if is first adverage
		if cSlave.FloodDetection.Adverage == 0 then

			-- Make hour average
			cSlave.FloodDetection.Adverage = cSlave.FloodDetection.iHourCount
		else

			-- Make hour average
			cSlave.FloodDetection.Adverage = (cSlave.FloodDetection.iHourCount + cSlave.FloodDetection.Adverage) / 2
		end

		-- Empty hour connection counter
		cSlave.FloodDetection.iHourCount = 0

		-- Empty hour counter
		cSlave.FloodDetection.iHourCounter = 0
	end

	-- Check if flood was detected
	if cSlave.FloodDetection.iMinCount > 0 then

		local iAverage = 0

		if cSlave.FloodDetection.Adverage == 0 then
			iAverage = cSlave.FloodDetection.iHourCount
		else
			iAverage = cSlave.FloodDetection.Adverage
		end

		-- Send Message to operators
		SendPmToOps(sBotName, "*** Connection Flood Detected: \r\n\r\n\t\tConnections in last minute: " .. cSlave.FloodDetection.iMinCount .. "\r\n\t\tConnections in this hour: " .. cSlave.FloodDetection.iHourCount .. "\r\n\t\tConnections in hour average: " .. iAverage .. "\r\n")

		cSlave.FloodDetection.iMinCount = 0
	end
end






I use ptokax 0.3.5.1 lua 5.0.2


Help me please

bastya_elvtars

Ran through the code and IMO it should work with 5.1.
Everything could have been anything else and it would have just as much meaning.

CrazyGuy

yes, the code is LUA 5.1 compatible

But there are a few things you might wanna look at.

Your timer interval is set to 60, which is 60 miliseconds. You increase it 60 times OnTimer and then pass that as an hour has passed, so that will be wrong. If you increase 60 times on Ontimer, the interval must be set to 1 minute: 1 milisecond * 1000 is 1 sec * 60 is a minute so 60000.

Another thing is that your Hour average will be off after the 2nd hour has passed.

cSlave.FloodDetection.Adverage = (cSlave.FloodDetection.iHourCount + cSlave.FloodDetection.Adverage) / 2


That is okay for the first 2 hours, after that Adverage (and why not Average?) holds a value for multiple hours. You then add 1 hour to it and divide it by 2.  That is not a good average.

Another thing is you can optimize your UnknownArrival. No need to actually capture a command if you are only interrested in 1 value.

UnknownArrival = function(User, sData)
 	-- Get command
	if string.find(sData, "$MyNick") then
		-- Add count to flood counter
		cSlave.FloodDetection.iMinCount = cSlave.FloodDetection.iMinCount + 1
		cSlave.FloodDetection.iHourCount = cSlave.FloodDetection.iHourCount + 1
	end
end


does the trick as well

SMF spam blocked by CleanTalk