Hi,
I'm trying to do a simple script, that log user and his IP in a table...
Now, he's repeating every IP Address'..
Here's the script:
function Main()
LoadFromFile("logs/log.txt")
end
local UserIP = {}
local tmp = {}
local tmp1 = {}
function NewUserConnected(user, data)
s = os.date("%S")
h = os.date("%H")
m = os.date("%M")
d = os.date("%d")
mm = os.date("%m")
y = os.date("%y")
tmp1[h..":"..m..":"..s] = user.sIP
tmp[y.."/"..d.."/"..mm] = tmp1
UserIP[user.sName] = tmp
SaveToFile("logs/log.txt", UserIP, "UserIP")
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
sTmp = sTmp..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)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
function LoadFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
dofile(file)
handle:flush()
handle:close()
end
end
And the .txt where's the table:
UserIP = {
["Atena"] = {
["05/02/09"] = {
["17:59:58"] = "127.0.0.1",
["18:00:01"] = "192.168.1.2",
},
},
["zero-cool"] = {
["05/02/09"] = {
["17:59:58"] = "127.0.0.1",
["18:00:01"] = "192.168.1.2",
},
},
}
I've entered on Hub only 2 times (one with nick zero-cool and IP 127.0.0.1, and other with nick Atena and IP 192.168.1.2).
Sorry my english :rolleyes: I hope you understand...
Regards,
Some help...? :rolleyes: :rolleyes:
Hello zero :) (the best portuguese LUA scripter of all times :P)
Try this :
--Connection Log 1.0 LUA 5
--
--by Mutor The Ugly
--
-- Log connections to hub in an external file
-- Hublist pingers are excluded by nick, add IP's if needed
--User Settings------------------------------------------------
LogFile = "Log.txt" --Log file
LogCmd = "+log" --View log Command
Maxlog = 200 --Number of entries to cache
Bot = frmHub:GetHubBotName() -- Bot name pulled from hub
--End User Settings--------------------------------------------
function Main()
local f,e = io.open( LogFile, "r" )
if f then
dofile(LogFile)
else
Log = {}
SaveLog()
end
end
function OnExit()
SaveLog()
end
function ChatArrival(user, data)
if string.sub(data, 1, 1) ~= "<" then end
data = string.sub(data,1,string.len(data)-1)
local s,e,cmd = string.find(data, "^%b<>%s+(%S+)")
local s,e,lines = string.find(data, "^%b<>%s+%S+%s+(%d+)")
if cmd and cmd == LogCmd then
if lines ~= nil then
GetLog(user, lines)
return 1
else
user:SendData("Please specify how may log entries to show, you can display available entries up to "..Maxlog.." lines.")
return 1
end
return 1
end
end
function GetLog(user, linecount)
local n1 = table.getn(Log)
local n2 = linecount
local n3 = n1 - n2
local n4
local str
if tonumber(n2) > n1 then
n3 = 1
n4 = n1 - n3
str = "<"..string.rep("-",45).."-[ There are only ( "..n4.." ) Connection Log Entries ]----------->\r\n"
else
n4 = n2
str = "<"..string.rep("-",50).."-[ Last ( "..n4.." ) Connection Log Entries ]----------->\r\n"
end
for i=n3+1,n1 do str = str.."\r\n"..Log[i] end
user:SendPM(Bot,str.."\r\n")
user:SendPM(Bot,"<"..string.rep("-",60).."-[ End of Connection Log ]--------------->")
end
function NewUserConnected(user,data)
if string.find(string.lower(user.sName), "ping") then return end
local prof = ""
if GetProfileName(user.iProfile) == nil then
prof = "Unregistered"
else
prof = GetProfileName(user.iProfile)
end
local when = os.date("[ %B %d %X ] ")
local userinfo = "- Log In > "..user.sName..", profile "..prof..", from: "..user.sIP..
", using: "..user.sClient..user.sClientVersion..", in: "..GetMode(user.sMode).." mode, shares: "..string.format("%.2f Gb.",user.iShareSize/(1024 * 1024 * 1024))..
", on: "..user.iSlots.." slots, is in: "..GetStatus(user.iNormalHubs).." hubs as a user, regged in: "..GetStatus(user.iRegHubs)..
", Ops in "..GetStatus(user.iOpHubs)..", total: "..GetStatus(user.iHubs)
table.insert(Log, when..userinfo)
if table.getn(Log) > Maxlog then
table.remove(Log, 1)
end
SaveLog()
end
OpConnected = NewUserConnected
function UserDisconnected(user,data)
if string.find(string.lower(user.sName), "ping") then return end
local prof = ""
if GetProfileName(user.iProfile) == nil then
prof = "Unregistered"
else
prof = GetProfileName(user.iProfile)
end
local when = os.date("[ %B %d %X ] ")
local userinfo = "- Log Out > "..user.sName..", profile "..prof..", from: "..user.sIP..
", using: "..user.sClient..user.sClientVersion..", in: "..GetMode(user.sMode).." mode, shares: "..string.format("%.2f Gb.",user.iShareSize/(1024 * 1024 * 1024))..
", on: "..user.iSlots.." slots, is in: "..GetStatus(user.iNormalHubs).." hubs as a user, regged in: "..GetStatus(user.iRegHubs)..
", Ops in "..GetStatus(user.iOpHubs)..", total: "..GetStatus(user.iHubs)
table.insert(Log, when..userinfo)
if table.getn(Log) > Maxlog then
table.remove(Log, 1)
end
SaveLog()
end
OpDisconnected = UserDisconnected
function SaveLog()
local f,e = io.open( LogFile, "w+" )
if f then
f:write( "Log={\n" )
for i = 1, table.getn(Log) do
f:write( " "..string.format("%q", Log[i])..",\r\n" )
end
f:write( "}" )
f:close()
return 1
else
return nil, user:SendData("Save Log failed: "..e)
end
end
function GetMode(mode)
if mode == "A" then
mode = "Active"
elseif mode == "P" then
mode = "Passive"
else
mode = Socks5
end
return mode
end
function GetStatus(status)
if not status or status == nil or status == "" then
status = 0
end
return status
end
Props
Hi,
Thanks -PT-B2S, but i want something different...
With that script I've made, i get this:
UserIP = {
["Atena"] = {
["05/02/09"] = {
["17:59:58"] = "127.0.0.1",
["18:00:01"] = "192.168.1.2",
},
},
["zero-cool"] = {
["05/02/09"] = {
["17:59:58"] = "127.0.0.1",
["18:00:01"] = "192.168.1.2",
},
},
}
But it would be:
UserIP = {
["Atena"] = {
["05/02/09"] = {
["18:00:01"] = "192.168.1.2",
},
},
["zero-cool"] = {
["05/02/09"] = {
["17:59:58"] = "127.0.0.1",
},
},
}
Script is creating the same thing, and put it in every tables :rolleyes:
Regards,
try it this way
UserIP = {
["Atena"] = {
["05/02/09"] = {
["192.168.1.2"] = "18:00:01",
},
},
["zero-cool"] = {
["05/02/09"] = {
["127.0.0.1"] = "17:59:58",
},
},
}
Same problem... :rolleyes:
UserIP = {
["Atena"] = {
["05/09/09"] = {
["127.0.0.1"] = "16:29:06",
["192.168.1.2"] = "16:29:21",
},
},
["zero-cool"] = {
["05/09/09"] = {
["127.0.0.1"] = "16:29:06",
["192.168.1.2"] = "16:29:21",
},
},
}
And I don't know why...
Try this 1
UserIP = {}
function Main()
LoadFromFile("logs/log.txt")
end
function NewUserConnected(user, data)
UserIP[user.sName] = {}
UserIP[user.sName][os.date("%x")] = {}
UserIP[user.sName][os.date("%x")][user.sIP] = os.date("%X")
SaveToFile("logs/log.txt", UserIP, "UserIP")
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 string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..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)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
function LoadFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
dofile(file)
handle:flush()
handle:close()
end
end
Dont save in the userconnected function. Because it consumes lots of memory. save in the exit function or on timer function.
There is a script for IP logging, if you want you can use that script:IPdbBOT (http://board.univ-angers.fr/thread.php?threadid=5250&boardid=26&styleid=1&sid=6cc22b01df2f8231199bb248fd18ed24)
Thanks
Optimus ;) :))
I've tried that, but I haven't create tables before... so, it gave error :P
QuoteDont save in the userconnected function. Because it consumes lots of memory. save in the exit function or on timer function.
Yes, I know... this is only the begin. It will be different.
Regards