Author Topic: ip range-description  (Read 4964 times)

0 Members and 1 Guest are viewing this topic.

Offline gia

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
ip range-description
« on: 09 April, 2007, 14:15:21 »
hello.
this script changes description of the user on "Net_1, Net_2, Net_3" depending on range IP

Code: [Select]
-- BotName --
HubBot = frmHub:GetHubBotName()
--time after user connect to overwrite the description
TimeOverWrite = 1 -- time in second
-- range ip overwrite ="begin ip range-end ip range-description"
-- not teste whit space in description
RangeDesc = {[1]="10.0.0.0-10.255.255.255-Net_1", [2]="89.105.0.0-89.105.255.254-Net_2", [3]="172.20.0.0-172.20.255.255-Net_3"}

-- Info Path --
InfoLog = "UserInfo/" -- Create this folder before starting the script

function Main()
   SetTimer(TimeOverWrite*1000)
end
   
-- New User Connect Info Arrival
function MyINFOArrival(curUser,data)
if GetTimer() == nil then StartTimer() end
end

function OnTimer()
   OverWrite(HubBot)
   StopTimer()
end

function rebuilmyinfo(curUser)
   local descript,userip = nil,calcip(curUser.sIP)
   if userip ~= 0 then
         for index,descIP in pairs(RangeDesc) do
            local _,_,startRange,endRange,RangeDescript = string.find(descIP, "(.*)-(.*)-(.*)")
            startRange = calcip(startRange)
            endRange = calcip(endRange)
            if userip>=startRange and userip<=endRange then
               descript = RangeDescript
            end
         end
      if descript == nil then descript = "Extern" end
      local _,_,nick,orgdescr,rest = string.find(curUser.sMyInfoString, "$MyINFO $ALL (%S+)%s+([^$]*)<(.*)")
      SendToAll("$MyINFO $ALL "..nick.." "..descript.."<"..rest)
      end
end

function calcip(ipcalc)
   local _,_,a,b,c,d = string.find(ipcalc, "(%d+).(%d+).(%d+).(%d+)")
   local calc = 0
   if (tonumber(a) and tonumber(b) and tonumber(c) and tonumber(d)) then
      calc = a*16777216 + b*65536 + c*256 + d   
      return calc
      else return 0
   end
end

function OverWrite(curUser)
   local tableover = frmHub:GetOnlineUsers()
   for i, Userover in pairs(tableover) do
      rebuilmyinfo(Userover)
   end
end

possible do so "Net_1...etc." was added to description, rather then changed it?
thank.

PtokaX forum

ip range-description
« on: 09 April, 2007, 14:15:21 »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: ip range-description
« Reply #1 on: 10 April, 2007, 00:27:21 »
Moved to Finished, thanks for the submission.
Everything could have been anything else and it would have just as much meaning.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: ip range-description
« Reply #2 on: 10 April, 2007, 09:19:19 »
possible do so "Net_1...etc." was added to description, rather then changed it?
thank.

Maybe trying

Code: [Select]
      SendToAll("$MyINFO $ALL "..nick.." "..orgdescr.." "..descript.."<"..rest)
instead of

Code: [Select]
      SendToAll("$MyINFO $ALL "..nick.." "..descript.."<"..rest)
As line 39
« Last Edit: 10 April, 2007, 09:21:49 by Naithif »

Offline gia

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: ip range-description
« Reply #3 on: 10 April, 2007, 12:45:36 »
Maybe trying

Code: [Select]
      SendToAll("$MyINFO $ALL "..nick.." "..orgdescr.." "..descript.."<"..rest)
instead of

Code: [Select]
      SendToAll("$MyINFO $ALL "..nick.." "..descript.."<"..rest)
As line 39

thank you, Naithif !
This works.

Offline sphinx_spb

  • Member
  • ***
  • Posts: 47
  • Karma: +10/-3
