PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: [NL]trucker on 24 February, 2004, 11:50:38

Title: who can help with this script???
Post by: [NL]trucker on 24 February, 2004, 11:50:38
hello all i got this script i want the datalog file it creates to look "better" or more readable

now i get :
------------------------------------------------------------------

<|02/24/04 00:11:35|yjdhbt|80.228.12.92|> $Version 1,0091|
<|02/24/04 00:11:35|yjdhbt|80.228.12.92|> $MyINFO $ALL yjdhbt mldc client$ $DSL$$  11534336$|
<|02/24/04 00:11:35||200.210.234.167|> $ValidateNick nivpki|
<|02/24/04 00:11:37||64.173.107.156|> $ValidateNick ebgpio|
<|02/24/04 00:11:37||81.66.61.212|> $ValidateNick gkgwcx|
=========================================

i think it could be optimized for better reading.
furthermore i love this script :-))



-------------------------------------------------------
---------------- 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 = "Datalog"

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).."\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 .. " = " .. tostring(Statistics[l]) .. ", \n"
   end
   local s = s.."}"
   write(s)
   writeto()
end   
Title:
Post by: nErBoS on 25 February, 2004, 02:23:42
Hi,

What would you like to do ??

Best regards, nErBoS
Title:
Post by: [NL]trucker on 25 February, 2004, 08:39:39
Nerbos

this is what i get from the script now:

now i get :
------------------------------------------------------------------

<|02/24/04 00:11:35|yjdhbt|80.228.12.92|> $Version 1,0091|
<|02/24/04 00:11:35|yjdhbt|80.228.12.92|> $MyINFO $ALL yjdhbt mldc client$ $DSL$$ 11534336$|
<|02/24/04 00:11:35||200.210.234.167|> $ValidateNick nivpki|
<|02/24/04 00:11:37||64.173.107.156|> $ValidateNick ebgpio|
<|02/24/04 00:11:37||81.66.61.212|> $ValidateNick gkgwcx|
=========================================
so this is a mess i hope you agree with me.

i reaaly want it to have it without the additional data like  $ or client$ $DSL$$  or $MyINFO $ALL

so it looks a bit cleaner so it will show just
date/time/nick /ip/client

and as you can see this is an rather old script and not yet optimised for 0330 yet

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

so i really would like if it gets optimised a bit for the newest version of pkotax.
Title:
Post by: nErBoS on 25 February, 2004, 13:40:33
Ok will see what i can do...

I will be out all day when i get time i will see that.

Best regards, nErBoS
Title:
Post by: [NL]trucker on 25 February, 2004, 14:51:09
Nerbos

thnx m8  
and have a good day :-)
Title:
Post by: nErBoS on 26 February, 2004, 13:07:46
Hi,

I have been taking a look at the script and...

What you want to change is the statistics ???

It saves some info !! you would only like to save the
date/ip/nick/version, and erase all other info ???

Best regards, nErBoS
Title:
Post by: [NL]trucker on 26 February, 2004, 14:55:15
Nerbos

hy there

i want to save all the info it saves now but :

this s a part of info-file i get now
========================================
<|02/24/04 00:11:35|yjdhbt|80.228.12.92|> $Version 1,0091|
<|02/24/04 00:11:35|yjdhbt|80.228.12.92|> $MyINFO $ALL yjdhbt mldc client$ $DSL$$ 11534336$|
<|02/24/04 00:11:35||200.210.234.167|> $ValidateNick nivpki|
<|02/24/04 00:11:37||64.173.107.156|> $ValidateNick ebgpio|
<|02/24/04 00:11:37||81.66.61.212|> $ValidateNick gkgwcx|
========================================

and i want this part as this

02/24/04  00.11:35 |username|ip |clientversion|


so without it showing  $ValidateNick or $MyINFO  or  $Version  or $ALL or whatever $ commands used in script.

whitout these things it looks a lot nicer and better to read the log file.

and i think tis script could be a bit more optimised for td4 and above.
Title:
Post by: nErBoS on 27 February, 2004, 02:21:45
Hi,

I made a second data text to your type of information...

-------------------------------------------------------
---------------- Datalog - Lua Edition ----------------
--------------------- Version 1.1 ---------------------
------------------- by DirtyFinger --------------------
---------------- [EMAIL]DirtyFinger@gmx.net[/EMAIL] ------------------
------------------ ICQ : 145873101 --------------------
------- [URL]http://mitglied.lycos.de/dirtyfinger01/[/URL] -------
-------------------------------------------------------
-------------------------------------------------------
-- 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"
SecondDatafile = "Datalog/data2log.txt"
-- Connectlogfile = "Datalog/connectlog.txt"
-- Datalogfile = "Datalog/datalog.txt"
-- Statisticsfile = "Datalog/stats.txt"

