PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: (!(Tys?kan)=) on 16 April, 2004, 16:46:37

Title: (ip)::(nick)
Post by: (!(Tys?kan)=) on 16 April, 2004, 16:46:37
Who can help with this?

On connecting usernick change to (ip)::(nick), but in mainchat and PM: nick...only on panel with nicks

And can I to this:
in userinfo change the description to ip's?
Title:
Post by: nErBoS on 17 April, 2004, 01:23:31
Hi,

If i understood you want to show user ips in his description ??? To all users ???

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 17 April, 2004, 10:30:48
Yes, It's realy? I'm saw this in the crazy bot by plop   V:?736.way_nutty.865452.i'm_lost
Title:
Post by: nErBoS on 17 April, 2004, 19:19:24
Hi,

Hope it helps...

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

sBot = "IP-Show"

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
SendIps(user)
end

OpConnected = NewUserConnected

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 SendIps(user)
if (connectuser[1] == nil and readfrom(onlinetxt) ~= nil) then
LoadFromFile(onlinetxt)
end

for i=1, getn(connectuser) do
if (GetItemByName(connectuser[i]) ~= nil) then
local s,e,info = strfind(GetItemByName(connectuser[i]).sMyInfoString, "$MyINFO%s+$ALL%s+%S+%s+(.*)")
user:SendData( "$MyINFO $ALL "..GetItemByName(connectuser[i]).sName.." "..GetItemByName(connectuser[i]).sIP.." "..info)
end
end
end

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 17 April, 2004, 19:47:12
Don't working ;(
Title:
Post by: nErBoS on 17 April, 2004, 22:03:57
Hi,

Little change, and tested...

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

sBot = "IP-Show"

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
SendIps(user)
end

OpConnected = NewUserConnected

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 SendIps(user)
if (connectuser[1] == nil and readfrom(onlinetxt) ~= nil) then
LoadFromFile(onlinetxt)
end

for i=1, getn(connectuser) do
if (GetItemByName(connectuser[i]) ~= nil) then
local s,e,info = strfind(GetItemByName(connectuser[i]).sMyInfoString, "$MyINFO%s+$ALL%s+%S+%s+(.*)")
SendToAll( "$MyINFO $ALL "..GetItemByName(connectuser[i]).sName.." "..GetItemByName(connectuser[i]).sIP.." "..info)
end
end
end

The ip appears in the start of the description. If there is a user that you can?t see just reconnect and you will see it.

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 18 April, 2004, 11:19:27
OK, 10x! :D
Title:
Post by: (!(Tys?kan)=) on 18 April, 2004, 16:08:14
Hi! Can i'm using the file online.txt from "Showips" script:

--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

There is such structure:
Nick1
Nick2
Nick3
Nick4
etc.


--Ty--
Title:
Post by: nErBoS on 18 April, 2004, 17:40:52
Hi,

Done..

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

sBot = "IP-Show"

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
SendIps(user)
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 SendIps(user)
if (connectuser[1] == nil and readfrom(onlinetxt) ~= nil) then
LoadFromFile(onlinetxt)
end

