Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local client
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- local function ports()
- for i,v in pairs(sides) do
- rednet.open(v)
- end
- end
- ports()
- while true do
- local id, msg = rednet.receive()
- sleep(0)
- local isP = false
- if id == client then
- isP = true
- end
- if isP == false and string.sub(msg, 1, 6) == "PROXY:" then
- isP = true
- client = id
- print("New client")
- end
- if isP == true and string.sub(msg, 1, 6) == "PROXY:" then
- local tbl = textutils.unserialize(string.sub(msg, 7))
- if not tbl then tbl = {} end
- if tbl.send and type(tbl.send) == "number" and tbl.send > -1 then
- pcall(function()
- rednet.send(tbl.send, tbl.message)
- print("Sent new message to "..tbl.send)
- end)
- elseif tbl.send and tbl.send == "broadcast" then
- pcall(function()
- rednet.broadcast(tbl.message)
- print("Broadcasted message")
- end)
- end
- elseif client ~= nil then
- pcall(function()
- rednet.send(client, textutils.serialize({rep=id, message=msg}))
- print("Sent message to client")
- end)
- else
- print("Message was not valid isP was "..tostring(isP))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement