Help*** removing lines?
 

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

Help*** removing lines?

Started by ruler, 04 June, 2004, 15:55:36

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ruler

howdy
does anyone have a simple way of removing a line from a text file?
the type of file i want to use will hold all the nicks of all unregistered users in the hub.
as the user leaves the hub, the script hopfully will remove that nick from the list in the text file and as they enter it will add the nick.

thanks

The Direct Connect Global Banlist get protected.

nErBoS

Hi,

Try this one...

--Requested by ruler 
--Made by nErBoS

sBot = "User Logger"

arrUserLog ={}
fUserLog = "userlog.dat"

function Main()
	frmHub:RegBot(sBot)
	LoadFromFile(fUserLog)
end

function OnExit()
	SaveToFile(fUserLog , arrUserLog , "arrUserLog")
end

function NewUserConnected(user)
	arrUserLog[user.sName] = "logged"
end

OpConnected = NewUserConnected

function UserDisconnected(user)
	arrUserLog[user.sName] = nil
end

OpDisconnected = UserDisconnected

function Serialize(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");

	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");

	sTab = sTab or "";
	sTmp = ""

	sTmp = sTmp..sTab..sTableName.." = {\n"

	for key, value in tTable do
		local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

		if(type(value) == "table") then
			Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end

		sTmp = sTmp..",\n"
	end

	sTmp = sTmp..sTab.."}"
	return sTmp
end

function SaveToFile(file , table , tablename)
	writeto(file)
	write(Serialize(table, tablename))
	writeto()
end

function LoadFromFile(file)
	if (readfrom(file) ~= nil) then
		readfrom(file)
		dostring(read("*all"))
		readfrom()
	end
end

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

ruler

thanks nErBoS
just what i was looking for :)
i spent hours searching the forum but couldnt find anything.
thanks again

regards

The Direct Connect Global Banlist get protected.

nErBoS

Hi,

Made a little update to clean the list if the HUB is shutdown...

--Requested by ruler 
--Made by nErBoS

sBot = "User Logger"

arrUserLog ={}
fUserLog = "userlog.dat"

function Main()
	frmHub:RegBot(sBot)
	LoadFromFile(fUserLog)
	CheckTable()
end

function OnExit()
	SaveToFile(fUserLog , arrUserLog , "arrUserLog")
end

function NewUserConnected(user)
	arrUserLog[user.sName] = "logged"
end

OpConnected = NewUserConnected

function UserDisconnected(user)
	arrUserLog[user.sName] = nil
end

OpDisconnected = UserDisconnected

function CheckTable()
	local usr,aux
	for usr, aux in arrUserLog do
		if (GetItemByName(usr) == nil) then
			arrUserLog[usr] = nil
		end
	end
end

function Serialize(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");

	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");

	sTab = sTab or "";
	sTmp = ""

	sTmp = sTmp..sTab..sTableName.." = {\n"

	for key, value in tTable do
		local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

		if(type(value) == "table") then
			Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end

		sTmp = sTmp..",\n"
	end

	sTmp = sTmp..sTab.."}"
	return sTmp
end

function SaveToFile(file , table , tablename)
	writeto(file)
	write(Serialize(table, tablename))
	writeto()
end

function LoadFromFile(file)
	if (readfrom(file) ~= nil) then
		readfrom(file)
		dostring(read("*all"))
		readfrom()
	end
end

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

ruler

nice peice of code and works just fine  8)
thanks

The Direct Connect Global Banlist get protected.

SMF spam blocked by CleanTalk