2021-01-07 23:30:28 +00:00
|
|
|
local event = require("event")
|
|
|
|
local keyboard = require("keyboard")
|
|
|
|
local component = require("component")
|
2021-01-08 00:04:54 +00:00
|
|
|
local fs = require("filesystem")
|
2021-01-08 13:24:51 +00:00
|
|
|
local internet = require("internet")
|
2021-01-07 23:30:28 +00:00
|
|
|
local tunnel = component.tunnel
|
2021-01-08 01:09:46 +00:00
|
|
|
|
2021-01-08 01:44:49 +00:00
|
|
|
local success = "console: команда выполнена успешно"
|
|
|
|
local fail = "console: неизвестная команда - пиши help"
|
2021-01-08 01:09:46 +00:00
|
|
|
|
2021-01-08 00:08:54 +00:00
|
|
|
function os.dateRL(format)
|
|
|
|
if not fs.get("/").isReadOnly() then
|
|
|
|
local time = io.open("/tmp/.time", "w")
|
2021-01-08 01:09:46 +00:00
|
|
|
time:write()
|
|
|
|
time:close()
|
|
|
|
os.sleep(0.01)
|
|
|
|
return os.date(format, fs.lastModified("/tmp/.time") / 1002.7)
|
2021-01-08 00:08:54 +00:00
|
|
|
else
|
|
|
|
return os.date(format)
|
|
|
|
end
|
2021-01-08 00:04:54 +00:00
|
|
|
end
|
2021-01-08 01:09:46 +00:00
|
|
|
|
|
|
|
function handleMessage(msg)
|
2021-01-08 01:24:12 +00:00
|
|
|
if msg == "help" then
|
2021-01-08 01:09:46 +00:00
|
|
|
return success
|
2021-01-08 01:24:12 +00:00
|
|
|
elseif msg == "rain" then
|
2021-01-08 01:09:46 +00:00
|
|
|
return success
|
|
|
|
else
|
|
|
|
return fail
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-08 01:24:12 +00:00
|
|
|
function getUser(from)
|
2021-01-08 01:49:59 +00:00
|
|
|
if from == "b7585fb7-1ea4-4f94-b1a2-05e1cef76a1f" then
|
2021-01-08 01:24:12 +00:00
|
|
|
return "erius"
|
|
|
|
elseif from == "0952a2dd-23fa-4dd2-aefe-92e7cd6c77ce" then
|
|
|
|
return "DummyWalrus"
|
|
|
|
else
|
|
|
|
return "???"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-07 23:30:28 +00:00
|
|
|
while true do
|
2021-01-08 01:09:46 +00:00
|
|
|
local _, _, from, _, _, message = event.pull("modem_message")
|
2021-01-08 01:46:09 +00:00
|
|
|
local answer = handleMessage(tostring(message))
|
2021-01-08 01:46:52 +00:00
|
|
|
local log = "["..os.dateRL("%x %X").."] "..getUser(tostring(from))..": "..message.."\n".."["..os.dateRL("%x %X").."] "..answer
|
2021-01-08 00:35:28 +00:00
|
|
|
print(log)
|
2021-01-08 00:40:24 +00:00
|
|
|
local f = io.open("logs.txt", "a")
|
2021-01-08 01:24:12 +00:00
|
|
|
f:write(log.."\n")
|
2021-01-08 00:35:28 +00:00
|
|
|
f:close()
|
2021-01-08 01:44:49 +00:00
|
|
|
tunnel.send(answer)
|
2021-01-07 23:30:28 +00:00
|
|
|
end
|