PtokaX forum

Development Section => Your Developing Problems => Topic started by: dragos_sto on 20 September, 2006, 12:45:32

Title: user and ip log
Post by: dragos_sto on 20 September, 2006, 12:45:32
i bild a script ho make log whit user ip
not finish yet
i have one little problem
log ip dont work like i expected
if user have a nik whitout [] work ok
but if fave a nik like [dsl]dief
in this section :
      if string.find(line,usernam) then
         local _,_,des = string.find(line,"%b==(%d+)")
         des = des + 1
         count = 1
         ma = ma..""..usernam.."=="..des.."\r\n"
      else
         ma = ma..line.."\r\n"
      end
string.find not detect the to be this string in the line (user.sname)

some one whit some ideea

like usually i`m not a good writer .. sorry , and hope some one understand

final script posted at
http://forum.ptokax.org/index.php?topic=6421.0
Title: Re: user and ip log
Post by: Herodes on 20 September, 2006, 12:54:17
%b== shouldn't work....
cause it needs <>, (), [] or {}

please give the format of the logs...
what is an example line that the string.find(line,"%b==(%d+)") should match ?

Something noticable in the script of yours is this:
if io.open(pathIp.."/"..userip..ext) == nil then io.open(pathIp.."/"..userip..ext,"w") end
nice thinking ;) I'll do some testing but I think it should be ok,... have you checked that this behaves as expected ?
Title: Re: user and ip log
Post by: dragos_sto on 20 September, 2006, 13:16:39
the ideea work it to count the number o how many time
a user from ip x.x.x.x log on the hub and
and see what nick it used most

in theat section of script string.find
dont match the line ho it read ok
for example :
read value of line it - [dsl]dief==1
when make if string.find(line,usernam) then
where usernam = [dsl]dief
string.find return nil :(
Title: Re: user and ip log
Post by: dragos_sto on 20 September, 2006, 13:21:11
in rest the script work ok
and the log are ok beside that little problem above
no error return from the hub
Title: Re: user and ip log
Post by: Herodes on 20 September, 2006, 13:59:50
then try changing
local s,e, des= string.find(line,"%b==(%d+)")
to
local s,e, des = string.find( line, "%=%=(%d+)$" )
if you are on lua 5.1 then try changing string.find with string.match since it saves you from using the s,e variables..
local des = string.match( line, "%=%=(%d+)$")
Title: Re: user and ip log
Post by: dragos_sto on 21 September, 2006, 23:00:34
i whil ...
and post the result after testing
Title: Re: user and ip log
Post by: dragos_sto on 22 September, 2006, 00:25:26
no change ,
but ho i wrote above the problem it not at
local s,e, des= string.find(line,"%b==(%d+)")
i change the line but the problem it not gone
the problem persist
and like i write above it if user have thei nickname letter like []

read value of line it - [dsl]dief==1
when make if string.find(line,usernam) then
where usernam = [dsl]dief
string.find return nil
if i change whit string.match
no change :((
Title: Re: user and ip log
Post by: dragos_sto on 22 September, 2006, 00:58:41
modify the first post

it at most final version
after i solve the above problem :( :'(
Title: Re: user and ip log
Post by: Herodes on 22 September, 2006, 08:41:52
This is what you posted

      if string.find(line,usernam) then
         local _,_,des = string.find(line,"%b==(%d+)")
         des = des + 1
         count = 1
         ma = ma..""..usernam.."=="..des.."\r\n"
      else
         ma = ma..line.."\r\n"
      end


Try this one, read the comments,... ;)


--- use this function for making the usernam variable (a string) pure since the regular expression in the string.find is a string too
local function Purify( s )
    local t, r = { ['['] = 1, [']'] = 1, ['?'] = 1, ['+'] = 1, ['*'] = 1, ['.'] = 1, ['-'] = 1, ['%'] = 1, ['$'] = 1, ['^'] = 1, ['('] = 1, [')'] = 1, ['{'] = 1, ['}'] =1  }, ''
    for char in string.gmatch( s, '(.)' ) do
        local esc = ''
        if t[char] then esc = '%' end
        r = r..esc..char
    end
    return r
end
--- now your piece of script looks like this ... string.match applied..
      if string.find(line, Purify(usernam) ) then
         local des = string.match( line, "%S+==(%d+)" )
         des = des + 1
         count = 1
         ma = ma..usernam.."=="..des.."\r\n"
      else
         ma = ma..line.."\r\n"
      end

also you could do the following,...
if ( string.sub(line,  1, string.len(usernam) ) == usernam ) then
    local des = string.match ( line, "%S+%=%=(%d+)$" )
    des = des + 1
    count = 1
    ma = ma..usernam.."=="..des.."\r\n"
else
    ma = ma..line.."\r\n"
end
Title: Re: user and ip log
Post by: dragos_sto on 22 September, 2006, 12:01:16
i will test first
Code (lua) Select

if ( string.sub(line,  1, string.len(usernam) ) == usernam ) then
    local des = string.match ( line, "%S+%=%=(%d+)$" )
    des = des + 1
    count = 1
    ma = ma..usernam.."=="..des.."\r\n"
else
    ma = ma..line.."\r\n"
end


and post the result after
Title: Re: user and ip log
Post by: dragos_sto on 22 September, 2006, 12:11:01
now work ok
but i have one question
why string.find or string.match return nil ...  ???

10x a lot for help
Title: Re: user and ip log
Post by: Herodes on 22 September, 2006, 12:25:50
Quote from: dragos_sto on 22 September, 2006, 12:11:01
now work ok
but i have one question
why string.find or string.match return nil ...  ???

10x a lot for help
because they don't find anything that matches the regular expression we provide it with...

- check what the 'line' var is just before it goes into the string.find/match
- check the regular expression with a sample target string,... in this case do a local line = "nick==4"
Title: Re: user and ip log
Post by: dragos_sto on 22 September, 2006, 13:27:35
the file log look the same like for other ip
when sendtoall the line to se what value return
in front of the nick appear "-" from nowhere
Title: Re: user and ip log
Post by: Herodes on 22 September, 2006, 13:32:16
Maybe trying "(%d+)$" instead of "%S+%=%=(%d+)$" will help,... it means : the number(s) at the end of the string
Title: Re: user and ip log
Post by: sourabhiitm on 20 August, 2007, 13:13:54
I have a problem ..
This script is startng and working fine only for some time with ptokex 0.3.6.  after some time (approx 1 min) ,
It is giving an error

UserInfo.lua:103: bad argument #1 to 'lines' (UserInfo/skamslast.log: No such file or directory)
and it is not working anymore.. ???
Some body help!!!!!!
By skamlast I mean.. It is a user.. wvrytime some diferent name is coming , which is basicaly name of any user..
Title: Re: user and ip log
Post by: dragos_sto on 27 August, 2007, 22:39:55
skamslast.log exist in userinfo folder ?
delete the file and see if the error ocure
Title: Re: user and ip log
Post by: sourabhiitm on 06 October, 2007, 08:56:40
I m using Rincefield IP log now .. SO i havnt tried. :)