PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: ?(???[AD]???)?Angel on 15 March, 2005, 08:54:06

Title: Help set in LUA 5
Post by: ?(???[AD]???)?Angel on 15 March, 2005, 08:54:06
Kann das mal bitte einer in LUA % umwandeln?

--// a peerguardian script ..
--// by Typhoon?/Ratcom_Typhoon?
--// 09-05-2004
--// idea and code from NXS-4 by NightLitch

---- setup

GuardianCheck = 1
notifyOps = 1

---- setup end

BotName = "GetHubBotName"

GuardianFile = "peerfolder/guarding.p2p"

Guard = {}

function Main()
       LoadTable(Guard,GuardianFile)  
end


function NewUserConnected(curUser)
   if GuardianCheck==1 then
      local check,comp = BlockGuard(curUser.sIP)
      if notifyOps==1 then
         curUser:Disconnect(BotName, "You are beeing disconnected!")
         SendPmToOps(BotName,"User "..curUser.sName.." - ( "..curUser.sIP.." ) from Company ( "..comp.." ) tried to login and was disconnected by "..BotName.."!")
         curUser:Ban()
      end
   end
end



function BlockGuard(ip)
   local _,_,a,b,c,d = strfind(ip, "(%d*).(%d*).(%d*).(%d*)")
   if ( tonumber(a) and tonumber(b) and tonumber(c) and tonumber(d) ) then
      local uip = ComputeIP(ip)
      if uip then
         for range,comp in Guard do
            local _,_,r1,r2 = strfind(range, "(.*)-(.*)")
            r1 = ComputeIP(r1)
            r2 = ComputeIP(r2)
            if uip>=r1 and uip<=r2 then
               return 1,comp
            end
         end
      end
   end
end

function ComputeIP(curIP)
   local _,_,a,b,c,d = strfind(curIP, "(%d+).(%d+).(%d+).(%d+)")
   return a*16777216 + b*65536 + c*256 + d
end

function LoadTable(table,file)
   local handle = openfile(file, "r")
   if (handle) then
          local line = read(handle)
          while line do
         s,e,ind,val = strfind( line, "(.*):(.*)")
         table[val]=ind
         line = read(handle)
          end
        closefile(handle)
   end
end
Title:
Post by: NightLitch on 15 March, 2005, 09:13:09
--// a peerguardian script ..
--// by Typhoon?/Ratcom_Typhoon?
--// 09-05-2004
--// idea and code from NXS-4 by NightLitch
--// Rewritten to Lua 5 by NightLitch 2005-03-15

---- setup

BotName = "GetHubBotName"
GuardianFile = "peerfolder/guarding.p2p"

GuardianCheck = 1
notifyOps = 1

---- setup end

Guard = {}

function Main()
LoadTable(Guard,GuardianFile)
end

function NewUserConnected(curUser)
if GuardianCheck==1 then
local check,comp = BlockGuard(curUser.sIP)
if check == 1 then
curUser:Disconnect(BotName, "You are beeing disconnected!")
curUser:Ban()
if notifyOps==1 then
SendPmToOps(BotName,"User "..curUser.sName.." - ( "..curUser.sIP.." ) from Company ( "..comp.." ) tried to login and was disconnected by "..BotName.."!")
end
end
end
end







function BlockGuard(ip)
local _,_,a,b,c,d = string.find(ip, "(%d*).(%d*).(%d*).(%d*)")
if ( tonumber(a) and tonumber(b) and tonumber(c) and tonumber(d) ) then
local uip = ComputeIP(ip)
if uip then
for range,comp in Guard do
local _,_,r1,r2 = string.find(range, "(.*)-(.*)")
r1 = ComputeIP(r1)
r2 = ComputeIP(r2)
if uip>=r1 and uip<=r2 then
return 1,comp
end
end
end
end
return 0,""
end



function ComputeIP(curIP)
local _,_,a,b,c,d = string.find(curIP, "(%d+).(%d+).(%d+).(%d+)")
return a*16777216 + b*65536 + c*256 + d
end

function LoadTable(table,file)
local handle = io.open(file, "r")
if (handle) then
for line in handle:lines() do
local s,e,ind,val = string.find(line, "(.*):(.*)")
table[val] = ind
end
handle:close()
end
end

** CODE UPDATED **

Cheers / NightLitch
Title: help
Post by: ?(???[AD]???)?Angel on 15 March, 2005, 09:35:59
PeerGuardian.lua

syntax error ?=?

for yu  new lua5
Title: Danke
Post by: ?(???[AD]???)?Angel on 15 March, 2005, 09:43:37
heheheheheh

code:--------------------------------------------------------------------------------



ich bin zu doof.

juhu

tanks

werry good