-- This script is converted with PtokaX LUA API Converter v0.9c at 10/06/09 13:12:14 -- Ban Flood Gate rev. 06 Oct 2009 -- written by district -- requested by ТиGRрр -- Reasoned here : http://dchublist.ru/forum/viewtopic.php?f=6&t=97 -- Private script author's Hub : dchub://dc.di-strict.ru -- Tech support topic : -- WELCOME TO OUR FORUM : http://mydc.ru/main.html local sBot = SetMan.GetString(21) local sAdminNick = "ТиGRрр" -- впишите ник админа local sMenuWay = "Ban Flood Gate" -- имя пункта меню local bUsePassword = true -- использовать ли пароль для разблокировки local sPassword = "12111" -- укажите пароль для разблокировки local sTestCmd = "test" -- команда для тестирования. в главный чат не проходит iProtectCount = 4 -- Количество событий защитного режима iProtectWithin = 20 -- Период наблюдения за событиями защитного режима в секундах nProtectRatio = iProtectCount/iProtectWithin -- Рабочее отношение local tCount = false local iGlCnt = 0 local tBlockedNicks = {} local bExtReport = false -- Посылать ли детальные посекундные репорты -- Встроенные команды банов PtokaX и приравненные к таковым команды : tBanCmds = { ["ban"] = true, ["banip"] = true, ["fullban"] = true, ["fullbanip"] = true, ["nickban"] = true, ["tempban"] = true, ["tempbanip"] = true, ["drop"] =true, ["fulltempban"] = true, ["fulltempbanip"] =true, ["nicktempban"] = true, ["rangeban"] =true, ["fullrangeban"] = true, ["rangetempban"] = true, ["fullrangetempban"] = true, -- ВНИМАНИЕ ! ТЕСТОВАЯ КОМАНДА : [sTestCmd] = true, } local sMenu = "$UserCommand 1 3 "..sMenuWay.."\\Отключить блокировку$<%[mynick]> ".. "!opengate "..(bUsePassword and "%[line:Введите пароль :]" or "").."||".. "$UserCommand 1 3 "..sMenuWay.."\\Включить блокировку$<%[mynick]> !closegate ".. (bUsePassword and "%[line:Введите пароль :]" or "").."||" function OnStartup() TmrMan.AddTimer(1000) end function OnTimer(tmr) iGlCnt = iGlCnt + 1 if tCount then local iCap = 0 for sNick,v in pairs(tCount) do iCap = iCap + 1 v:fEachCountFunc() if v.iEndTime == iGlCnt then tCount[sNick] = nil end end if iCap == 0 then tCount = nil ; end end end function OpConnected(tUser) if tUser.iProfile == 0 then Core.SendToUser(tUser,sMenu) ; end end function ChatArrival(tUser,sData) local sData = sData:sub(1,-2) ; local sCmd = sData:match("%b<>%s+%p(%S+)") if sCmd == "opengate" or sCmd == "closegate" then if tUser.iProfile == 0 then local sPass = false local bRightPass = false if bUsePassword then sPass = sData:match("%b<>%s+%p%S+%s+(%S+)") if sPass then if sPass == sPassword then bRightPass = true else Core.SendToUser(tUser,"<"..sBot.."> *** Ошибка! Неверный пароль!") end else Core.SendToUser(tUser,"<"..sBot.."> *** Ошибка! Вы не ввели пароль!") end end if sCmd == "opengate" then if not bUsePassword or bRightPass then if TableLen(tBlockedNicks) > 0 then tBlockedNicks = {} Core.SendToOps("<"..sBot.."> *** Блокировка кик- и бан-команд выключена.") else Core.SendToUser(tUser,"<"..sBot.."> *** Ошибка ! Режим блокировки кик- и бан-команд неактивен.") end end else if not bUsePassword or bRightPass then if TableLen(tBlockedNicks) == 0 then for _,v in pairs(RegMan.GetOps()) do tBlockedNicks[v.sNick] = true Core.SendToUser(tUser,"<"..sBot.."> *** Оптом заблокирован ник : "..v.sNick) end Core.SendToOps("<"..sBot.."> *** Блокировка кик- и бан-команд ВКЛЮЧЕНА.") else Core.SendToUser(tUser,"<"..sBot.."> *** Ошибка ! Режим блокировки кик- и бан-команд уже активирован!") end end end else Core.SendToUser(tUser,"<"..sBot.."> *** Stop bothering me with your useless cmds, stupid dork ! >:-]") end return true end if sData:find("<%S+> is kicking %S+ because:") and tBlockedNicks[tUser.sNick] or tBanCmds[sCmd] and BanCommandsCount(tUser,sCmd) then return true end if sCmd == sTestCmd then return true ; end end function KickArrival(tUser) if BanCommandsCount(tUser,"kick") then return true ; end end function ToArrival(tUser,sData) local text = sData:match("%$To:%s%S+%sFrom:%s%S+%s%$<%S+>%s(.-)$") if text and text:find("You are being kicked because:") and tBlockedNicks[tUser.sName] then return true ; end end -- Управляется из ChatArrival(tUser,sData) и KickArrival(tUser,sData): function BanCommandsCount(tUser,sCmd) if not tBlockedNicks[tUser.sNick] then if not tCount then tCount = {} ; end if not tCount[tUser.sNick] then tCount[tUser.sNick] = { iEndTime = iGlCnt + iProtectWithin, iCount = 1, iWithin = 0, nRatio = 0, fEachCountFunc = function(self) self.iWithin = self.iWithin + 1 if bExtReport then Core.SendToNick(sAdminNick, " Nick : "..tUser.sNick.."\t".. "Left : "..(self.iEndTime - iGlCnt).."\t".. "iWithin = "..self.iWithin.."\tnRatio : "..("%.3f"):format(self.nRatio)) end end,} else tCount[tUser.sNick].iCount = tCount[tUser.sNick].iCount + 1 tCount[tUser.sNick].nRatio = tCount[tUser.sNick].iWithin > 0 and tCount[tUser.sNick].iCount/tCount[tUser.sNick].iWithin or tCount[tUser.sNick].iCount -- Возвращаем true и блокируем дальнейшее прохождение команды в ChatArrival или KickArrival : if tCount[tUser.sNick].nRatio > nProtectRatio then SwitchToProtected(tUser.sNick,tCount[tUser.sNick].nRatio,sCmd) ; return true ; end end else Core.SendToOps("<"..sBot.."> *** ВНИМАНИЕ ! РЕЖИМ ЗАЩИТЫ. Блокировано событие :\r\n\tКоманда : "..sCmd.."\r\n\tЮзер : ".. "<"..tUser.sNick..">\r\n\tIP : [ "..tUser.sIP.." ]\r\n") return true end end function SwitchToProtected(sNick,nRatio,sCmd) tBlockedNicks[sNick] = true Core.SendToOps("<"..sBot.."> *** ВНИМАНИЕ ! Активирован режим блокировки кик- и бан-команд для ника <"..sNick.."> ".. "вследствие превышения количества кик/бан-команд в главном чате за установленное время !\r\n\t".. "Global Protect Threshold :\t"..iProtectCount.."/"..iProtectWithin.." ( "..("%.3f"):format(nProtectRatio).." )\r\n\t".. "Юзер :\t\t"..sNick.."\r\n\tПослед. команда :\t"..sCmd.."".. "\r\n\tCurrent Ratio :\t"..("%.3f"):format(nRatio).."\r\n") tCount[sNick] = nil end function TableLen(tTab) local c = 0 for k,_ in pairs(tTab) do c = c + 1 ; end return c end