Advertisement
Volaik

Untitled

Nov 13th, 2021 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. CLIENT_PORT = {}
  2. io.write("Set a server port: ")
  3. SERVER_PORT = tonumber(io.read())
  4. print("Server port has been set to: "..SERVER_PORT)
  5.  
  6. local modem = peripheral.find("modem")
  7. modem.open(SERVER_PORT)
  8.  
  9. function pingLoc()
  10.     io.write("Select a computer to ping: ")
  11.     local num1 = tonumber(io.read())
  12.     modem.transmit(num1, SERVER_PORT, "pingLoc")
  13.     event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  14.     print(message)
  15. end
  16.  
  17. function clear()
  18.     for i = 1,25 do
  19.         print(" ")
  20.     end
  21. end
  22.  
  23. function list()
  24.     for data in ipairs(CLIENT_PORT) do
  25.         print(" ")
  26.         for value in pairs(data) do
  27.             print(value)
  28.         end
  29.     end
  30. end
  31.  
  32. function help()
  33.     for i = 1,25 do
  34.         print(" ")
  35.     end
  36.     print("loc   --Displays the coordinates of requested turtle")
  37.     print("clear --Clears the display")
  38.     print("list  --Lists connected computers")
  39.     print("help  --Brings up this list")
  40. end
  41.  
  42. function newConnection()
  43.     event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  44.     if message == "connectMessage" then
  45.         table.insert(CLIENT_PORT, replyChannel, replyChannel)
  46.         print("New connection from "..replyChannel)
  47.         modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
  48.     end
  49. end
  50.  
  51. function userInput()
  52.     command = io.read()
  53. end
  54.  
  55. while true do
  56.  
  57.     parallel.waitForAny(newConnection, userInput)
  58.  
  59.     if command == "loc" then
  60.         pingLoc()
  61.     end
  62.     if command == "list" then
  63.         list()
  64.     end
  65.     if command == "help" then
  66.         help()
  67.     end
  68.     if command == "clear" then
  69.         clear()
  70.     end
  71.    
  72. end
  73.  
  74. --event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  75. --if message == "connectMessage" then
  76. --print("Connection detected from "..replyChannel)
  77. --modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
  78. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement