PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Conversion Requests => Topic started by: billli on 21 December, 2011, 23:49:30

Title: Help with this bit of script
Post by: billli on 21 December, 2011, 23:49:30
Code: [Select]
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 :)