PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Pingelmonster on 04 February, 2005, 14:07:27

Title: IP+Prefix checker
Post by: Pingelmonster on 04 February, 2005, 14:07:27
On my hub are 10/10Mbit users, they are in 4 ip-ranges. I want that they have a [nue.nl]-tag. I searched for a script, but they will allow people inside this range, and others wil be  disconnected. I want a scripts that checks for the tag [nue.nl], and others (outside the ranges) can connect without tag. Can u help me?
Title:
Post by: Pingelmonster on 04 February, 2005, 15:43:48
All right, i have this now, but it gives a error:


function Main()
   tPrefixIp = {}
   if readfrom("ipprefix/ipprefix.txt") then
      while 1 do
         local line = read()
         if line == nil then
            break
         end
         if strfind(line, "|") then
            local _,_,sStart,sEnd = strfind(line, "^([%.%d])|([%.%d])$")
            tPrefixIp[(IPtoDec(sStart))]=(IPtoDec(sEnd))
         else
            tPrefixIp[line]=1
         end
      end
      readfrom()
   else
      execute("mkdir ipprefix")
      writeto("ipprefix/ipprefix.txt")
      writeto()
   end[
end

function IPtoDec(IP)
   local s,e,dIP1,dIP2,dIP3,dIP4 = strfind(IP, "^(%d+)%.(%d+)%.(%d+)%.(%d+)$")
   IP = (tonumber(dIP1) * 16777216) + (tonumber(dIP2) *65536) + (tonumber(dIP3) * 256) + (tonumber(dIP4))
   return IP
end

function NewUserConnected(user)
   if tPrefixIp[user.sIP] then
     if (strlen(curUser.sName) >= 1 and strlower(strsub(curUser.sName,1,8)) ~= "[nue.nl]") or (strlen(curUser.sName) >= 1  and strlower(strsub(curUser.sName,1,12)) ~= "[SU][nue.nl]") then
curUser:SendData("*** Put this prefix in front of your nickname: [nue.nl]  and connect again to this hub!")
         curUser:Disconnect()
     else
        curUser:SendData(Bot,"Welcome to this hub!")
     end        
   else
      local sIp = IPtoDec(user.sIP)
      for a,b in tPrefixIp do
         if b ~= 1 and sIp >= a and sIp <= b then
            if (strlen(curUser.sName) >= 1 and strlower(strsub(curUser.sName,1,8)) ~= "[nue.nl]") or (strlen(curUser.sName) >= 1  and strlower(strsub(curUser.sName,1,12)) ~= "[SU][nue.nl]") then
       curUser:SendData("*** Put this prefix in front of your nickname: [nue.nl] or [SU][nue.nl] when regged and connect again to this hub!")
                curUser:Disconnect()
            else
                curUser:SendData(Bot,"Welcome to this hub!")
            end
         else
                curUser:SendData(Bot,"Welcome to this hub!")
         end
      end
   end
end



Error:
Syntax error: bad argument #1 to `strfind' (string expected, got nil)
stack traceback:
   1:  function `strfind' [C]
   2:  function `IPtoDec' at line 34 [file `D:\Program Files\Ptokax DC\scripts\ipcheck.lua']
   3:  function `Main' at line 20 [file `D:\Program Files\Ptokax DC\scripts\ipcheck.lua']
Title: nobody?:S
Post by: Pingelmonster on 05 February, 2005, 14:48:25
Nobody who can help me?

I want to have that my users that are in a specific IP-range wear the [nue.nl]-tag. Other users must be don't disconnected is they are outside the ranges.

Can somebody help me?