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:
-- 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
Ran through the code and IMO it should work with 5.1.
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