Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI( "DateAndTime" )
- wifi = "left"
- monitor = peripheral.wrap( "right" )
- timeAPI = "http://www.timeapi.org/utc/now"
- names = {}
- monitor.setTextScale( 1.5 )
- function stringSplit( str )
- local t = {}
- local function helper( word )
- table.insert( t, word )
- return ""
- end
- if not str:gsub( "%w+", helper ):find"%S" then
- return t
- end
- end
- function redrawPlayers()
- monitor.clear()
- local line = 0
- for player, table in pairs( names ) do
- line = line + 2
- local status = ""
- if "true" == names[player]["status"] then
- status = "Online"
- else
- status = "Last seen " .. DateAndTime.output( names[player]["seen"], "H:i (d/m)" )
- end
- monitor.setCursorPos( 5, line )
- monitor.write( tostring( player ) .. " - " .. status )
- end
- end
- function getTime()
- local currentTime = http.get( timeAPI )
- return currentTime.readAll()
- end
- function parseMsg( id, msg )
- local incomingLine = stringSplit( msg )
- if "playerstatus" == incomingLine[1] then
- local player = incomingLine[2]
- local status = incomingLine[3]
- if nil == names[player] then
- names[player] = {}
- names[player]["online"] = status
- names[player]["seen"] = "Unknown"
- end
- if "false" == status and "true" == names[player]["online"] then
- names[player]["seen"] = getTime()
- end
- names[player]["online"] = status
- end
- redrawPlayers()
- end
- rednet.open( wifi )
- while true do
- id, msg, time = rednet.receive()
- parseMsg( id, msg )
- end
- rednet.close( wifi )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement