PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: (!(Tys?kan)=) on 14 April, 2004, 08:33:53

Title: Script, which show all ip's on hub
Post by: (!(Tys?kan)=) on 14 April, 2004, 08:33:53
Exmpl:
!showips

PM to User by Bot:
Name: ip
Name1: ip
Name2: ip
Name3: ip
etc.

Who's want to help me?
Title:
Post by: nErBoS on 14 April, 2004, 12:21:41
Hi,

Hope it helps...

--Requested by (!(Tys?kan)=)
--Made by nErBoS

sBot = "IP-ALL"

loggintxt = "loggin.txt" -- Will be created in the script folder

function Main()
frmHub:RegBot(sBot)
end

function OnExit()
remove(loggintxt)
end

function NewUserConnected(user, data)
OnlineUser(user)
end

function UserDisconnected(user, data)
OfflineUser(user)
end

OpConnected = NewUserConnected
OpDisconnected = UserDisconnected

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

function OnlineUser(user)
local tmp = ""
local time = 0
if (readfrom(loggintxt) == nil) then
writeto(loggintxt)
write(user.sName)
writeto()
else
readfrom(loggintxt)
while 1 do
local line = read()
if (line == nil) then
if (time == 0) then
tmp = tmp..user.sName.."\r\n"
end
break
elseif (line == "") then
tmp = tmp..user.sName.."\r\n"
time = 1
else
tmp = tmp..line.."\r\n"
end
end
readfrom()
writeto(loggintxt)
write(tmp)
writeto()
end
end

function OfflineUser(user)
local tmp = ""
if (readfrom(loggintxt) ~= nil) then
readfrom(loggintxt)
while 1 do
local line = read()
if (line == nil) then
break
else
local s,e,who = strfind(line, "(%S+)")
if (who ~= user.sName) then
tmp = tmp..line.."\r\n"
end
end
end
readfrom()
writeto(loggintxt)
write(tmp)
writeto()
end
end

function ShowIp(user)
local tmp = ""
tmp = tmp.."All IPS from the HUB:\r\n\r\n"
if (readfrom(loggintxt) ~= nil) then
readfrom(loggintxt)
while 1 do
local line = read()
if (line == nil) then
break
else
local s,e,who = strfind(line, "(%S+)")
if (GetItemByName(who) ~= nil) then
tmp = tmp.."Name :"..who.." IP: "..GetItemByName(who).sIP.."\r\n"
end
end
end
readfrom()
end
user:SendPM(sBot, tmp)
end

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 14 April, 2004, 15:16:05
10x, but it is possible in fact to scan a server on names and to see at them ip-addresses, as in a script showing free slot's -- without temp files
Title:
Post by: nErBoS on 15 April, 2004, 01:08:21
Hi,

It?s only possible to call registered user the non-registered the only way is to create a file or table with all users, i have created a file because with a table when you restart the script or hub all will be lost.

Best regards, nErBoS
Title:
Post by: pHaTTy on 15 April, 2004, 04:52:16
little tip forif ya using 0.330, save em allin a table, then use

function OnExit();

to write then in a table on file, then it can be re-asserted ;-)
Title:
Post by: (!(Tys?kan)=) on 15 April, 2004, 05:56:46
This script have bug=)
When the hub gone down and starting table started copying names on hub:

[07:56] All IPS from the HUB:

Name :=Lis= IP: ***.***.**.**
Name :(!(Tys?kan)=) IP: ***.***.**.**
Name :=Lis= IP: ***.***.**.**
Name :Roman(Festi) IP: ***.***.**.**
Name :Faby{10.5.68.53} IP: ***.***.**.**
Name :[??????????]Liar IP: ***.***.**.**
Name :[??????]?FLOOD? IP: ***.***.**.**
Name :[??????]Xirtam IP: ***.***.**.**
Name :WEREWOLF IP: ***.***.**.**
Name :[??????]AlexG IP: ***.***.**.**
Name :Wizard IP: ***.***.**.**
Title:
Post by: nErBoS on 15 April, 2004, 12:35:50
Hi,

Try this one....

--Requested by (!(Tys?kan)=)
--Made by nErBoS

sBot = "IP-ALL"

loggintxt = "loggin.txt" -- Will be created in the script folder

function Main()
frmHub:RegBot(sBot)
end

function OnExit()
remove(loggintxt)
end

function NewUserConnected(user, data)
OnlineUser(user)
end

function UserDisconnected(user, data)
OfflineUser(user)
end

OpConnected = NewUserConnected
OpDisconnected = UserDisconnected

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

function OnlineUser(user)
local tmp = ""
local time = 0
if (readfrom(loggintxt) == nil) then
writeto(loggintxt)
write(user.sName)
writeto()
else
readfrom(loggintxt)
while 1 do
local line = read()
if (line == nil) then
if (time == 0) then
tmp = tmp..user.sName.."\r\n"
end
break
else
local s,e,who = strfind(line, "(%S+)")
if (who == user.sName) then
time = 1
tmp = tmp..line.."\r\n"
else
tmp = tmp..line.."\r\n"
end
end
end
readfrom()
writeto(loggintxt)
write(tmp)
writeto()
end
end

function OfflineUser(user)
local tmp = ""
if (readfrom(loggintxt) ~= nil) then
readfrom(loggintxt)
while 1 do
local line = read()
if (line == nil) then
break
else
local s,e,who = strfind(line, "(%S+)")
if (who ~= user.sName) then
tmp = tmp..line.."\r\n"
end
end
end
readfrom()
writeto(loggintxt)
write(tmp)
writeto()
end
end

function ShowIp(user)
local tmp = ""
tmp = tmp.."All IPS from the HUB:\r\n\r\n"
if (readfrom(loggintxt) ~= nil) then
readfrom(loggintxt)
while 1 do
local line = read()
if (line == nil) then
break
else
local s,e,who = strfind(line, "(%S+)")
if (GetItemByName(who) ~= nil) then
tmp = tmp.."Name :"..who.." IP: "..GetItemByName(who).sIP.."\r\n"
end
end
end
readfrom()
end
user:SendPM(sBot, tmp)
end

Phatty OnExit() is only done when the hub is going to be shut down or restart right ?? If yes don?t see the advantage :P, i don?t used table because of the restart script, or i could use but would always been saving in the file when a new user gets connected and disconnected.

Best regards, nErBoS
Title:
Post by: pHaTTy on 16 April, 2004, 05:35:33
onexit is done when scripts restarted or hub closed, meaning instead of using hdd life, u can keep everything in tables, until u restart then it can write everything at once and reload them, saving cpu time also ;-)
Title:
Post by: nErBoS on 17 April, 2004, 01:35:35
Hi,

Thought that OnExit() was only to hub closed, thanks phatty. Tomorrow i do a rewrite of the script today i am to tired :)

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 17 April, 2004, 10:34:21
10x, script is working :D
Title:
Post by: nErBoS on 17 April, 2004, 19:25:59
Hi,

Try this one then..

--Requested by (!(Tys?kan)=)
--Made by nErBoS

sBot = "IP-ALL"

connectuser = {}
onlinetxt = "online.txt"

function Main()
frmHub:RegBot(sBot)
end

function OnExit()
SaveToFile(onlinetxt , connectuser , "connectuser")
end

function NewUserConnected(user, data)
if (connectuser[1] == nil and readfrom(onlinetxt) ~= nil) then
LoadFromFile(onlinetxt)
end

local pos = 0
for i=1, getn(connectuser) do
if (connectuser[i] == user.sName) then
break
end
pos = pos + 1
end
connectuser[pos+1] = user.sName
end

OpConnected = NewUserConnected

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


function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

function ShowIp(user)
local tmp = ""
tmp = tmp.."All IPS from the HUB:\r\n\r\n"
if (connectuser[1] == nil and readfrom(onlinetxt) ~= nil) then
LoadFromFile(onlinetxt)
end

for i=1, getn(connectuser) do
if (GetItemByName(connectuser[i]) ~= nil) then
tmp = tmp..connectuser[i]..": "..GetItemByName(connectuser[i]).sIP.."\r\n"
end
end
user:SendPM(sBot, tmp)
end

Best regards, nErBoS