Author Topic: Help with this bit of script  (Read 1575 times)

0 Members and 1 Guest are viewing this topic.

Offline billli

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Help with this bit of script
« 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 :)

PtokaX forum

Help with this bit of script
« on: 21 December, 2011, 23:49:30 »