PtokaX forum

Archive => Archived 5.1 boards => Conversion Requests => Topic started by: 7P-Darkman on 12 March, 2007, 06:34:44

Title: Datalog script for LUA 5.1
Post by: 7P-Darkman on 12 March, 2007, 06:34:44
Hello friends...


Much time behind, I used one excellent script, called "Datalog - Lua Edition - Version 1.1", by DirtyFinger. Here is the code (LUA 4):


-------------------------------------------------------
---------------- Datalog - Lua Edition ----------------
--------------------- Version 1.1 ---------------------
------------------- by DirtyFinger --------------------
---------------- DirtyFinger@gmx.net ------------------
------------------ ICQ : 145873101 --------------------
------- http://mitglied.lycos.de/dirtyfinger01/ -------
-------------------------------------------------------
-------------------------------------------------------
-- This script logs incoming data , connects, disconnects
-- and saves them in three seperate files.
-- I'm pretty sure that absolutely NO ONE needs this script
-- to run a functioning hub.
-- It's rather something to watch at long, cold evenings.

-- Due to the known problems with PtokaX 0.323X the files
-- may not be generated.
-- In that case AND if you use PtokaX 0.324 or higher,
-- use the second set of file locations (directly below).
-- Make sure the Directory Datalog exists !!
Connectlogfile = "Datalog/connectlog.txt"
Datalogfile = "Datalog/datalog.txt"
Statisticsfile = "Datalog/stats.txt"
-- Connectlogfile = "Datalog/connectlog.txt"
-- Datalogfile = "Datalog/datalog.txt"
-- Statisticsfile = "Datalog/stats.txt"

sBotName = "Guat?"

timerIntervall = 10*1000 -- This sets the intervalls in which the files get saved

sDatalog = ""
sConnectlog = ""


Statistics = {
ConnectToMe = 0,
GetNickList = 0,
GetINFO = 0,
Kick = 0,
MainChat = 0,
MultiConnectToMe = 0,
MultiSearch = 0,
MyINFO = 0,
MyPass = 0,
OpForceMove = 0,
Other = 0,
Quit = 0,
RevConnectToMe = 0,
Search = 0,
SearchResult = 0,
To = 0,
ValidateNick = 0,
Version = 0,
ZTotal = 0,
}


--// This function is fired at the serving start
function Main()
SendToAll(sBotName.." "..date(" launched at %B %d %Y %X "))
SetTimer(timerIntervall)
StartTimer()
loadStatistics (Statisticsfile)

end

--// This function is fired when a new data arrives
function DataArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
local s = splitstring(sData)
if s == "$ConnectToMe" then
Statistics.ConnectToMe = Statistics.ConnectToMe + 1
elseif s == "$GetNickList|" then
Statistics.GetNickList = Statistics.GetNickList + 1
elseif s == "$GetINFO" then
Statistics.GetINFO = Statistics.GetINFO + 1
elseif s == "$Kick" then
Statistics.Kick = Statistics.Kick + 1
elseif s == "<"..curUser.sName..">" then
Statistics.MainChat = Statistics.MainChat + 1
elseif s == "$MultiConnectToMe" then
Statistics.MultiConnectToMe = Statistics.MultiConnectToMe + 1
elseif s == "$MultiSearch" then
Statistics.MultiSearch = Statistics.MultiSearch + 1
elseif s == "$MyINFO" then
Statistics.MyINFO = Statistics.MyINFO + 1
elseif s == "$MyPass" then
Statistics.MyPass = Statistics.MyPass + 1
elseif s == "$OpForceMove" then
Statistics.OpForceMove = Statistics.OpForceMove + 1
elseif s == "$Quit" then
Statistics.Quit = Statistics.Quit + 1
elseif s == "$RevConnectToMe" then
Statistics.RevConnectToMe = Statistics.RevConnectToMe + 1
elseif s == "$Search" then
Statistics.Search = Statistics.Search + 1
elseif s == "$SR" then
Statistics.SearchResult = Statistics.SearchResult + 1
elseif s == "$To:" then
Statistics.To = Statistics.To + 1
elseif s == "$ValidateNick" then
Statistics.ValidateNick = Statistics.ValidateNick + 1
elseif s == "$Version" then
Statistics.Version = Statistics.Version + 1
else
Statistics.Other = Statistics.Other + 1
end
Statistics.ZTotal = Statistics.ZTotal + 1
end


--// This function is fired when a new user finishes the login
function NewUserConnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<"..date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "> " .. "User Connected"
end

function tokenize (inString,token)
_WORDS = {}
local matcher = "([^"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end

--// This function is fired when an operator enters the hub
function OpConnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<"..date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "> " .. "Operator Connected"
end

--// This function is fired when an user disconnects
function UserDisconnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<"..date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "> " .. "User Disconnected"
end

--// This function is fired when an operator disconnects
function OpDisconnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<"..date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "> " .. "Operator Disconnected"
end

function OnTimer()
-- DirtyUsers:saveToFile(HubSettings.HubDataFile,FileIPList)
if sDatalog ~= "" then
local f = appendto(Datalogfile)
write(sDatalog)
sDatalog = ""
closefile(f)

end
if sConnectlog ~= "" then
local f = appendto(Connectlogfile)
write(sConnectlog)
sConnectlog = ""
closefile(f)

end
saveStatistics (Statisticsfile)

end


function print (...)
local s =""
for i=1,arg.n do
s = s..tostring(arg[i]).."\t"
end
SendToAll ("",s)
end   

function splitstring (string,token)
token = token or " "
local n = strfind(string,token)
if n then
return strsub(string,1,n-1) , strsub(string,n+1)
else
return string , ""
end
end

function loadStatistics (file)
assert(readfrom(file),"stats.txt not found.Generating new stats.txt. All is fine. Don't panic.")
dostring(read("*all"))
readfrom()
end

function saveStatistics (file)
writeto(file)
local l = {}
for k,v in Statistics do
tinsert(l,k)
end
sort(l)

local s = "Statistics = { \n"
for i=1,getn(l) do
s = s .. "\t" .. l[i] .. " = " .. tostring(Statistics[l[i]]) .. ", \n"
end
local s = s.."}"
write(s)
writeto()
end



Well... I am needing one script that it makes something similar, but for LUA 5.1. I tried to convert it, but I did not get success.

In case that some of our friends scripters obtains to convert it, it would be thankful very.

In case that it is not possible the conversion, it will be that somebody could develop some script that made the same that this? Perhaps with plus some functions, as the Logs separate for date and, perhaps, the possibility of research in logs, for strings... and... and...  :D

Anticipatedly I am thankful the friends who trying.

Respectfully,


7P-Darkman
Title: Re: Datalog script for LUA 5.1
Post by: Madman on 12 March, 2007, 19:24:23
Code (lua) Select

-------------------------------------------------------
---------------- Datalog - Lua Edition ----------------
--------------------- Version 1.1 ---------------------
------------------- by DirtyFinger --------------------
---------------- DirtyFinger@gmx.net ------------------
------------------ ICQ : 145873101 --------------------
------- http://mitglied.lycos.de/dirtyfinger01/ -------
-------------------------------------------------------
-------------------------------------------------------

-- Lua 5.1 version by Madamn

-- This script logs incoming data , connects, disconnects
-- and saves them in three seperate files.
-- I'm pretty sure that absolutely NO ONE needs this script
-- to run a functioning hub.
-- It's rather something to watch at long, cold evenings.

-- Due to the known problems with PtokaX 0.323X the files
-- may not be generated.
-- In that case AND if you use PtokaX 0.324 or higher,
-- use the second set of file locations (directly below).
-- Make sure the Directory Datalog exists !!
Connectlogfile = "Datalog/connectlog.txt"
Datalogfile = "Datalog/datalog.txt"
Statisticsfile = "Datalog/stats.txt"
-- Connectlogfile = "Datalog/connectlog.txt"
-- Datalogfile = "Datalog/datalog.txt"
-- Statisticsfile = "Datalog/stats.txt"

sBotName = "Guat?"

timerIntervall = 10*1000 -- This sets the intervalls in which the files get saved

sDatalog = ""
sConnectlog = ""

Statistics = {
ConnectToMe = 0,
GetNickList = 0,
GetINFO = 0,
Kick = 0,
MainChat = 0,
MultiConnectToMe = 0,
MultiSearch = 0,
MyINFO = 0,
MyPass = 0,
OpForceMove = 0,
Other = 0,
Quit = 0,
RevConnectToMe = 0,
Search = 0,
SearchResult = 0,
To = 0,
ValidateNick = 0,
Version = 0,
ZTotal = 0,
}a

--// This function is fired at the serving start
function Main()
SendToAll(sBotName.." "..os.date(" launched at %B %d %Y %X "))
SetTimer(timerIntervall)
StartTimer()
loadStatistics (Statisticsfile)
end

function ChatArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.MainChat = Statistics.MainChat + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function ValidateNickArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.ValidateNick = Statistics.ValidateNick + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function PasswordArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.MyPass = Statistics.MyPass + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function VersionArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.Version = Statistics.Version + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function GetNickListArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.GetNickList = Statistics.GetNickList + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function MyINFOArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.MyINFO = Statistics.MyINFO + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function GetINFOArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.GetINFO = Statistics.GetINFO + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function SearchArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
if string.find(sData, "$MultiSearch") then
Statistics.MultiSearch = Statistics.MultiSearch + 1
elseif string.find(sData, "$Search") then
Statistics.Search = Statistics.Search + 1
end
Statistics.ZTotal = Statistics.ZTotal + 1
end
function ToArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.To = Statistics.To + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function ConnectToMeArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.ConnectToMe = Statistics.ConnectToMe + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function MultiConnectToMeArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.MultiConnectToMe = Statistics.MultiConnectToMe + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function RevConnectToMeArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.RevConnectToMe = Statistics.RevConnectToMe + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function SRArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.SearchResult = Statistics.SearchResult + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function KickArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.Kick = Statistics.Kick + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function OpForceMoveArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
Statistics.OpForceMove = Statistics.OpForceMove + 1
Statistics.ZTotal = Statistics.ZTotal + 1
end
function UnknownArrival(curUser, sData)
sDatalog = sDatalog .. "\n" .. "<|"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. sData
if string.find(sData,"$Quit") then
Statistics.Quit = Statistics.Quit + 1
else
Statistics.Other = Statistics.Other + 1
end
Statistics.ZTotal = Statistics.ZTotal + 1
end

--// This function is fired when a new user finishes the login
function NewUserConnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "> " .. "User Connected"
end

--// This function is fired when an operator enters the hub
function OpConnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "> " .. "Operator Connected"
end

--// This function is fired when an user disconnects
function UserDisconnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "> " .. "User Disconnected"
end

--// This function is fired when an operator disconnects
function OpDisconnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<"..os.date("%c|") .. curUser.sName .. "|" .. curUser.sIP .. "> " .. "Operator Disconnected"
end

function OnTimer()
-- DirtyUsers:saveToFile(HubSettings.HubDataFile,FileIPList)
if sDatalog ~= "" then
local f = io.open(Datalogfile,"a+")
f:write(sDatalog)
sDatalog = ""
f:close()

end
if sConnectlog ~= "" then
local f = io.open(Connectlogfile,"a+")
f:write(sConnectlog)
sConnectlog = ""
f:close()
end
saveStatistics (Statisticsfile)

end


function print (...)
local s =""
for i=1,arg.n do
s = s..tostring(arg[i]).."\t"
end
SendToAll ("",s)
end   

function loadStatistics (file)
if not loadfile(file) then
local f = io.open(file,"w+")
f:write("Statistics = { \n ConnectToMe = 0,\n GetNickList = 0,\n GetINFO = 0,\n Kick = 0,\n MainChat = 0,\n MultiConnectToMe = 0,\n MultiSearch = 0,\n MyINFO = 0,\n MyPass = 0,\n OpForceMove = 0,\n Other = 0,\n Quit = 0,\n RevConnectToMe = 0,\n Search = 0,\n SearchResult = 0,\n To = 0,\n ValidateNick = 0,\n Version = 0,\n ZTotal = 0,\n }" )
f:close()
SendToOps(sBotName,"stats.txt not found.Generating new stats.txt. All is fine. Don't panic.")
else
dofile(file)
end
end

function saveStatistics (file)
local f = io.open(file,"w+")
local l = {}
for k,v in pairs(Statistics) do
table.insert(l,k)
end
table.sort(l)
local s = "Statistics = { \n"
for i=1,table.maxn(l) do
s = s.. "\t" ..l[i].. " = " ..tostring(Statistics[l[i]]).. ", \n"
end
local s = s.. "}"
f:write(s)
f:close()
end



completly untested! Might not work...
Title: Re: Datalog script for LUA 5.1
Post by: 7P-Darkman on 12 March, 2007, 20:49:42
Hello Madman...


Thanks for your initiative and effort? but it did not function here.


[15:40] Sintaxe Datalog.lua:75: '<eof>' expected near 'end'


Respectfully,


7P-Darkman
Title: Re: Datalog script for LUA 5.1
Post by: Madman on 13 March, 2007, 06:04:44
bah... noob error, fixed that error, but now it gives error
77: attempt to perform arithmetic on field 'ValidateNick' (a nil value)
goes for all thos, and i am to tierd and have to get to work to fix that now, maybe someone else can, or i will fix it when i get home.

*Edit*
Okey, fixed that as well, prev post updated.