Help with this bit of script
 

Help with this bit of script

Started by billli, 21 December, 2011, 23:49:30

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billli

require "socket"

-- config begin

logmc = 1 -- log main chat, 1 = yes, 0 = no

mclogfile = "/mc.txt" -- direction to text file name for main chat log
maxsize = 51234

function replacechars (text)
	text = string.gsub (text, "<", "&lt;")
	text = string.gsub (text, ">", "&gt;")
	text = string.gsub (text, string.char (10), string.char (10).."<br />- ")
	return text
end


function writemclog (logstring)
	logfile = assert (io.open (mclogfile, "a"))
	if logfile then
		logsize = logfile:seek ("end")
		logstring = replacechars (logstring).."\r\n<br />"

		if logsize >= maxsize then
			logfile:close ()
			os.rename (mclogfile, mclogfile.."."..os.date ("%Y.%m.%d.%H.%M.%S"))
			logfile = assert (io.open (mclogfile, "a"))
			logfile:write (logstring)
			logfile:close ()
		else
			logfile:write (logstring)
			logfile:close ()
		end
	end
end


function ChatArrival (user,data)
	
		writemclog ("["..socket.gettime().."] &lt;"..user.."&gt; "..data)

end


It just logs the main chat to a file called mc.txt
Any pointers would be greatly appreciated :)

SMF spam blocked by CleanTalk