PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: daft009 on 14 March, 2004, 03:33:43

Title: users and their IPs
Post by: daft009 on 14 March, 2004, 03:33:43
hi,

i've tried searching but couldnt find anything so am posting here.

i would like a simple script which gives me the IPs of all users currently connected to the hub (or IPs of all users registered)

i currently use L.I.S and NXS-3, both of which i dont think can do it.

it should give a result like this.

Quoteusername: IP
username: IP
...
...
...

thanks
Title:
Post by: nErBoS on 14 March, 2004, 19:52:29
Hi,

Hope it helps...

--Requested by daft009
--Made by nErBoS

Bot = "IPs-Connected"

connectedusers = "users.txt"

function Main()
frmHub:RegBot(Bot)
end

function NewUserConnected(user, data)
DealUser(user, data, "ADD")
end

function UserDisconnected(user, data)
DealUser(user, data, "REMOVE")
end

OpConnected = NewUserConnected
OpDisconnected = UserDisconnected

function DataArrival(user, data)
if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd=="!allips") then
user:SendPM(Bot, ReadUser())
return 1
end
end
end

function DealUser(user, data, type)
local tmp = ""
local time = 0
readfrom(connectedusers)
while 1 do
local line = read()
if (line == nil) then
if (type == "ADD" and time == 0) then
tmp = tmp..user.sName.."\r\n"
break
elseif (type == "REMOVE") then
break
else
break
end
elseif (line == "" and type == "ADD") then
tmp = tmp..user.sName.."\r\n"
time = 1
else
local s,e,usr = strfind(line, "(%S+)")
if (type == "ADD") then
if (usr ~= nil and user.sName == usr) then
time = 1
else
tmp = tmp..line.."\r\n"
end
elseif (type == "REMOVE") then
if (usr ~= nil and usr == user.sName) then
else
tmp = tmp..line.."\r\n"
end
end
end
end
readfrom()

writeto(connectedusers)
write(tmp)
writeto()
end

function ReadUser()
local tmp = ""
tmp = tmp.."All users connected and their ips: \r\n\r\n"
tmp = tmp.."User: IP\r\n\r\n"
readfrom(connectedusers)
while 1 do
local line = read()
if (line == nil) then
break
else
local s,e,usr = strfind(line, "(%S+)")
if (usr ~= nil and GetItemByName(usr) ~= nil) then
tmp = tmp..usr..": "..GetItemByName(usr).sIP
end
end
end
readfrom()
return tmp
end

Best regards, nErBoS
Title:
Post by: daft009 on 14 March, 2004, 22:35:31
hi nErBoS,

thanks for the fast reply.

i hope i'm not troubling you too much by asking this.

1. is it possible to change it so the script gives me the IPs of whoever is connected at that point in time. (as right now it only gives me the IPs of users who have newly connected)

2. is it possible to make it a hidden bot (so it doesnt appear in the users list)

3. is it possible to make it so only OPs and above can use the command (if that isnt the case already)


EDIT: it seems its not putting new lines after each IP.

the current output is:

Quoteusername: IPusername: IPusername: IP
Title:
Post by: nErBoS on 14 March, 2004, 23:43:08
Hi,

--Requested by daft009
--Made by nErBoS

Bot = "IPs-Connected"

connectedusers = "users.txt" --Will be created in the script folder

function Main()
end

function NewUserConnected(user, data)
DealUser(user, data, "ADD")
end

function UserDisconnected(user, data)
DealUser(user, data, "REMOVE")
end

OpConnected = NewUserConnected
OpDisconnected = UserDisconnected

function DataArrival(user, data)
if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd=="!allips") then
if (user.bOperator) then
user:SendData(Bot, ReadUser())
return 1
else
user:SendData(Bot, "You don?t have permission to use this command.")
end
end
end
end

function DealUser(user, data, type)
local tmp = ""
local time = 0
readfrom(connectedusers)
while 1 do
local line = read()
if (line == nil) then
if (type == "ADD" and time == 0) then
tmp = tmp..user.sName.."\r\n"
break
elseif (type == "REMOVE") then
break
else
break
end
elseif (line == "" and type == "ADD") then
tmp = tmp..user.sName.."\r\n"
time = 1
else
local s,e,usr = strfind(line, "(%S+)")
if (type == "ADD") then
if (usr ~= nil and user.sName == usr) then
time = 1
else
tmp = tmp..line.."\r\n"
end
elseif (type == "REMOVE") then
if (usr ~= nil and usr == user.sName) then
else
tmp = tmp..line.."\r\n"
end
end
end
end
readfrom()

writeto(connectedusers)
write(tmp)
writeto()
end

function ReadUser()
local tmp = ""
tmp = tmp.."All users connected and their ips: \r\n\r\n"
tmp = tmp.."User: IP\r\n\r\n"
readfrom(connectedusers)
while 1 do
local line = read()
if (line == nil) then
break
else
local s,e,usr = strfind(line, "(%S+)")
if (usr ~= nil and GetItemByName(usr) ~= nil) then
tmp = tmp..usr..": "..GetItemByName(usr).sIP.."\r\n"
end
end
end
readfrom()
return tmp
end

1. The script saves in the file all connected users when they leave the HUB they are erased from that file, but if you have put the script when the HUB was runnig you have to start the hub from the begining to write all users.

2. Done

3. Done, sorry i have forgotten that.

About the other porbelm with lines, solved my bad :).

Best regards, nErBoS
Title:
Post by: daft009 on 15 March, 2004, 05:00:53
thanks for that. works a treat!

much appreciated  :D