Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("bottom")
- --ease of use function ftw!
- function reply(text)
- rednet.broadcast(text)
- print("replied: "..text)
- end
- function rec(timeout)
- if timeout == nil then
- id, msg, d = rednet.receive()
- else
- id, msg, d = rednet.receive(timeout)
- end
- print("Message received!")
- end
- --Real code now;
- function loadFile()
- local check = fs.exists("messages")
- if check == true then
- shell.run("messages")
- else
- saveFile(true)
- end
- end
- function saveFile(gen)
- if gen == nil then
- w = fs.open("messages", "a")
- w.writeLine("center("..[["]]..MESSAGE..[["]]..")")
- w.writeLine("p.setTextColor(colors.yellow)")
- w.writeLine("center("..[["]].."-"..USER..[["]]..")")
- w.writeLine("p.setTextColor(colors.white)")
- w.close()
- os.reboot()
- else
- w = fs.open("messages", "w")
- w.writeLine("p = peripheral.wrap("..[["]].."top"..[["]]..")")
- w.writeLine("p.setTextScale(1)")
- w.writeLine("p.clear()")
- w.writeLine("p.setCursorPos(1,1)")
- w.writeLine("function center(text)")
- w.writeLine("local x, y = p.getSize()")
- w.writeLine("local x2, y2 = p.getCursorPos()")
- w.writeLine("local length = text:len()")
- w.writeLine("if length > x then")
- w.writeLine("while true do")
- w.writeLine("if length >= x then")
- w.writeLine("p.write(text)")
- w.writeLine("text = string.sub(text, (x + 1))")
- w.writeLine("length = length - x")
- w.writeLine("y2 = y2 + 1")
- w.writeLine("p.setCursorPos(1, y2)")
- w.writeLine("else")
- w.writeLine("p.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)")
- w.writeLine("p.write(text)")
- w.writeLine("y2 = y2 + 1")
- w.writeLine("p.setCursorPos(1, y2)")
- w.writeLine("break")
- w.writeLine("end")
- w.writeLine("end")
- w.writeLine("else")
- w.writeLine("p.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)")
- w.writeLine("p.write(text)")
- w.writeLine("y2 = y2 + 1")
- w.writeLine("p.setCursorPos(1, y2)")
- w.writeLine("end")
- w.writeLine("end")
- w.writeLine("p.setTextColor(colors.orange)")
- w.writeLine("center("..[["]].."Server Message Board"..[["]]..")")
- w.writeLine("local x, y = p.getSize()")
- w.writeLine("for i = 1, x do")
- w.writeLine("p.write("..[["]].."~"..[["]]..")")
- w.writeLine("end")
- w.writeLine("p.setCursorPos(1, 3)")
- w.writeLine("p.setTextColor(colors.white)")
- w.close()
- os.reboot()
- end
- end
- function re()
- rec()
- if msg == "start" then
- reply("go on")
- while true do
- id, mssg, d = rednet.receive(15)
- if mssg == "user" then
- reply(".")
- id, USER, d = rednet.receive(15)
- print("received user: "..USER)
- reply(".")
- elseif mssg == "message" then
- reply(".")
- id, MESSAGE, d = rednet.receive(15)
- print("received msg: "..MESSAGE)
- reply(".")
- elseif mssg == "end" then
- print("Transmission over")
- saveFile()
- break
- end
- end
- else
- os.reboot()
- end
- end
- loadFile()
- re()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement