PtokaX forum

Development Section => Your Developing Problems => Topic started by: nErBoS on 26 October, 2003, 18:50:35

Title: Get ip o nicks from texts
Post by: nErBoS on 26 October, 2003, 18:50:35
Hi all,

How can i remove a ip or nick from a text file for example:

when ever i do this commands !kick, !ban or nick ban
i made this in the end of the comand function

appendto(Banlist)
write("\r\n"..userToBeKicked.sName.."\t"..userToBeKicked.sIP.."\t"..reason)
writeto()

Now i would like to know how to remove by the ip or nick
in the banlist file. The search for the nick or ip int the banlist file must be from the end to the start to remove only the last ban from the nick !!

Can anyone help me out here ??

Best regards, nErBoS
Title:
Post by: nErBoS on 28 October, 2003, 01:18:24
I still need help out here please !!
Title:
Post by: tezlo on 28 October, 2003, 01:25:30
you need to read the whole file and write it all again without the desired nick/ip
Title:
Post by: nErBoS on 28 October, 2003, 13:27:23
And how can i do that ???
Title:
Post by: klownietklowniet on 28 October, 2003, 14:17:27
Maybe something like:

  -- first read the whole file

   local tmp = ""
   readfrom(Banlist) -- or the banlist filename in quotes

   while 1 do
      local line = read()
      if (line == nil) then
         break
      else
         -- do some filtering!
         if line == "ip number to remove" then
         else
            -- write to file if it's not the one we want to remove (we append to a list for now)
            tmp = tmp .. line .. "\r\n"
         end
      end
   end
   readfrom()

   appendto("script_data/newreggedusers.txt")
      write(tmp)
   writeto()

   
Title:
Post by: nErBoS on 28 October, 2003, 16:48:56
Yes that works if the line was only the ip or nick but in my case in one line i have ip, user name and reason !!

How can i solve that ??


PS: Great to have tezlo and klownietklowniet back : )
Title:
Post by: klownietklowniet on 28 October, 2003, 18:15:42
give me a format...
Title:
Post by: nErBoS on 28 October, 2003, 18:28:36
My ban, nickban and kickban have this on the end

appendto(Banlist)
write("\r\n"..userToBeKicked.sName.."\t"..userToBeKicked.sIP.."\t"..reason)
writeto()

In the text file it will be like this

nErBoS   127.0.0.1   reason
Title:
Post by: klownietklowniet on 29 October, 2003, 01:39:32
Haven't tryed it.. but try something like this:

 -- first read the whole file



   local tmp = ""

   readfrom(Banlist) -- or the banlist filename in quotes

   while 1 do
      local line = read()
      if (line == nil) then
         break
      else
         -- do some filtering!
         local s, e, ip = strfind(line, "%S*%s(%S*)%s")
         if ip == "ip number to remove" then
         else
            -- write to file if it's not the one we want to remove (we append to a list for now)
            tmp = tmp .. line .. "\r\n"
         end
      end
   end
   readfrom()

   appendto("script_data/newreggedusers.txt")
      write(tmp)
   writeto()
Title:
Post by: nErBoS on 29 October, 2003, 03:08:59
Yes is working for the ip : )

can it be made for nick too ??
Title:
Post by: tezlo on 29 October, 2003, 03:36:40
yep (http://www.lua.org/manual/4.0/manual.html#pm)
Title:
Post by: nErBoS on 29 October, 2003, 14:08:33
Done many thanks tezlo the manual its very useful : )

Just one more thing I would like only to delete the last ban made for the ip or nick, for example if the nick or ip gave more then one ban i would like to remove only the last ban for that i need..

how can I make this function read from the end to the top ??

how can i make the function that when found the ip or nick stop the search for that ip or nick and write the rest of the file ??
Title:
Post by: klownietklowniet on 30 October, 2003, 04:04:03
Why would you wanna do that?

You mean you want to have double instances in the ban file? So if an ip number is banned 4 timres, you gotta unban it 4 times aswell?... or..?
Title:
Post by: nErBoS on 30 October, 2003, 13:37:30
Because i want only to remove the last ban !!
Title:
Post by: klownietklowniet on 30 October, 2003, 19:33:32
Doesn't make sence to me. You eather unban a user's ip, as in removing ALL instances, or you remove none. Just the last doesn't make any difference... or sence to me. Besides, it's not worth it.

You could do it from the beggining of the file and remove just one, then write the rest of the file dirrectly... but from the end towards the beggining there is no easy way to read.

You would have to read it into a list... then do a for loop from the end towards the beggining of that list and check for first accurance of the ip, remove it from the list, then break ot of the loop and finally write the new Banlist. Takes some resources.... and as I said, I don't see the point... :-(
Title:
Post by: tezlo on 30 October, 2003, 19:39:37
i think hes logging users who ban.. not users who get banned
but then whats the point in removing any of these ?!
Title:
Post by: nErBoS on 31 October, 2003, 00:51:34
Ok, thanks both for all the help !!

Best regards, nErBoS
Title:
Post by: nErBoS on 02 November, 2003, 17:28:25
Hi again can you help me out here i am callig this function

function SeeBans(user, data)

GetArgML(data)
local tmp = ""

   readfrom(Banlist)

   while 1 do
      local line = read()
      if (line == nil) then
         break
else
         local s, e, nick, ip = strfind(line, "(%S*)%s(%S*)%s%S*")
         if (nick == arg or ip == arg) then
   tmp = tmp..""..line.."\r\n"
         else
       tmp = tmp..""
 end
         end
      end
readfrom()
user:SendPM(Bot, tmp)
end

This sends me back if arg is banned the lines of bans which have nick, ip and reason .

How can i make that the line only sends back the reason ??
Title:
Post by: nErBoS on 04 November, 2003, 01:15:53
Need some help please !!
Title:
Post by: Guibs on 04 November, 2003, 03:17:50
Hi there,,

Maybe that one,.... ( not tested, so.... )
------
function SeeBans(user, data)

GetArgML(data)
local tmp = ""

   readfrom(Banlist)

   while 1 do
      local line = read()
      if (line == nil) then
         break
else
         local s, e, nick, ip, reason = strfind(line, "(%S*)%s(%S*)%s(%S*)")
         if (nick == arg or ip == arg) then
   tmp = tmp..""..arg.." banned for: "..reason.."\r\n"
         else
       tmp = tmp..""
 end
         end
      end
readfrom()
user:SendPM(Bot, tmp)
end
------

Good luck,, :)

l8tr,, ;)
Title:
Post by: nErBoS on 04 November, 2003, 04:17:10
Yes it is working but the reason only sends the first word of the reason :(
Title:
Post by: Guibs on 06 November, 2003, 00:23:51
Hi,,

yup,, just modifye the way to parse,,... remplace:
----
local s, e, nick, ip, reason = strfind(line, "(%S*)%s(%S*)%s(%S*)")
----
by:
----
local s, e, nick, ip, reason = strfind(line, "(%S*)%s(%S*)%s(.*)")
----
& you should have the entire reason,,

l8tr,, ;)
Title:
Post by: nErBoS on 06 November, 2003, 02:38:24
Yep working, Thanks Guibs.

Best regards, nErBoS