Advertisement
Lanzr

iotaLibClient

Jul 3rd, 2024 (edited)
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. require("listUILib")
  2. local g_host
  3. local g_server_protocal
  4. local g_entry_list = {}
  5. local g_retry_times = 4
  6.  
  7. -- init for connect Server
  8. local function init()
  9.     local ret = false
  10.     print("pls appoint proc")
  11.     rednet.open("back")
  12.     g_server_protocal = io.read()
  13.     while g_retry_times do
  14.         g_host = rednet.lookup(g_server_protocal)
  15.         if (g_host ~= nil) then
  16.             local msgBoxPack = {["cmd"] ="get_list",["msg"] = {}}
  17.             ret = true
  18.             print("target found")
  19.             rednet.send(g_host, msgBoxPack,g_server_protocal)
  20.             break
  21.         end
  22.         g_retry_times = g_retry_times - 1
  23.     end
  24.     return ret
  25. end
  26.  
  27. local function key_listener()
  28.     os.pullEvent("init_done")
  29.     local w,h = term.getSize()
  30.     page.init(g_entry_list,w,h)
  31.     while true do
  32.         local msgBoxPack = {["cmd"] ="compile",["msg"] = {}}
  33.         local event, key, isHeld = os.pullEvent("key")
  34.         local kvalue = keys.getName(key)
  35.         if kvalue == "enter" then
  36.             local index = page.getSelect()
  37.             msgBoxPack["msg"] = g_entry_list[index]
  38.             rednet.send(g_host, msgBoxPack, g_server_protocal)
  39.         else
  40.             page.control(kvalue)
  41.         end
  42.     end
  43. end
  44.  
  45. -- netCheck to receive Server Message
  46. local function net_listener()
  47.     while 1 do
  48.         local event, sender, message, protocol = os.pullEvent("rednet_message")
  49.         if(protocol == g_server_protocal) then
  50.             print("-----------------")
  51.             if message["cmd"] =="ret_list" then
  52.                 print("receive")
  53.                 g_entry_list = message["msg"]
  54.                 sleep(2)
  55.                 os.queueEvent("init_done")
  56.             end
  57.  
  58.         end
  59.     end
  60. end
  61.  
  62. function mainloop()
  63.     local ret = init()
  64.     if ret then
  65.         parallel.waitForAny(net_listener,key_listener)
  66.     else
  67.         print("target not found")
  68.     end
  69. end
  70.  
  71. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement