Advertisement
cyber_Ahn

Ficsit-Networks-Terminal

Apr 13th, 2022 (edited)
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.24 KB | None | 0 0
  1. ----------------------var------------------------------------------
  2. Server = "A95659614E3764D6CA3A53948E6E9FFE"
  3. Name = "Terminal_1"
  4. data_typ = {}
  5. data_name = {}
  6. data_amount = {}
  7. screen_id = "6E5FB6124199ADC8A83B54A17359CA2E"
  8. line_per_page = 28
  9. ---------------------get-hardware----------------------------------
  10. local page = 1
  11. local max_page = 1
  12. local NetworkCard = computer.getPCIDevices(findClass("NetworkCard"))[1]
  13. local panel = component.proxy(component.findComponent("Panel"))
  14.  
  15. local gpu = computer.getPCIDevices(findClass("GPUT1"))[1]
  16. if not gpu then
  17.  error("No GPU T1 found!")
  18. end
  19.  
  20. local screen = computer.getPCIDevices(findClass("FINComputerScreen"))[1]
  21. if not screen then
  22.  local comp_b=""
  23.  local comp = component.findComponent(findClass("Screen"))
  24.  for i=1, #comp do
  25.   if comp[i] == screen_id then
  26.    comp_b = comp[i]
  27.   end
  28.  end
  29.  screen = component.proxy(comp_b)
  30. end
  31. button_1 = panel[1]:getModule(0,0)
  32. gpu:bindScreen(screen)
  33. gpu:setSize(120,34)
  34. w,h = gpu:getSize()
  35. gpu:setSize(w,h)
  36. gpu:setText(0,0,"Start Terminal......")
  37. gpu:flush()
  38. event.pull(10)
  39. gpu:fill(0,0,w,h," ")
  40. gpu:flush()
  41. ----------------------function-------------------------------------
  42. function network_send(receiver, port_s, data)
  43.  netcard = component.proxy(NetworkCard.id)
  44.  netcard:open(port_s)
  45.  netcard:open(8081)
  46.  netcard:send(receiver, port_s, data)
  47. end
  48.  
  49. function split(s, delimiter)
  50.     result = {};
  51.     for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  52.         table.insert(result, match);
  53.     end
  54.     return result;
  55. end
  56.  
  57. function in_table(table, element)
  58.  for _, value in pairs(table) do
  59.   if value == element then
  60.    return true
  61.   end
  62.  end
  63.  return false
  64. end
  65.  
  66. function table_pos(table,stri)
  67.  local index={}
  68.  for k,v in pairs(table) do
  69.    index[v]=k
  70.  end
  71.  return index[stri]
  72. end
  73.  
  74. function draw_frame(x,y,le,dire)
  75.  for i=0, le do
  76.   if dire == "right" then
  77.    gpu:setText(x+i,y, "-")
  78.   end
  79.   if dire == "down" then
  80.    gpu:setText(x,y+i, "|")
  81.   end
  82.  end
  83. end
  84.  
  85. function screen_draw()
  86.  gpu:fill(0,0,w,h," ")
  87.  gpu:flush()
  88.  gpu:setText(40,0,Name.." Items: "..#data_name)
  89.  line = 1
  90.  screen_left = {}
  91.  screen_right ={}
  92.  screen_left_a = {}
  93.  screen_right_a ={}
  94.  line_a = 0
  95.  for i=1,#data_typ do
  96.   if string.find(data_typ[i],"Fluid") then
  97.    table.insert(screen_left,data_typ[i].." "..data_name[i])
  98.    table.insert(screen_left_a,data_amount[i])
  99.   end
  100.   if string.find(data_typ[i],"Container") then
  101.    table.insert(screen_right,data_typ[i].." "..data_name[i])
  102.    table.insert(screen_right_a,data_amount[i])
  103.   end
  104.  end
  105.  for i=1,#screen_left do
  106.   gpu:setText(1,line+i,screen_left[i])
  107.   gpu:setText(35,line+i,screen_left_a[i])
  108.  end
  109.  line_start = 1
  110.  line_end = line_per_page
  111.  max_page = math.floor(#screen_right / line_per_page)
  112.  if max_page < (#screen_right / line_per_page) then
  113.   max_page = max_page + 1
  114.  end
  115.  if page > 1 then
  116.   line_start = line_per_page * (page-1)
  117.   line_end = line_per_page * page
  118.  end
  119.  if line_end > #screen_right then
  120.   line_end = #screen_right
  121.  end
  122.  for i=line_start, line_end do
  123.   text_line = i+line
  124.   if page > 1 then
  125.    text_line = (i-line_per_page)+line
  126.   end
  127.   gpu:setText(60,text_line,screen_right[i])
  128.   gpu:setText(107,text_line,screen_right_a[i])
  129.   line_a = i
  130.  end
  131.  draw_frame(0,1,line_a,"down")
  132.  draw_frame(119,1,line_a,"down")
  133.  draw_frame(58,1,line_a,"down")
  134.  draw_frame(0,1,120,"right")
  135.  draw_frame(0,line_a+2,120,"right")
  136.  gpu:setText(80,0, "Page: "..page)
  137.  gpu:flush()
  138. end
  139. ---------------------register----------------------------------------
  140. network_send(Server, 5256, Name)
  141. ---------------------send_data---------------------------------------
  142. computer.beep(5)
  143. while true do
  144.  event.listen(netcard,button_1)
  145.  typ, to, ip, port, data = event.pull(10)
  146.  if to == button_1 then
  147.   page = page + 1
  148.   if page > max_page then
  149.    page = 1
  150.   end
  151.  end
  152.  network_send(Server, 5256, Name)
  153.  if(port == 8081) then
  154.   cach = split(data,"|")
  155.   if in_table(data_name,cach[2]) == false then
  156.    table.insert(data_typ,cach[1])
  157.    table.insert(data_name,cach[2])
  158.    table.insert(data_amount,cach[3])
  159.   else
  160.    t_pos = table_pos(data_name,cach[2])
  161.    if(data_amount[t_pos] ~= cach[3]) then
  162.     --update amount for a item
  163.     data_amount[t_pos]=cach[3]
  164.    end
  165.   end
  166.  end
  167.  screen_draw()
  168. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement