PtokaX forum

Development Section => Your Developing Problems => Topic started by: nErBoS on 27 February, 2004, 14:44:18

Title: Ptokax 0.3.3.0 syntax erros...
Post by: nErBoS on 27 February, 2004, 14:44:18
Hi all,

Geting this error on many of my scripts which works without errors in the TD4

for eg...

Syntax error: bad argument #1 to `strfind' (string expected, got nil)
stack traceback:
   1:  function `strfind' [C]
   2:  function `DataArrival' at line 113 [file `C:\teste\Ptokax 3.30\scripts\teste.lua']

at line 113 i have this...

if strfind(curUser.sMyInfoString, "
Did something changed in the new version ???

Best regards, nErBoS
Title:
Post by: NightLitch on 27 February, 2004, 15:02:19
I have the same erros sometimes when someother script is loaded before my NXS-3. if NXS-3 loads first I don't have those errors.

try. load that bot first then the others.
Title:
Post by: nErBoS on 27 February, 2004, 15:13:57
In this case is only one bot that i am using...

Here is it...

-------------------------------------------------------
---------------- 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 strfind(curUser.sMyInfoString, "_,b, ver = strfind(curUser.sMyInfoString, "V:(.*),M:") --- ADDED TO SEE CLIENT AND VERSION
client = "oDC"
version = "V:"..ver
elseif strfind(curUser.sMyInfoString, "<++") then
_,b, ver = strfind(curUser.sMyInfoString, "V:(.*),M:") --- ADDED TO SEE CLIENT AND VERSION
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

Have to create a DataLog folder in the script folder.

I?m using ptokax 0.3.3.0 debug 15.18, is there any more recently coud be that.

Best regards, nErBoS
Title:
Post by: tezlo on 27 February, 2004, 15:22:42
the user object cant have a sMyInfoString property until the client actually sends the first $MyINFO
Title:
Post by: NightLitch on 27 February, 2004, 15:42:01
ptokax 0.3.3.0 debug 15.18 have a tendes to lose MyInfo quite often.

that version is not stable.

ptokax 0.3.3.0 debug 15.25 is the best so far in my eyes.

/NL
Title:
Post by: tezlo on 27 February, 2004, 15:51:27
MyINFOs dont get "lost".. user.sMyInfoString is always nil on $ValidateNick (for instance) because it comes before $MyINFO
Title:
Post by: nErBoS on 27 February, 2004, 16:46:26
Hi,

If i understod tezlo the script isn't catching user.sMyInfoString because is nil, why ??? is this a bug ?? please examplain me..

Best regards, nErBoS
Title:
Post by: tezlo on 27 February, 2004, 16:59:57
i just did.. its not a bug its obvious
everytime DataArrival() triggers the script tries to strfind something in user.sMyInfoString
in the login sequence.. $Key and $ValidateNick come before $MyINFO so there is no user.sMyInfoString at that point
Title:
Post by: Guibs on 27 February, 2004, 17:03:46
Hi there,

tezlo is right, yep, & it's not a bug,,

When a user log, there is an order,,
In first, the datas come from:
> function DataArrival(curUser, sData) < all incoming datas are going thrue this function, and datas on login received are in first:
"$ValidateNick" key < nick is coming, & not yet the user :)
"$MyINFO" < user has send Client infos,, & is now connected
Then, function NewUserConnected(curUser) is called, like a confirmation,...

So, the lines like:
----
if strfind(curUser.sMyInfoString, "----
is right only if user has send the "$MyINFO" key,

So, after the line > elseif s == "$MyINFO" then  < you could try:
----
elseif s == "$MyINFO" then
Statistics.MyINFO = Statistics.MyINFO + 1
if strfind(curUser.sMyInfoString, " _,b, ver = strfind(curUser.sMyInfoString, "V:(.*),M:") --- ADDED TO SEE CLIENT AND VERSION
client = "oDC"
version = "V:"..ver
elseif strfind(curUser.sMyInfoString, "<++") then
_,b, ver = strfind(curUser.sMyInfoString, "V:(.*),M:") --- ADDED TO SEE CLIENT AND VERSION
client = "DC++"
version = "V:"..ver
else
client = "unknown"
version = "unknown"
end
sSDatalog = sSDatalog .. "\n" .. "<|"..date .. "|" .. curUser.sName .. "|" .. curUser.sIP .. "|> " .. client .. "|" .. version
----
It should maybe work better,,

good luck,, ;)
Title:
Post by: NightLitch on 27 February, 2004, 17:07:54
QuoteOriginally posted by tezlo    
MyINFOs dont get "lost".. user.sMyInfoString is always nil on $ValidateNick (for instance) because it comes before $MyINFO

Well they do, many of us here have had those problems in the scripts. I don't know now if your just talking about this script above. But Optimus had the same problem a while ago when 15.18 was the latest. Plop had it.

We by passed it with:
if curUser.sMyInfoString==nil then

or

if (strsub(data,1,7) == "$MyINFO") then
   local _,_,MyInfo = strfind(data, "(.*)")
   if MyInfo==nil then

this took care of my problem and I got the solve from Optimus script.

/NL
Title:
Post by: NightLitch on 27 February, 2004, 17:09:31
Am I alone remembering this "bug".

Plop, Optimus.... others...

I Am so sure of this.
Title:
Post by: tezlo on 27 February, 2004, 17:14:27
its not what causes the error anyway..
are you sure you werent trying to get sMyInfoString on $ValidateNick too?
Title:
Post by: nErBoS on 27 February, 2004, 17:27:27
Hi,

Thanks to all complete understood on this metter, solved all my bugs :)

Best regards, nErBoS
Title:
Post by: NightLitch on 27 February, 2004, 18:02:07
QuoteOriginally posted by tezlo    
its not what causes the error anyway..
are you sure you werent trying to get sMyInfoString on $ValidateNick too?

 
Yes Am sure, Try doing this, install my bot NXS-3 and anther script that uses strfind in NewUserConnected for ex:

NXS-3 2.9 and a ip-bot that strfind in NewUserConnected or a ISPChecker etc.

And that NXS-3 loads last. then you have a strfind error.

Same error occurr in Glory if something before main script, why ???

/NL
Title:
Post by: kepp on 01 March, 2004, 06:37:51
It's nothing else than a bug indeed..