PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: badtrip on 21 September, 2005, 00:28:29

Title: lua4 to lua 5
Post by: badtrip on 21 September, 2005, 00:28:29
hello,


can anyone convert this script to Lua 5 ???

--## Nick and IP logger
--## Added Number to Loggers                                            
--## Requested by D-J Valhala                                        
--## Made by nErBoS                                                    
--## Command:  
--## +ip - Will show the nicks and ips of all connected users
--## +getip - Will give you the ip of the nick

sBot = "IP-Logger"

arrIP = {}

--## Configuration ##--

uLaterPtokax = 0 --## If you are using ptokax 0.3.30 or higher choose 0
--## If you are using lower versions then ptokax 0.3.3.0 choose 1

fileIP = "ip.log" --## This file will be created to save the users and ips

--## End of Configuration ##--

function Main()
frmHub:RegBot(sBot)
LoadFromFile(fileIP)
CheckForUser()
end

function OnExit()
SaveToFile(fileIP , arrIP , "arrIP")
end

function NewUserConnected(user)
arrIP[user.sName] = user.sIP
end

function UserDisconnected(user)
arrIP[user.sName] = nil
if (uLaterPtokax == 1) then
SaveToFile(fileIP , arrIP , "arrIP")
end
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 == "+ip" and user.bOperator) then
local sTmp,count,usr,ip = "Connected User's and their IP's:\r\n\r\n",0
for usr, ip in arrIP do
count = count + 1
sTmp = sTmp.."("..count..") User: "..usr.."\tIP: "..ip.." ("..count..")\r\n"
end
user:SendPM(sBot, sTmp)
return 1
elseif (cmd == "+getip" and user.bOperator) then
local s,e,usr = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (usr == nil) then
user:SendPM(sBot, "Syntax Error, !getip , you must write a nick.")
elseif (GetItemByName(usr) == nil) then
user:SendPM(sBot, "The user "..usr.." isn't online.")
else
user:SendPM(sBot, "The user "..GetItemByName(usr).sName.." ip is: "..GetItemByName(usr).sIP)
end
return 1
end
end
end

function CheckForUser()
local usr,ip
for usr, ip in arrIP do
if (GetItemByName(usr) == nil) then
arrIP[usr] = nil
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
Title: Re: lua4 to lua 5
Post by: ((KMN))Gazza-95 on 04 September, 2006, 22:05:42

--## Nick and IP logger
--## Added Number to Loggers                                             
--## Requested by D-J Valhala                                       
--## Made by nErBoS                                                     
--## Command:
--## +ip - Will show the nicks and ips of all connected users
--## +getip - Will give you the ip of the nick

sBot = "IP-Logger"

arrIP = {}

--## Configuration ##--

uLaterPtokax = 0 --## If you are using ptokax 0.3.30 or higher choose 0
--## If you are using lower versions then ptokax 0.3.3.0 choose 1

fileIP = "ip.log" --## This file will be created to save the users and ips

--## End of Configuration ##--

function Main()
frmHub:RegBot(sBot)
LoadFromFile(fileIP)
CheckForUser()
end

function OnExit()
SaveToFile(fileIP , arrIP , "arrIP")
end

function NewUserConnected(user)
arrIP[user.sName] = user.sIP
end

function UserDisconnected(user)
arrIP[user.sName] = nil
if (uLaterPtokax == 1) then
SaveToFile(fileIP , arrIP , "arrIP")
end
end

OpConnected = NewUserConnected
OpDisconnected = UserDisconnected

function DataArrival(user, data)
if (string.sub(data,1,1) == "<" or string.sub(data,1,5+string.len(sBot)) == "$To: "..sBot) then
data = string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if (cmd == "+ip" and user.bOperator) then
local sTmp,count,usr,ip = "Connected User's and their IP's:\r\n\r\n",0
for usr, ip in arrIP do
count = count + 1
sTmp = sTmp.."("..count..") User: "..usr.."\tIP: "..ip.." ("..count..")\r\n"
end
user:SendPM(sBot, sTmp)
return 1
elseif (cmd == "+getip" and user.bOperator) then
local s,e,usr = string.find(data, "%b<>%s+%S+%s+(%S+)")
if (usr == nil) then
user:SendPM(sBot, "Syntax Error, !getip , you must write a nick.")
elseif (GetItemByName(usr) == nil) then
user:SendPM(sBot, "The user "..usr.." isn't online.")
else
user:SendPM(sBot, "The user "..GetItemByName(usr).sName.." ip is: "..GetItemByName(usr).sIP)
end
return 1
end
end
end

function CheckForUser()
local usr,ip
for usr, ip in arrIP do
if (GetItemByName(usr) == nil) then
arrIP[usr] = nil
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 string.format("[%q]",key) or string.format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.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)

readfrom()
end
end


Try this m8 see if it works