sBotName = "Datalog"

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

sDatalog = ""
sConnectlog = ""
sSDatalog = ""


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

_,b, ver = strfind(curUser.sMyInfoString, "V:(.*),M:") --- ADDED TO SEE CLIENT AND VERSION
if strfind(curUser.sMyInfoString, "client = "oDC"
version = "V:"..ver
elseif strfind(curUser.sMyInfoString, "<++") then
client = "DC++"
version = "V:"..ver
else
client = "unknown"
version = "unknown"
end
sSDatalog = sSDatalog .. "\n" .. "<|"..date .. "|" .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. client .. "|" .. version

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 .. "|" .. 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
if sSDatalog ~= "" then
local f = appendto(SecondDatafile)
write(sSDatalog)
sSDatalog = ""
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

Best regards, nErBoS
Title:
Post by: [NL]trucker on 27 February, 2004, 08:34:37
Nerbos

thnx alot for your effort
but upon starting script i get this

Syntax error: bad argument #1 to `strfind' (string expected, got nil)
stack traceback:
   1:  function `strfind' [C]
   2:  function `DataArrival' at line 115 [file `D:\==PTOTAX==\robo\scripts\datalog1-2.lua']
Title:
Post by: nErBoS on 27 February, 2004, 15:09:04
Hi,

Its something that i shouldn't do in the new version of ptkoax i will try to see what is and let you know, in TD4 works without error i think :P

Best regards, nErBoS
Title:
Post by: nErBoS on 27 February, 2004, 17:31:48
Hi,

This will solve the syntax error..

-------------------------------------------------------
---------------- Datalog - Lua Edition ----------------
--------------------- Version 1.1 ---------------------
------------------- by DirtyFinger --------------------
---------------- [EMAIL]DirtyFinger@gmx.net[/EMAIL] ------------------
------------------ ICQ : 145873101 --------------------
------- [URL]http://mitglied.lycos.de/dirtyfinger01/[/URL] -------
-------------------------------------------------------
-------------------------------------------------------
-- 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"
SecondDatafile = "Datalog/data2log.txt"
-- Connectlogfile = "Datalog/connectlog.txt"
-- Datalogfile = "Datalog/datalog.txt"
-- Statisticsfile = "Datalog/stats.txt"

sBotName = "Datalog"

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

sDatalog = ""
sConnectlog = ""
sSDatalog = ""


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
if (curUser.sMyInfoString ~= nil) then
_,b, ver = strfind(curUser.sMyInfoString, "V:(.*),M:") --- ADDED TO SEE CLIENT AND VERSION
if strfind(curUser.sMyInfoString, "client = "oDC"
version = "V:"..ver
elseif strfind(curUser.sMyInfoString, "<++") then
client = "DC++"
version = "V:"..ver
else
client = "unknown"
version = "unknown"
end
sSDatalog = sSDatalog .. "\n" .. "<|"..date .. "|" .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. client .. "|" .. version
else
end

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 .. "|" .. 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
if sSDatalog ~= "" then
local f = appendto(SecondDatafile)
write(sSDatalog)
sSDatalog = ""
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

Thanks to tezlo, Guibs and NL help :)

Best regards, nErBoS
Title:
Post by: [NL]trucker on 27 February, 2004, 23:24:32
Nerbos

i get this error :

Syntax error: attempt to concat global `date' (a function value)
stack traceback:
   1:  function `DataArrival' at line 124 [file `D:\==PTOTAX==\trucker\scripts\datalog-3.lua']


this is line 124
sSDatalog = sSDatalog .. "\n" .. "<|"..date .. "|" .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. client .. "|" .. version"
Title:
Post by: Stravides on 27 February, 2004, 23:38:15
Try something like

timestamp = ""..date("%d").."/"..date("%m").."/"..date("%Y").." - "..date("%H")..":"..date("%M")..""
to give dd/mm/yyyy - hh:mm
Title:
Post by: nErBoS on 28 February, 2004, 00:19:14
Hi,

Done..

