Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local AMI
- local Bridge
- for i,v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "adventure map interface" then
- AMI = peripheral.wrap(v)
- elseif peripheral.getType(v) == "glassesbridge" then
- Bridge = peripheral.wrap(v)
- end
- end
- if not AMI then
- error("No AMI attached", 0)
- end
- if not Bridge then
- error("No bridge attaches", 0)
- end
- local Log = {}
- if fs.exists("log") then
- local File = fs.open("log", "r")
- Log = textutils.unserialize(File.readAll())
- File.close()
- end
- local function Save()
- local File = fs.open("log", "w")
- File.write(textutils.serialize(Log))
- File.close()
- end
- Bridge.clear()
- -- local Box = Bridge.addBox(10, 10, 200, 110, 0x000000, 0.5)
- local Texts = {}
- for i = 1, 10 do
- local Tex = Bridge.addText(10, i * 10, "", 0xFFFFFF)
- table.insert(Texts, Tex)
- end
- local Made = 0
- local Month, Day, Year, Hour, Minute
- local function TimeT()
- local NowH = http.get("http://www.timeapi.org/utc/4+hours+before+now?" .. textutils.urlEncode([[\m/\d/\Y/\H/\M]]))
- local Now = NowH.readAll()
- NowH.close()
- for i in string.gmatch(Now, "[^/]+") do
- i = tonumber(i)
- if Month then
- if Day then
- if Year then
- if Hour then
- Minute = i
- else
- Hour = i
- end
- else
- Year = i
- end
- else
- Day = i
- end
- else
- Month = i
- end
- end
- while true do
- sleep(60)
- Minute = Minute + 1
- if Minute == 60 then
- Hour = Hour + 1
- Minute = 0
- if Hour == 25 then
- Day = Day + 1
- Hour = 1
- end
- end
- end
- end
- local function PTime()
- return Month .. "/" .. Day .. "/" .. Year .. " " .. Hour .. ":" .. Minute
- end
- local function NewMess(Txt)
- Made = Made + 1
- if Made < 11 then
- Texts[Made].setText(Txt)
- else
- for i = 1, 9 do
- Texts[i].setText(Texts[i + 1].getText())
- end
- Texts[10].setText(Txt)
- end
- end
- local function ListenT()
- repeat sleep(1) until Month
- while true do
- local Event, P1, P2, P3, P4, P5 = os.pullEvent()
- if Event == "player_login" then
- table.insert(Log, {"Login", P1, PTime()})
- Save()
- print("[" .. PTime() .. "] " .. P1 .. " joined.")
- NewMess("[" .. PTime() .. "] " .. P1 .. " joined.")
- elseif Event == "player_logout" then
- table.insert(Log, {"Logout", P1, PTime()})
- Save()
- print("[" .. PTime() .. "] " .. P1 .. " left.")
- NewMess("[" .. PTime() .. "] " .. P1 .. " left.")
- elseif Event == "chat_message" then
- table.insert(Log, {"Message", P1, P2, PTime()})
- Save()
- print("[" .. PTime() .. "] " .. P1 .. ": " .. P2)
- NewMess("[" .. PTime() .. "] " .. P1 .. ": " .. P2)
- end
- end
- end
- -- [[ Threading ]]
- local Threads = {{coroutine.create(TimeT)}, {coroutine.create(ListenT)}}
- os.queueEvent("Init")
- while true do
- local Obj = {os.pullEventRaw()}
- if Obj[1] == "terminate" then
- break
- end
- for On = 1, #Threads do
- local TTab = Threads[On]
- if TTab then
- if TTab[2] and Obj[1] == TTab[2] then
- local Stat, Err = coroutine.resume(TTab[1], unpack(Obj))
- if Stat == false then
- printError(Err)
- os.queueEvent("terminate")
- break
- end
- TTab[2] = Err
- elseif not TTab[2] then
- local Stat, Err = coroutine.resume(TTab[1], unpack(Obj))
- if Stat == false then
- printError(Err)
- os.queueEvent("terminate")
- break
- end
- TTab[2] = Err
- end
- if coroutine.status(TTab[1]) == "dead" then
- table.remove(Threads, On)
- On = On - 1
- end
- end
- end
- if #Threads == 0 then
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement