Advertisement
fishermedders

Smithernet Explorer Browser/Installer

Jun 3rd, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None | 0 0
  1. size = {term.getSize()}
  2. function loadUI()
  3.   term.setBackgroundColor(colors.white)
  4.   term.clear()
  5.   term.setCursorPos(1,1)
  6.   term.setBackgroundColor(colors.lightGray)
  7.   function grayBar()
  8.     for i = 1,size[1]-1 do
  9.       term.write(" ")
  10.     end
  11.     print(" ")
  12.   end
  13.   for i = 1,3 do
  14.     grayBar()
  15.   end
  16.   title = "Smithernet Explorer 1.0"
  17.     term.setTextColor(colors.lightBlue)
  18.   term.setCursorPos((size[1]/2)-(#title/2),1)
  19.   term.write(title)
  20.   term.setCursorPos(2,2)
  21.   term.setBackgroundColor(colors.gray)
  22.   term.write(" Home ")
  23.   term.setBackgroundColor(colors.lightGray)
  24.   term.write(" ")
  25.   term.setBackgroundColor(colors.gray)
  26.   term.write("                                ")
  27.   term.setBackgroundColor(colors.lightGray)
  28.   term.write(" ")
  29.   term.setBackgroundColor(colors.gray)
  30.   term.write(" Refresh ")
  31.   term.setCursorPos(1,4)
  32. end
  33.  
  34. if term.isColor() then
  35.   term.setBackgroundColor(colors.lightBlue)
  36.   term.clear()
  37.   term.setCursorPos(1,1)
  38. else
  39.   term.clear()
  40.   term.setCursorPos(1,1)
  41. end
  42.  
  43. if not fs.exists("smithernetexplorer/cfg/config.cfg") then
  44.   fs.makeDir("smithernetexplorer/cfg/")
  45.   print("Thank you for purchasing your SMITHNET SERVER!")
  46.   print("You will now be guided through the installation")
  47.   size = {term.getSize()}
  48.   for i = 1,size[1]-1 do
  49.     term.write("-")
  50.   end
  51.   print("-")
  52.   term.write("What side is the modem on? :: ")
  53.   side = read()
  54.   term.write("What number is the house?")
  55.   housenumber = read()
  56.   print("Thank you for configuring the SMITHNET SERVER!")
  57.   file = fs.open("smithernetexplorer/cfg/config.cfg","w")
  58.   t = {}
  59.   t["side"] = side
  60.   t["housenumber"] = tonumber(housenumber)
  61.   file.write(textutils.serialize(t))
  62.   file.close()
  63. end
  64.  
  65.  
  66. --Main Program loop
  67. config = fs.open("smithernetexplorer/cfg/config.cfg","r")
  68. tbl = textutils.unserialize(config.readAll())
  69. config.close()
  70. p = peripheral.wrap(tbl["side"])
  71. p.open(tbl["housenumber"])
  72. loadUI()
  73. while true do
  74.   evnt = {os.pullEvent()}
  75.   if evnt[1] == "mouse_click" then
  76.     if evnt[4] == 2 then
  77.       if evnt[3] > 8 and evnt[3] < 41 then
  78.         term.setCursorPos(9,2)
  79.         input = read()
  80.         p.transmit(80,tbl["housenumber"],tbl["housenumber"]..":req:ws:"..input)
  81.         evnt1 = {os.pullEvent("modem_message")}
  82.         term.setCursorPos(1,4)
  83.         term.setBackgroundColor(colors.white)
  84.         for i = 1,size[2]-4 do
  85.           for i = 1,size[1]-1 do
  86.             term.write(" ")
  87.           end
  88.           print(" ")
  89.         end
  90.         term.setCursorPos(1,4)
  91.         args = {}
  92.         if string.match(evnt1[5],"\n") then
  93.           for word in string.gmatch(evnt1[5], '(.-)\\n') do
  94.             table.insert(args,word)
  95.           end
  96.         else
  97.           args[1] = evnt1[5]
  98.         end
  99.         for i = 1,#args do
  100.           print(args[i])
  101.         end
  102.       end
  103.     end
  104.   end
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement