Get ip o nicks from texts
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Get ip o nicks from texts

Started by nErBoS, 26 October, 2003, 18:50:35

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nErBoS

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
--## nErBoS Spot ##--

nErBoS

I still need help out here please !!
--## nErBoS Spot ##--

tezlo

you need to read the whole file and write it all again without the desired nick/ip

nErBoS

And how can i do that ???
--## nErBoS Spot ##--

klownietklowniet

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()

   
[ > DC - UniteD < ]

nErBoS

#5
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 : )
--## nErBoS Spot ##--

klownietklowniet

give me a format...
[ > DC - UniteD < ]

nErBoS

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
--## nErBoS Spot ##--

klownietklowniet

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()
[ > DC - UniteD < ]

nErBoS

#9
Yes is working for the ip : )

can it be made for nick too ??
--## nErBoS Spot ##--

tezlo


nErBoS

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 ??
--## nErBoS Spot ##--

klownietklowniet

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..?
[ > DC - UniteD < ]

nErBoS

Because i want only to remove the last ban !!
--## nErBoS Spot ##--

klownietklowniet

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... :-(
[ > DC - UniteD < ]

tezlo

i think hes logging users who ban.. not users who get banned
but then whats the point in removing any of these ?!

nErBoS

Ok, thanks both for all the help !!

Best regards, nErBoS
--## nErBoS Spot ##--

nErBoS

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 ??
--## nErBoS Spot ##--

nErBoS

Need some help please !!
--## nErBoS Spot ##--

Guibs

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,, ;)
-- Please,... don\'t ask help in Pm,...Forums are made for that, to help everyone & my Inbox pm will be safe,... Thks,,  :))  --
CB forum     /     CB Home page

nErBoS

Yes it is working but the reason only sends the first word of the reason :(
--## nErBoS Spot ##--

Guibs

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,, ;)
-- Please,... don\'t ask help in Pm,...Forums are made for that, to help everyone & my Inbox pm will be safe,... Thks,,  :))  --
CB forum     /     CB Home page

nErBoS

Yep working, Thanks Guibs.

Best regards, nErBoS
--## nErBoS Spot ##--

SMF spam blocked by CleanTalk