READ THE RULES
0 Members and 1 Guest are viewing this topic.
Inc = "NickName",
Inc = false,
--[[ OmniBlocker 1.0e LUA 5.1x [Strict][API 2] By Mutor 03/18/08 Yet another block bot, nothing new here but the code method. :P Naturally the same limitiations exist as the protocol is the same. -Blocks uploads and downloads from specified profiles or users -Exclusion table for protected nick within blocked profiles -Operator command/menu to toggle user block on/off -Both blocked/unblocked users are informed of a blocked xfer -Blocked user data saved to file for hub/script restarts. +Changes from 1.0 03/18/08 +Added search block for blocked users +Changes from 1.0b 05/31/08 +Added (optional) block/unblock toggle message to nick. Requested by ExtreeM +Changes from 1.0c 09/10/08 +Added option for user blocks to be permanent or not ~Extended fraudulent search to include free slot and TTH root +Changes from 1.0d 09/10/08 +Added option for a single nick that blocked users may download from. requested by merlin_xl54]]Cfg = {-- "BotName" ["" = hub bot]Bot = "[OmniBlock]",-- Bot descriptionDesc = "I block file transfers and searches",--Bot Email addressMail = "user@domain.com",-- Should bot have a key? true/falseBotIsOp = true,-- Admins nick for status / error messagesOpNick = "Mutor",--"Command SubMenu" ["" = script name]SubMenu = "",-- Context Menu Title ["" = hub name]Menu = "",-- File to save exlusion tableFile = Core.GetPtokaXPath().."scripts/OmniBlock.dat",-- Set your profiles / permissions here.-- profile_idx = true/false, [Block transfers, true = yes / false = no]Profiles = { [-1] = true, --Unregistered User [0] = false, --Master [1] = false, --Operator [2] = false, --Vip [3] = false, --Registered User },-- Exclude these nicks from checkExc = { ["Mutor"] = true, ["WebReg"] = true, },-- List here a single nick that blocked users may download from. ["Nick" as string or false = disable]Inc = false,-- Number of warns before user is kicked. [0 = disabled]MaxWarn = 7,-- Unblocking user in a blocked profile is temporary? true/false [per script session]TempBlock = true,}local Xfer,Search = {},{}OnStartup = function() Cfg.MaxWarn,Cfg.Scp = math.min(Cfg.MaxWarn,10),"OmniBlocker 1.0e" if Cfg.Bot == "" then Cfg.Bot = SetMan.GetString(21) end if Cfg.Menu == "" then Cfg.Menu = SetMan.GetString(0) end if Cfg.SubMenu == "" then Cfg.SubMenu = Cfg.Scp end if Cfg.Bot ~= SetMan.GetString(21) then Core.RegBot(Cfg.Bot, Cfg.Desc,Cfg.Mail,Cfg.BotIsOp) end if loadfile(Cfg.File) then dofile(Cfg.File) else Block = {} Save() end local chg = false for _,user in ipairs(Core.GetOnlineUsers()) do local Chk = function(nick) for i,v in pairs(Block) do if i:lower() == nick:lower() then return true end end end local p,n = user.iProfile,user.sNick if not Cfg.Exc[n] then if Cfg.Profiles[p] then if Cfg.TempBlock then if not Block[n] then Block[n] = true chg = true end else if not Chk(n) then Block[n] = true chg = true end end end end end for n,v in pairs(Block) do local t,p = RegMan.GetReg(n),-1 if t then p = t.iProfile end if Cfg.Exc[n] or not Cfg.Profiles[p] then Block[n] = nil chg = true end end if chg then Save() end assert(loadfile(Cfg.File))endOnError = function(msg) local user = Core.GetUser(Cfg.OpNick) if user then Core.SendToUser(user,"<"..Cfg.Bot.."> "..msg.."|") endendUserConnected = function(user) local p,n,pfx = user.iProfile,user.sNick,SetMan.GetString(29):sub(1,1) if p and n and pfx then if not Cfg.Exc[n] then if Cfg.Profiles[p] and not Block[n] then Block[n] = true Save() end end if Core.GetUserValue(user,11) then local uc = "$UserCommand 1 1 "..Cfg.Menu.."\\"..Cfg.SubMenu.."\\Toggle User Block".. "$<%[mynick]> "..pfx.."block %[line:Nickname (Case Sensitive)]||$UserCommand 1 2 ".. Cfg.Menu.."\\"..Cfg.SubMenu.."\\Toggle User Block".."$<%[mynick]> "..pfx.."block %[nick] ".. "%[line: Reason (Optional)]||" Core.SendToUser(user,uc) end else return true endendOpConnected,RegConnected = UserConnected,UserConnectedUserDisconnected = function(user) if Xfer[user.sNick] then if Xfer[user.sNick] >= Cfg.MaxWarn then Xfer[user.sNick] = nil end end if Search[user.sNick] then if Search[user.sNick] >= Cfg.MaxWarn then Search[user.sNick] = nil end endendRegDisconnected, OpDisconnected = UserDisconnected,UserDisconnectedChatArrival = function(user,data) if Core.GetUserValue(user,11) then local _,_,cmd = data:lower():find("^%b<> (["..SetMan.GetString(29).."]block) ") local _,_,nick = data:find("^%b<> [^ ]+ ([^ |]+)|?") local _,_,rsn = data:find("^%b<> [^ ]+ [^ ]+ ([^|]+)|$") if cmd and nick then local tab = RegMan.GetReg(nick) if not tab or not ProfMan.GetProfile(tab.iProfile).tProfilePermissions.bIsOP then local x,t = Block[nick],{["true"]= "blocked",["false"] = "unblocked"} if x then x = false else x = true end Block[nick] = x local s = t[tostring(x)] if rsn then local usr = Core.GetUser(nick) local prof = ProfMan.GetProfile(user.iProfile).sProfileName if usr then Core.SendToUser(usr,"<"..Cfg.Bot.."> Your search and transfers ".. "are being "..s.." by "..prof.." "..user.sNick.." because:"..rsn.."|") end end return Save(),Core.SendToUser(user,"<"..Cfg.Bot.."> "..nick.. "'s transfers are "..s.."|"),true end end endendConnectToMeArrival = function(user,data) local p,n = user.iProfile,user.sNick local Ctms = {[1] = "^$ConnectToMe ([^ ]-) ",[2] = "^$RevConnectToMe [^ ]- (.+)",} if Block[n] then if Cfg.Inc then for i,v in ipairs(Ctms) do local _,_,s = data:sub(1,-2):find(v) if s and s:lower() == Cfg.Inc:lower() then return end end end if Cfg.MaxWarn > 0 then if Xfer[n] then Xfer[n] = Xfer[n] + 1 else Xfer[n] = 1 end if Xfer[n] >= Cfg.MaxWarn then return Core.Kick(user,Cfg.Bot,Cfg.MaxWarn.."x blocked transfer attempts."),true end end return Core.SendToUser(user,"<"..Cfg.Bot.."> Your transfers are blocked. ".. "Please clear this transfer from your download queue. Thank you.|"),true end for i,v in ipairs(Ctms) do local _,_,s = data:sub(1,-2):find(v) if s and Block[s] then return Core.SendToUser(user,"<"..Cfg.Bot.."> You requested a file from ".. s:format("%q")..", transfers from this user are blocked.|"), Core.SendToUser(user,"<"..Cfg.Bot.."> Please clear "..string.format("%q",s).. " from your download queue. Thank you.|"),true end endendRevConnectToMeArrival = ConnectToMeArrivalSearchArrival = function (user,data) local p,n = user.iProfile,user.sNick if Block[n] then if Cfg.MaxWarn > 0 then if Search[n] then Search[n] = Search[n] + 1 else Search[n] = 1 end if Search[n] >= Cfg.MaxWarn then return Core.Kick(user,Cfg.Bot,Cfg.MaxWarn.."x blocked search attempts."),true end end local _,_,search = string.find(data,"([^?]+)|$") if search then local t = "TTH:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"--hash(t) in lieu of hub(h) local h,b,i,u = SetMan.GetString(0),SetMan.GetString(21), SetMan.GetString(3):gsub(";.*",""),SetMan.GetString(4) local res = "Unknown Path"..string.char(92)..n..", search is ".. "disabled for you :P "..string.rep("\t",15)..search return Core.SendToUser(user,"$SR "..b.." "..res.." 0 1/2"..t.." ("..i..":"..u..")|".. "<"..Cfg.Bot.."> "..n..", search is disabled for you. Please close the ".. string.format("%q",search:gsub("%$"," ")).." search window. Thank you.|"),true end return true endendSaveFile = function(File,table, tablename ) local hFile = io.open (File , "wb") assert(hFile) Serialize(table, tablename, hFile) hFile:flush() hFile:close() collectgarbage("collect")endSerialize = function(tTable, sTableName, hFile, sTab) sTab = sTab or ""; hFile:write(sTab..sTableName.." = {\n" ) for key, value in pairs(tTable) do local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key) if(type(value) == "table") then Serialize(value, sKey, hFile, sTab.."\t") else local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value) hFile:write( sTab.."\t"..sKey.." = "..sValue) end hFile:write( ",\n") end hFile:write( sTab.."}")endSave = function() SaveFile(Cfg.File,Block,"Block") end
The same nick cannot be listed twice in the Block table.
Profiles = { [-1] = true, --Unregistered User [0] = false, --Owner [1] = false, --Admin [2] = false, --SOP [3] = false, --OP [4] = false, --VIP-OP [5] = false, --VIP },
--[[ OmniBlocker 1.0g LUA 5.1x [Strict][API 2] By Mutor 03/18/08 Yet another block bot, nothing new here but the code method. :P Naturally the same limitiations exist as the protocol is the same. -Blocks uploads and downloads from specified profiles or users -Exclusion table for protected nick within blocked profiles -Operator command/menu to toggle user block on/off -Both blocked/unblocked users are informed of a blocked xfer -Blocked user data saved to file for hub/script restarts. +Changes from 1.0 03/18/08 +Added search block for blocked users +Changes from 1.0b 05/31/08 +Added (optional) block/unblock toggle message to nick. Requested by ExtreeM +Changes from 1.0c 09/10/08 +Added option for user blocks to be permanent or not ~Extended fraudulent search to include free slot and TTH root +Changes from 1.0d 09/10/08 +Added option for a single nick that blocked users may download from. requested by merlin_xl54 +Changes from 1.0f 04/04/10 ~Blocking searches now optional, requested by 4uvak91]]Cfg = {-- "BotName" ["" = hub bot]Bot = "[OmniBlock]",-- Bot description ["" = script name]Desc = "I block file transfers and searches",--Bot Email addressMail = "user@domain.com",-- Should bot have a key? true/falseBotIsOp = true,-- Admins nick for status / error messagesOpNick = "Mutor",--"Command SubMenu" ["" = script name]SubMenu = "",-- Context Menu Title ["" = hub name]Menu = "",-- File to save exlusion tableFile = "OmniBlock.dat",-- Set your profiles / permissions here.-- profile_idx = true/false, [Block transfers, true = yes / false = no]Profiles = { [-1] = true, --Unregistered User [0] = false, --Master [1] = false, --Operator [2] = false, --Vip [3] = false, --Registered User },-- Block Searches from blocked users also? [false = Search enabled]NoSearch = true,-- Exclude these nicks from checkExc = { ["Mutor"] = true, ["WebReg"] = true, },-- List here a single nick that blocked users may download from. ["Nick" as string or false = disable]Inc = false,-- Number of warns before user is kicked. [0 = disabled]MaxWarn = 7,-- Unblocking user in a blocked profile is temporary? true/false [per script session]TempBlock = true,-- Always send script replies in private message?OnlyPm = true,}local Xfer,Search = {},{}OnStartup = function() Cfg.MaxWarn,Cfg.Scp,Cfg.Path = math.min(Cfg.MaxWarn,10),"OmniBlocker 1.0g",Core.GetPtokaXPath().."scripts/" if Cfg.Menu == "" then Cfg.Menu = SetMan.GetString(0) end if Cfg.SubMenu == "" then Cfg.SubMenu = Cfg.Scp end if Cfg.Desc == "" then Cfg.Desc = Cfg.Scp end if Cfg.Bot == "" then Cfg.Bot = SetMan.GetString(21) else Core.RegBot(Cfg.Bot,Cfg.Desc,Cfg.Mail,Cfg.BotIsOp) end if not Cfg.File:find("^"..Cfg.Path,1,true) then Cfg.File = Cfg.Path..Cfg.File end if loadfile(Cfg.File) then dofile(Cfg.File) else Block = {} Save() end local chg = false for _,user in ipairs(Core.GetOnlineUsers()) do local Chk = function(nick) for i,v in pairs(Block) do if i:lower() == nick:lower() then return true end end end local p,n = user.iProfile,user.sNick if not Cfg.Exc[n] then if Cfg.Profiles[p] then if Cfg.TempBlock then if not Block[n] then Block[n] = true chg = true end else if not Chk(n) then Block[n] = true chg = true end end end end end for n,v in pairs(Block) do local t,p = RegMan.GetReg(n),-1 if t then p = t.iProfile end if Cfg.Exc[n] or not Cfg.Profiles[p] then Block[n] = nil chg = true end end if chg then Save() end if not Cfg.NoSearch then SearchArrival = nil end assert(loadfile(Cfg.File))endOnError = function(msg) local user = Core.GetUser(Cfg.OpNick) if user then Core.SendToUser(user,"<"..Cfg.Bot.."> "..msg.."|") endendUserConnected = function(user) local p,n,pfx = user.iProfile,user.sNick,SetMan.GetString(29):sub(1,1) if p and n and pfx then if not Cfg.Exc[n] then if Cfg.Profiles[p] and not Block[n] then Block[n] = true Save() end end if Core.GetUserValue(user,11) then local uc,p,cmd = "$UserCommand 1 1 "..Cfg.Menu.."\\"..Cfg.SubMenu.."\\","||","" local t = { {"Toggle User Block","block"," %[line:Nickname (Case Sensitive)]"," %[nick] %[line: Reason (Optional)]"}, {"Check User Block","chkblock"," %[line:Nickname]"," %[nick]"},{"List Blocked Users","listblock","",""}, } for i,v in ipairs(t) do cmd = cmd..uc..v[1].."$<%[mynick]> "..pfx..v[2]..v[3]..p.. uc:gsub(" 1 1"," 1 2")..v[1].."$<%[mynick]> "..pfx..v[2]..v[4]..p end if cmd ~= "" then Core.SendToUser(user,cmd) end end else return true endendOpConnected,RegConnected = UserConnected,UserConnectedUserDisconnected = function(user) if Xfer[user.sNick] then if Xfer[user.sNick] >= Cfg.MaxWarn then Xfer[user.sNick] = nil end end if Search[user.sNick] then if Search[user.sNick] >= Cfg.MaxWarn then Search[user.sNick] = nil end endendRegDisconnected, OpDisconnected = UserDisconnected,UserDisconnectedChatArrival = function(user,data) if Core.GetUserValue(user,11) then local _,_,to = data:find("^$To: (%S+) From:") local _,_,cmd = data:lower():find("%b<> ["..SetMan.GetString(29).."](%a+)") local _,_,nick = data:find("^%b<> [^ ]+ ([^ |]+)|?") local _,_,rsn = data:find("^%b<> [^ ]+ [^ ]+ ([^|]+)|$") if cmd then if cmd == "block" and nick then local tab = RegMan.GetReg(nick) if not tab or not ProfMan.GetProfile(tab.iProfile).tProfilePermissions.bIsOP then local x,t = Block[nick],{["true"]= "blocked",["false"] = "unblocked"} if x then x = false else x = true end Block[nick] = x local s = t[tostring(x)] if rsn then local usr = Core.GetUser(nick) local prof = ProfMan.GetProfile(user.iProfile).sProfileName if usr then local msg = "Your search and transfers are being "..s.. " by "..prof.." "..user.sNick.." because:"..rsn.."|" if Cfg.OnlyPm then Core.SendPmToUser(usr,Cfg.Bot,msg) else Core.SendToUser(usr,"<"..Cfg.Bot.."> "..msg) end end end Save() local reply = nick.."'s transfers are now "..s.."|" if to and to == Cfg.Bot then Core.SendPmToUser(usr,Cfg.Bot,reply) else return Core.SendToUser(user,"<"..Cfg.Bot.."> "..reply),true end end elseif cmd == "chkblock" and nick then local t = {["true"]= "blocked",["false"] = "unblocked",["nil"] = "not set by script",} local s = t[tostring(Block[nick])] local reply = nick.."'s transfers are now "..s.."|" if to and to == Cfg.Bot then Core.SendPmToUser(usr,Cfg.Bot,reply) else return Core.SendToUser(user,"<"..Cfg.Bot.."> "..reply),true end elseif cmd == "listblock" then local s,t,b,u,x,r = "",{["true"]= "blocked",["false"] = "unblocked"},{},{},0,"¯" for k,v in pairs(Block) do if tostring(Block[k]) == "true" then table.insert(b,k) else table.insert(u,k) end --s = s.."\n\t"..k.." is "..t[tostring(Block[k])] end if next (b) then local pl = "s" if #b == 1 then pl = "" end s = s.."\n\n\t"..tostring(#b).." Blocked User"..pl..":\n\t"..r:rep(80).."\n" for i = 1, #b do if x == 0 then s = s.."\n" end x = x + 1 if x < 4 then s = s.."\t"..string.format("%-20.10s\t\t",b[i]) else x = 0 s = s.."\n" end end end if next(u) then local pl = "s" if #u == 1 then pl = "" end s = s.."\n\n\t"..tostring(#u).." Unblocked User"..pl..":\n\t"..r:rep(80).."\n" for i = 1, #u do if x == 0 then s = s.."\n" end x = x + 1 if x < 4 then s = s.."\t"..string.format("%-20.10s\t\t",u[i]) else x = 0 s = s.."\n" end end end if s == "" then s = "No results.|" else s = "Listing Users:"..s.."\n\n\t"..r:rep(80).."\n|" end if to and to == Cfg.Bot then Core.SendPmToUser(usr,Cfg.Bot,reply) else return Core.SendToUser(user,"<"..Cfg.Bot.."> "..s),true end end end endendToArrival = ChatArrivalConnectToMeArrival = function(user,data) local p,n = user.iProfile,user.sNick local Ctms = {[1] = "^$ConnectToMe ([^ ]-) ",[2] = "^$RevConnectToMe [^ ]- (.+)",} if Block[n] then if Cfg.Inc then for i,v in ipairs(Ctms) do local _,_,s = data:sub(1,-2):find(v) if s and s:lower() == Cfg.Inc:lower() then return end end end if Cfg.MaxWarn > 0 then if Xfer[n] then Xfer[n] = Xfer[n] + 1 else Xfer[n] = 1 end if Xfer[n] >= Cfg.MaxWarn then return Core.Kick(user,Cfg.Bot,Cfg.MaxWarn.."x blocked transfer attempts."),true end end local msg = "Your transfers are blocked. Please clear this transfer from your download queue. Thank you.|" if Cfg.OnlyPm then return Core.SendPmToUser(user,Cfg.Bot,msg),true else return Core.SendToUser(user,"<"..Cfg.Bot.."> "..msg),true end end for i,v in ipairs(Ctms) do local _,_,s = data:sub(1,-2):find(v) if s and Block[s] then local msg1,msg2 = "You requested a file from "..s:format("%q")..", transfers from this user are blocked.|", "Please clear "..string.format("%q",s).." from your download queue. Thank you.|" if Cfg.OnlyPm then return Core.SendPmToUser(user,Cfg.Bot,msg1), Core.SendPmToUser(user,Cfg.Bot,msg2),true else return Core.SendToUser(user,"<"..Cfg.Bot.."> "..msg1), Core.SendToUser(user,"<"..Cfg.Bot.."> "..msg2),true end end endendRevConnectToMeArrival = ConnectToMeArrivalSearchArrival = function (user,data) local p,n = user.iProfile,user.sNick if Block[n] then if Cfg.MaxWarn > 0 then if Search[n] then Search[n] = Search[n] + 1 else Search[n] = 1 end if Search[n] >= Cfg.MaxWarn then return Core.Kick(user,Cfg.Bot,Cfg.MaxWarn.."x blocked search attempts."),true end end local _,_,search = string.find(data,"([^?]+)|$") if search then local t = "TTH:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"--hash(t) in lieu of hub(h) local h,b,i,u = SetMan.GetString(0),SetMan.GetString(21), SetMan.GetString(3):gsub(";.*",""),SetMan.GetString(4) local res = "Unknown Path"..string.char(92)..n..", search is ".. "disabled for you :P "..string.rep("\t",15)..search return Core.SendToUser(user,"$SR "..b.." "..res.." 0 1/2"..t.." ("..i..":"..u..")|".. "<"..Cfg.Bot.."> "..n..", search is disabled for you. Please close the ".. string.format("%q",search:gsub("%$"," ")).." search window. Thank you.|"),true end return true endendSaveFile = function(File,table, tablename ) local hFile = io.open (File , "wb") assert(hFile) Serialize(table, tablename, hFile) hFile:flush() hFile:close() collectgarbage("collect")endSerialize = function(tTable, sTableName, hFile, sTab) sTab = sTab or ""; hFile:write(sTab..sTableName.." = {\n" ) for key, value in pairs(tTable) do local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key) if(type(value) == "table") then Serialize(value, sKey, hFile, sTab.."\t") else local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value) hFile:write( sTab.."\t"..sKey.." = "..sValue) end hFile:write( ",\n") end hFile:write( sTab.."}")endSave = function() SaveFile(Cfg.File,Block,"Block") end
I meant, that unreg user can't use search & download from others in the hub, but OP still can get unreg's filelist!
If you allow the op to get the user's file list, that user can then download from the op.This is the nature of the NMDC protocol. You can't selectively block the transfer betweenclients with hubside script.
-- List here a single nick that blocked users may download from. ["Nick" as string or false = disable]Inc = false,