--------------------------------------------------------
---------------- Datalog - Lua Edition ----------------
--------------------- Version 1.1 ---------------------
------------------- by DirtyFinger --------------------
---------------- [EMAIL]DirtyFinger@gmx.net[/EMAIL] ------------------
------------------ ICQ : 145873101 --------------------
------- [URL]http://mitglied.lycos.de/dirtyfinger01/[/URL] -------
-------------------------------------------------------
-------------------------------------------------------
-- 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"
SecondDatafile = "Datalog/data2log.txt"
-- Connectlogfile = "Datalog/connectlog.txt"
-- Datalogfile = "Datalog/datalog.txt"
-- Statisticsfile = "Datalog/stats.txt"

sBotName = "Datalog"

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

sDatalog = ""
sConnectlog = ""
sSDatalog = ""

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
if (curUser.sMyInfoString ~= nil) then
_,b, ver = strfind(curUser.sMyInfoString, "V:(.*),M:") --- ADDED TO SEE CLIENT AND VERSION
if strfind(curUser.sMyInfoString, "client = "oDC"
version = "V:"..ver
elseif strfind(curUser.sMyInfoString, "<++") then
client = "DC++"
version = "V:"..ver
else
client = "unknown"
version = "unknown"
end
sSDatalog = sSDatalog .. "\n" .. "<|"..GetTime() .. "|" .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. client .. "|" .. version
else
end

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 .. "|" .. 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
if sSDatalog ~= "" then
local f = appendto(SecondDatafile)
write(sSDatalog)
sSDatalog = ""
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

function GetTime()
s = date("%S")
h = date("%H")
m = date("%M")
d = date("%d")
mm = date("%m")
y = date("%y")
Date = "Day: "..d.."/"..mm.."/20"..y.."  Hour: "..h..":"..m..":"..s
return Date
end

The example that Stravides said is also right.

Best regards, nErBoS
Title:
Post by: [NL]trucker on 28 February, 2004, 16:59:21
Nerbos

got an error

Syntax error: attempt to concat global `date' (a function value)
stack traceback:
   1:  function `OpDisconnected' at line 155 [file `D:\==PTOTAX==\trucker\scripts\datalog-4.LUA']

 i was the onley one disconnecting and i,m a master so how comes the script sees me as an OP?
Title:
Post by: nErBoS on 28 February, 2004, 17:59:10
Hi,

Done...

--------------------------------------------------------
---------------- Datalog - Lua Edition ----------------
--------------------- Version 1.1 ---------------------
------------------- by DirtyFinger --------------------
---------------- [EMAIL]DirtyFinger@gmx.net[/EMAIL] ------------------
------------------ ICQ : 145873101 --------------------
------- [URL]http://mitglied.lycos.de/dirtyfinger01/[/URL] -------
-------------------------------------------------------
-------------------------------------------------------
-- 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"
SecondDatafile = "Datalog/data2log.txt"
-- Connectlogfile = "Datalog/connectlog.txt"
-- Datalogfile = "Datalog/datalog.txt"
-- Statisticsfile = "Datalog/stats.txt"

sBotName = "Datalog"

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

sDatalog = ""
sConnectlog = ""
sSDatalog = ""

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
if (curUser.sMyInfoString ~= nil) then
_,b, ver = strfind(curUser.sMyInfoString, "V:(.*),M:") --- ADDED TO SEE CLIENT AND VERSION
if strfind(curUser.sMyInfoString, "client = "oDC"
version = "V:"..ver
elseif strfind(curUser.sMyInfoString, "<++") then
client = "DC++"
version = "V:"..ver
else
client = "unknown"
version = "unknown"
end
sSDatalog = sSDatalog .. "\n" .. "<|"..GetTime() .. "|" .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. client .. "|" .. version
else
end

end


--// This function is fired when a new user finishes the login
function NewUserConnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<".. GetTime() .. "|" .. 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" .. "<".. GetTime() .. "|" .. curUser.sName .. "|" .. curUser.sIP .. "> " .. "Operator Connected"
end

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

--// This function is fired when an operator disconnects
function OpDisconnected(curUser)
sConnectlog = sConnectlog .. "\n" .. "<"..GetTime() .. "|" .. 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
if sSDatalog ~= "" then
local f = appendto(SecondDatafile)
write(sSDatalog)
sSDatalog = ""
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

function GetTime()
s = date("%S")
h = date("%H")
m = date("%M")
d = date("%d")
mm = date("%m")
y = date("%y")
Date = "Day: "..d.."/"..mm.."/20"..y.."  Hour: "..h..":"..m..":"..s
return Date
end

OpConnected or OpDisconnected works in all kind of OPs.

Best regards, nErBoS
Title:
Post by: [NL]trucker on 28 February, 2004, 20:10:12
Nerbos

thnx for the quick reply if i find anything i will report back to you .