Advertisement
Lanzr

iotaLibServer

Jul 3rd, 2024 (edited)
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1.  
  2. local g_modem = peripheral.find("modem")
  3. local impetus = peripheral.wrap("bottom")
  4. local g_modem_ID = peripheral.getName(g_modem)
  5.  
  6. local ID = os.getComputerID()
  7. local g_Protocal = "iotaServer_"..ID
  8. local g_hostName = "iotaServer "..ID
  9. -- iotaServer_0
  10. local g_iota_list = {}
  11.  
  12. local function init()
  13.     rednet.open(g_modem_ID)
  14.     print("my Proc is:\n  ",g_Protocal)
  15.     rednet.host(g_Protocal,g_hostName)
  16. end
  17.  
  18. local function checkIotaList()
  19.     g_iota_list = fs.list("iota")
  20. end
  21.  
  22. local function compileLoop(filename)
  23.     shell.run("hex ".."iota/"..filename)
  24.     sleep(1)
  25.     impetus.activateCircle()
  26.     sleep(1)
  27. end
  28.  
  29. local function net_listener()
  30.     init()
  31.     while true do
  32.         local msgBoxPack = {["cmd"] ="",["msg"] = {}}
  33.         local event, sender, iMsgBox, protocol = os.pullEvent("rednet_message")
  34.         if(protocol == g_Protocal) then
  35.             local cmd = iMsgBox["cmd"]
  36.             local msg = iMsgBox["msg"]
  37.             if(cmd == "get_list")then
  38.                 checkIotaList()
  39.                 msgBoxPack["cmd"] = "ret_list"
  40.                 msgBoxPack["msg"] = g_iota_list
  41.                 rednet.send(sender, msgBoxPack,protocol)
  42.                 sleep(1)
  43.             end
  44.             if(iMsgBox["cmd"] == "compile")then
  45.                 compileLoop(msg)
  46.             end
  47.         end
  48.     end
  49. end
  50.  
  51. local function mainloop()
  52.     net_listener()
  53. end
  54.  
  55. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement