Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scanner = peripheral.wrap("left")
- rednet.open("right")
- timeInterval = 1
- logOutputFile = "playerLog"
- newLogTitle = "New logging session started."
- permittedIDs = {}
- -- To add a new id, just put the id into the table above as a value
- time = {m = -timeInterval, h = 0, d = 0}
- function main()
- while true do
- players = scanner.getPlayers()
- time.m = time.m + timeInterval
- if time.m >= 60 then
- time.m = time.m - 60
- time.h = time.h + 1
- if players[1] == nil then logger("Nobody is here.", false) end
- end
- if time.h >= 24 then time.h = time.h - 24 time.d = time.d + 1 end
- function logger(input, title)
- logFile = fs.open(logOutputFile,"a")
- log = input
- if title == false then
- log = "[" .. tostring(time.m) .. "/" .. tostring(time.h) .. "/" .. tostring(time.d) .. "] " .. input
- end
- print(log)
- logFile.writeLine(log)
- logFile.close()
- end
- if time.m == 0 and time.h == 0 and time.d == 0 then logger("\n" .. newLogTitle, true) end
- for i=1,#players do
- for key,value in pairs(players[i]) do
- if key == "name" and value ~= nil then
- logger(value, false)
- end
- end
- end
- sleep(timeInterval * 60)
- end
- end
- function respond()
- while true do
- local currID, msg = rednet.receive()
- for i=1,#permittedIDs do
- if permittedIDs[i] == currID then
- if msg == "sendScan" then
- local logFile = fs.open(logOutputFile,"r")
- logFileContents = logFile.readAll()
- logFile.close()
- rednet.send(currID,logFileContents)
- break
- end
- end
- end
- end
- end
- parallel.waitForAll(main,respond)
Advertisement
Add Comment
Please, Sign In to add comment