PtokaX forum

Archive => Archived 5.1 boards => Help with scripts => Topic started by: nEgativE on 06 June, 2007, 21:41:53

Title: [help] Datalog.lua
Post by: nEgativE on 06 June, 2007, 21:41:53
Hello all, could someone check this syntax error ? using PtokaX 0.360

Error:
datalog.lua:61: '=' expected near 'function'

Script:

-------------------------------------------------------
---------------- 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
Title: Re: [help] Datalog.lua
Post by: Psycho_Chihuahua on 06 June, 2007, 22:03:25
1. In Line 58 the "a" is not supposed to be there
2. Line 65 should read:         loadStatistics(Statisticsfile)

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

--// 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
Title: Re: [help] Datalog.lua
Post by: nEgativE on 06 June, 2007, 22:30:18
thx Psycho_Chihuahua, working fine now  :D
Title: Re: [help] Datalog.lua
Post by: Psycho_Chihuahua on 06 June, 2007, 23:01:17
your welcome