Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- for i,v in pairs(sides) do
- rednet.open(v)
- end
- local rf = "/files"
- local clients = {}
- local stx, sty = term.getSize()
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function drawlist(title, listr, num)
- clear()
- term.setTextColor(colors.lime)
- local list = {}
- print(title.."\n")
- for i,v in pairs(listr) do
- list[i] = v
- end
- local start = 1
- local last = #list
- if num > sty - 4 then
- start = num - (sty - 4)
- end
- local cnt = 0
- for i = start, #list do
- if cnt > sty - 4 then
- last = last - 1
- cnt = cnt - 1
- end
- cnt = cnt + 1
- end
- for m = start, last do
- local tor = true
- if tor == true then
- if m == num then
- term.setTextColor(colors.white)
- write("[")
- term.setTextColor(colors.lime)
- write("-")
- term.setTextColor(colors.white)
- write("]")
- term.setTextColor(colors.lime)
- print(" "..list[m])
- else
- term.setTextColor(colors.white)
- print("[ ] "..list[m])
- end
- end
- end
- end
- function getKey()
- local rt = nil
- function lop()
- local e, a1 = os.pullEvent("key")
- if a1 == 200 then
- rt = "up"
- elseif a1 == 208 then
- rt = "down"
- elseif a1 == 28 then
- rt = "enter"
- else
- lop()
- end
- end
- lop()
- repeat sleep(0) until rt ~= nil
- return rt
- end
- function ch(title, list)
- clear()
- local ind = 1
- local lcopy = list
- drawlist(title, lcopy, ind)
- local rt = nil
- cycle = function()
- local ke = getKey()
- if ke == "up" then
- if ind > 1 then
- ind = ind - 1
- else
- ind = #list
- end
- drawlist(title, lcopy, ind)
- cycle()
- elseif ke == "down" then
- if ind < #list then
- ind = ind + 1
- else
- ind = 1
- end
- drawlist(title, lcopy, ind)
- cycle()
- elseif ke == "enter" then
- rt = ind
- end
- end
- cycle()
- repeat sleep(0) until rt ~= nil
- return ind
- end
- if not fs.exists(rf) then
- fs.makeDir(rf)
- end
- local function a1()
- while true do
- local tr = ch("Grief reports", {"View reports", "Delete reports"})
- if tr == 1 then
- while true do
- local lst = fs.list(rf)
- table.insert(lst, 1, "Back")
- local yu = ch("Choose a report to view", lst)
- if yu ~= 1 then
- shell.run("edit", rf.."/"..lst[yu])
- else
- break
- end
- end
- elseif tr == 2 then
- while true do
- local lst = fs.list(rf)
- table.insert(lst, 1, "Back")
- local yu = ch("Choose a report to delete", lst)
- if yu ~= 1 then
- local conf = ch("Are you sure you want to delete this report?", {"Yes", "No"})
- if conf == 1 then
- fs.delete(rf.."/"..lst[yu])
- end
- else
- break
- end
- end
- end
- end
- end
- local function a2()
- while true do
- local id, msg = rednet.receive()
- local isi = false
- for i,v in pairs(clients) do
- if v == id then
- isi = true
- end
- end
- if isi == true then
- local ty = fs.open(rf.."/"..math.random(1, 10000)+math.random(1, 1000)-math.random(1, 100), "w")
- ty.write(msg)
- ty.close()
- end
- end
- end
- parallel.waitForAny(a1, a2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement