hello.
this script changes description of the user on "Net_1, Net_2, Net_3" depending on range IP
-- 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.
Moved to Finished, thanks for the submission.
Quote from: gia on 09 April, 2007, 14:15:21
possible do so "Net_1...etc." was added to description, rather then changed it?
thank.
Maybe trying
SendToAll("$MyINFO $ALL "..nick.." "..orgdescr.." "..descript.."<"..rest)
instead of
SendToAll("$MyINFO $ALL "..nick.." "..descript.."<"..rest)
As line 39
Quote from: Naithif on 10 April, 2007, 09:19:19
Maybe trying
SendToAll("$MyINFO $ALL "..nick.." "..orgdescr.." "..descript.."<"..rest)
instead of
SendToAll("$MyINFO $ALL "..nick.." "..descript.."<"..rest)
As line 39
thank you, Naithif !
This works.
This scripts results error:
[05:12] Syntax C:\ptokax\scripts\iprange.lua:39: attempt to concatenate global 'rest' (a nil value)
What can I do about it? ???
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 :'(
crash attempt to call global 'GetTimer' (a nil value), , can you help?
???????? ?????????? 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 ;)