PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: MetalPriest on 27 May, 2004, 13:30:49

Title: PeerGuardian Script !!! Help Help
Post by: MetalPriest on 27 May, 2004, 13:30:49
Hello !!

Get some error in this script

------------------------------------------------------------------------
--// 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 = frmHub: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, "bye bye")
         SendPmToOps(BotName,"*** "..curUser.sName.." - ( "..curUser.sIP.." ) from Company ( "..comp.." ) tried to login! ***")
      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
------------------------------------------------------------------------
Syntax error: attempt to concat local `comp' (a nil value)
stack traceback:
   1:  function `NewUserConnected' at line 29 [file `...okaX-0.330 build 15.25\scripts\PeerGuardian.lua']

So if someone can help me !!

MetalPriest




Title:
Post by: nErBoS on 27 May, 2004, 13:35:53
Hi,

Try this one...

--// 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 = frmHub:GetHubBotName()

GuardianFile = "peerfolder/Guarding.P2P"

Guard = {}

function Main()
LoadTable(Guard,GuardianFile)
end


function NewUserConnected(curUser)
if GuardianCheck==1 then
local comp = BlockGuard(curUser.sIP)
if notifyOps==1 then
curUser:Disconnect(BotName, "bye bye")
SendPmToOps(BotName,"*** "..curUser.sName.." - ( "..curUser.sIP.." ) from Company ( "..comp.." ) tried to login! ***")
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

Best regards, nErBoS
Title:
Post by: MetalPriest on 27 May, 2004, 13:39:13
Huuuu Nerbos this was fast ...

Thanks !!!

MetalPriest
Title:
Post by: MetalPriest on 27 May, 2004, 13:44:45
Same **** error come up again..

Hmm...

MetalPriest
Title:
Post by: nErBoS on 27 May, 2004, 16:11:28
Hi,

The script is was ok...

--// 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 = frmHub: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, "bye bye")
SendPmToOps(BotName,"*** "..curUser.sName.." - ( "..curUser.sIP.." ) from Company ( "..comp.." ) tried to login! ***")
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

I belive that the probelm is the table isn't being loaded. Can you show me what you have in "peerfolder/Guarding.P2P" ??

Best regards, nErBoS
Title:
Post by: MetalPriest on 27 May, 2004, 17:19:57
ok.. No Problem..

I have only Guardian.p2p file there...

No table file in folder

looks like script can't read it...

Found this script on plops site..

MetalPriest
Title:
Post by: nErBoS on 28 May, 2004, 13:01:35
Hi,

The script is given erro because the table is empty, should have something i think.

Best regards, nErBoS
Title:
Post by: MetalPriest on 28 May, 2004, 18:45:52
Thanks Nerbos

Have play with it and check some things..

My code goes here..
--------------------------------------------------------------------
BotName = frmHub:GetHubBotName()
----------------------------------------------------------------------------------------------
GuardianFile = "Guard/Guarding.P2P"
Guard = {}
Guardian = 1
----------------------------------------------------------------------------------------------
--//Code
----------------------------------------------------------------------------------------------
function Main()
LoadGuard(Guard,GuardianFile)
frmHub:RegBot(BotName)
end
----------------------------------------------------------------------------------------------
function NewUserConnected(User)
if GuardianCheck==1 then
      local check,comp = BlockGuard(User.sIP)
      if check==1 then
         SendPmToOps(nBotName,"*** "..User.sName.." - ( "..User.sIP.." ) from Company ( "..comp.." ) tried to login! ***")
         check = 0
      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 LoadGuard(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
----------------------------------------------------------------------------------------------
This work !!!!
MetalPriest