Re: ip range-description
« Reply #4 on: 21 May, 2007, 03:24:56 »
This scripts results error:
Code: [Select]
[05:12] Syntax C:\ptokax\scripts\iprange.lua:39: attempt to concatenate global 'rest' (a nil value)What can I do about it? ???

Offline sphinx_spb

  • Member
  • ***
  • Posts: 47
  • Karma: +10/-3
Re: ip range-description
« Reply #5 on: 22 May, 2007, 12:43:59 »
Thanks, Mutor! Now it works great.
But, with this script Ptokax starts lag very hard... ???
Even chat is lagged, so I forced to switch the script off  :'(

Offline wlfdark

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
ip range-description
« Reply #6 on: 01 December, 2011, 17:22:06 »
crash attempt to call global 'GetTimer' (a nil value), , can you help?


Code: [Select]
???????? ?????????? PtokaX LUA API ????????? v0.9. ??????? ?????? 08/29/09 21:09:22
-- BotName --
HubBot = SetMan.GetString(21)
--time after user connect to overwrite the description
TimeOverWrite = 10 -- time in second
-- range  ip  overwrite ="begin ip range-end ip range-description"
-- not teste whit space in description
RangeDesc = {
[1]="10.202.0.0-10.202.255.255-[???????]", -- ???????? ????? ???? ???????? ? ???????? ???? (??? ???????), ????? ?????????? ??? ?? ??? ????????? ??????? , ?????????? ? ?????????
[2]="172.20.0.0-172.20.255.255-[???????]", -- ? ??? ????? , ?????? ??????? ????? ????????? ?? ???????????? )) , ? ???? ?????? ????? 130 ??????????
[3]="192.168.0.0-192.168.255.255-[???????]",
[4]="10.239.0.0-10.239.255.255-[??????????]",
}

-- Info Path --
InfoLog = "UserInfo/" -- Create this folder before starting the script

function OnStartup()

end

-- New User Connect Info Arrival
function MyINFOArrival(curUser,data)
Core.GetUserAllData(curUser)
if GetTimer() == nil then StartTimer() end
end

function OnTimer(tmr)
OverWrite(HubBot)
TmrMan.RemoveTimer(tmr)
end

function rebuilmyinfo(curUser)
local descript,userip = nil,calcip(curUser.sIP)
if userip ~= 0 then
for index,descIP in pairs(RangeDesc) do
local _,_,startRange,endRange,RangeDescript = string.find(descIP, "(.*)-(.*)-(.*)")
startRange = calcip(startRange)
endRange = calcip(endRange)
if userip>=startRange and userip<=endRange then
descript = RangeDescript
end
end
if descript == nil then descript = "[??]" end -- ? ??????? ???????? ??? ??????????? ???? (????? ???? , ?????? ??? ???????)
local s,e,nick,desc,speed,email,share = string.find(curUser.sMyInfoString, "$MyINFO $ALL (%S+)%s+([^$]*)$ $([^$]*)$([^$]*)$([^$]+)")
local addtag = tProfileTag[curUser.iProfile].." "..descript
Core.SendToAll("$MyINFO $ALL "..nick.." "..addtag.." "..desc.."$ $"..speed.."$"..email.."$"..share.."$")
end
end


function calcip(ipcalc)
local _,_,a,b,c,d = string.find(ipcalc, "(%d+).(%d+).(%d+).(%d+)")
local calc = 0
if (tonumber(a) and tonumber(b) and tonumber(c) and tonumber(d)) then
calc = a*16777216 + b*65536 + c*256 + d
return calc
else return 0
end
end

function OverWrite(curUser)
local tableover = Core.GetOnlineUsers(true)
for i, Userover in pairs(tableover) do
rebuilmyinfo(Userover)
end
end


Edit: Please use Code Tags when posting Code ;)
« Last Edit: 02 December, 2011, 21:40:46 by Psycho_Chihuahua »

PtokaX forum

ip range-description
« Reply #6 on: 01 December, 2011, 17:22:06 »