for i=1, getn(connectuser) do
if (GetItemByName(connectuser[i]) ~= nil) then
local s,e,info = strfind(GetItemByName(connectuser[i]).sMyInfoString, "$MyINFO%s+$ALL%s+%S+%s+(.*)")
SendToAll( "$MyINFO $ALL "..GetItemByName(connectuser[i]).sName.." "..GetItemByName(connectuser[i]).sIP.." "..info)
end
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
Title:
Post by: (!(Tys?kan)=) on 18 April, 2004, 21:23:17
Don't working... ;(
Writing:
Syntax Error: expected;
  last token read: `[' at line 1 in string "[R.H.]BLAST..."
Title:
Post by: nErBoS on 18 April, 2004, 22:11:17
Hi,

I have tested and is working, have you made any modification ???

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 19 April, 2004, 06:54:14
It's have trouble, when nick of user begining "["...
Syntax Error: expected;
  last token read: `[' at line 1 in string "[R.H.][Tushino]BLAST..."
Title:
Post by: kepp on 19 April, 2004, 07:14:39
Are you sure you diodn't edit the code at top, for a comment.
but forgot "--" infront?
Title:
Post by: (!(Tys?kan)=) on 19 April, 2004, 08:08:48
My curently code:
sBot = "President"

connectuser = {}
onlinetxt = "online.txt"

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
SendIps(user)
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 SendIps(user)
if (connectuser[1] == nil and readfrom(onlinetxt) ~= nil) then
LoadFromFile(onlinetxt)
end

for i=1, getn(connectuser) do
if (GetItemByName(connectuser[i]) ~= nil) then
local s,e,info = strfind(GetItemByName(connectuser[i]).sMyInfoString, "$MyINFO%s+$ALL%s+%S+%s+(.*)")
SendToAll( "$MyINFO $ALL "..GetItemByName(connectuser[i]).sName.." ::["..GetItemByName(connectuser[i]).sIP.."]::[ "..info)
end
end
end

function ShowIp(user)
local tmp = ""
tmp = tmp.."Ip-?????? ????:\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

But file is empty!
On !showips Bot showing:
[10:08] Ip-?????? ????:

(!(Tys?kan)=): 10.5.2.16
=Storm=: 10.3.21.58
WEREWOLF: 10.9.1.86
Totenkopf: 192.168.4.36
- [???????]Carnage: 10.11.5.45
- [bot]~???~: 192.168.5.55

Showing ip's in tag is working successfull

--Ty--
Title:
Post by: nErBoS on 19 April, 2004, 12:39:13
Hi,

ShowIPs in Tag and ShowIps from a command is using the same txt which is "online.txt". What isn?t working ??? I have tested your bot and is workin.

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 19 April, 2004, 15:35:30
Ok, this script is working. Yesterday there is one bag...Today all ok, 10x!
Title:
Post by: (!(Tys?kan)=) on 21 April, 2004, 21:27:14
Hello, if i restarting the script's on the hub, files don't modify and still empty on restarting scriptd :(
Title:
Post by: nErBoS on 22 April, 2004, 01:36:32
Hi,

Hummm maybe the function OnExit() his failing, i will see that. When i have an answer i will post here.

Best regards, nErBoS
Title:
Post by: nErBoS on 24 April, 2004, 15:32:32
Hi,

Which ptokax version are you using ???

Best regards, nErBoS
Title:
Post by: nErBoS on 24 April, 2004, 15:44:42
Hi,

Due a stupid bug (me programming), try this one....

sBot = "President"

connectuser = {}
onlinetxt = "online.txt"

function OnExit()
if (connectuser[1] == nil and readfrom(onlinetxt) ~= nil) then
LoadFromFile(onlinetxt)
end
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
SendIps(user)
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 SendIps(user)
if (connectuser[1] == nil and readfrom(onlinetxt) ~= nil) then
LoadFromFile(onlinetxt)
end

for i=1, getn(connectuser) do
if (GetItemByName(connectuser[i]) ~= nil) then
local s,e,info = strfind(GetItemByName(connectuser[i]).sMyInfoString, "$MyINFO%s+$ALL%s+%S+%s+(.*)")
SendToAll( "$MyINFO $ALL "..GetItemByName(connectuser[i]).sName.." ::["..GetItemByName(connectuser[i]).sIP.."]::[ "..info)
end
end
end

function ShowIp(user)
local tmp = ""
tmp = tmp.."Ip-?????? ????:\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

This script will only work 100% in ptokax 0.3.3.0

Best regards, nErBoS
Title:
Post by: nErBoS on 26 April, 2004, 12:28:38
Hi,

Another Bug corrected in the script above.

Best regards, nErBoS