Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local serialization = require("serialization")
- local sides = require("sides")
- local m = component.modem
- clients = {}
- processed = {}
- local function has_value (tab, val)
- for index, value in ipairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- PORT = 666
- m.open(PORT)
- print("Working port opened")
- -- Main While
- while true do
- local _, localNetworkCard, remoteAddress, port, distance, payload = event.pull("modem_message")
- if payload ~= nil then
- local res = serialization.unserialize(payload)
- if not has_value(processed, res["id"]) then
- print(tostring(res["id"]) .. ": Message Received")
- local request = res["type"]
- print(" Payload deserialized")
- if clients[remoteAddress] == nil then
- if request == "starter" then
- clients[remoteAddress] = res["name"]
- local resp = {}
- resp["serveraddr"] = m.address
- resp["status"] = "ok"
- print(" New starter request found")
- print(" Sender: " .. res["name"] .. " @ " .. remoteAddress)
- os.sleep(3)
- m.send(remoteAddress, PORT, serialization.serialize(resp))
- print(" Machine added and response sended")
- end
- end
- if request == "disconnect" then
- print(" Found disconnection request")
- clients[remoteAddress] = nil
- print(" Client " .. remoteAddress .. " succesfully disconnected")
- end
- if request == "launch" then
- print(" Launch request received, starting bomb sequence...")
- component.redstone.setOutput(sides.right, 15)
- print(" Frontal door opened")
- component.redstone.setOutput(sides.back, 15)
- print(" TNT Ignited")
- os.sleep(1)
- component.redstone.setOutput(sides.back, 0)
- os.sleep(5)
- print(" Launch done, closing door")
- component.redstone.setOutput(sides.right, 0)
- print(" Door closed, sequence terminated")
- end
- processed[#processed+1] = res["id"]
- print("\n")
- end
- end
- end
Add Comment
Please, Sign In to add comment