phone_server.lua
40 lines · 936 B
PHONE APP MINE--
Copy & run
wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/Maengorn/phone_server.lua
| 1 | --PHONE APP MINE-- |
| 2 | |
| 3 | local SERVER_PORT = 420 |
| 4 | local PHONE_PORT = 69 |
| 5 | |
| 6 | function findWirelessModem() |
| 7 | for _, side in ipairs(peripheral.getNames()) do |
| 8 | if peripheral.getType(side) == "modem" and peripheral.call(side, "isWireless") then |
| 9 | return side |
| 10 | end |
| 11 | end |
| 12 | return nil |
| 13 | end |
| 14 | |
| 15 | local modemSide = findWirelessModem() |
| 16 | if not modemSide then |
| 17 | error("No wireless modem found!") |
| 18 | end |
| 19 | modem = peripheral.wrap(modemSide) |
| 20 | local size = vector.new() |
| 21 | |
| 22 | if (#arg == 3) then |
| 23 | size.x = tonumber(arg[1]) |
| 24 | size.y = tonumber(arg[2]) |
| 25 | size.z = tonumber(arg[3]) |
| 26 | else |
| 27 | print("NO SIZE GIVEN") |
| 28 | os.exit(1) |
| 29 | end |
| 30 | |
| 31 | local target = vector.new(gps.locate()) |
| 32 | local payloadMessage = string.format("%d %d %d %d %d %d %d", |
| 33 | target.x, target.y - 1, target.z, |
| 34 | size.x, size.y, size.z, |
| 35 | 1 |
| 36 | ) |
| 37 | |
| 38 | print(string.format("Targetting %d %d %d", target.x, target.y, target.z)) |
| 39 | modem.transmit(SERVER_PORT, PHONE_PORT, payloadMessage) |
| 40 |