Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("listUILib")
- local g_host
- local g_server_protocal
- local g_entry_list = {}
- local g_retry_times = 4
- -- init for connect Server
- local function init()
- local ret = false
- print("pls appoint proc")
- rednet.open("back")
- g_server_protocal = io.read()
- while g_retry_times do
- g_host = rednet.lookup(g_server_protocal)
- if (g_host ~= nil) then
- local msgBoxPack = {["cmd"] ="get_list",["msg"] = {}}
- ret = true
- print("target found")
- rednet.send(g_host, msgBoxPack,g_server_protocal)
- break
- end
- g_retry_times = g_retry_times - 1
- end
- return ret
- end
- local function key_listener()
- os.pullEvent("init_done")
- local w,h = term.getSize()
- page.init(g_entry_list,w,h)
- while true do
- local msgBoxPack = {["cmd"] ="compile",["msg"] = {}}
- local event, key, isHeld = os.pullEvent("key")
- local kvalue = keys.getName(key)
- if kvalue == "enter" then
- local index = page.getSelect()
- msgBoxPack["msg"] = g_entry_list[index]
- rednet.send(g_host, msgBoxPack, g_server_protocal)
- else
- page.control(kvalue)
- end
- end
- end
- -- netCheck to receive Server Message
- local function net_listener()
- while 1 do
- local event, sender, message, protocol = os.pullEvent("rednet_message")
- if(protocol == g_server_protocal) then
- print("-----------------")
- if message["cmd"] =="ret_list" then
- print("receive")
- g_entry_list = message["msg"]
- sleep(2)
- os.queueEvent("init_done")
- end
- end
- end
- end
- function mainloop()
- local ret = init()
- if ret then
- parallel.waitForAny(net_listener,key_listener)
- else
- print("target not found")
- end
- end
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement