Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Basic website client by PaymentOption --
- VERSION = "ALPHA 0.0.1"
- -------------------------------------------
- rednet.open("top")
- rednet.open("bottom")
- rednet.open("right")
- rednet.open("left")
- rednet.open("back")
- rednet.open("bottom")
- -- VARS --
- selection = 1
- ----------
- shell.run("mkdir", "NeXuS/Website/")
- -- Helper Functions --
- function cPrint(height, string)
- local w, h = term.getSize()
- local xPosition = w/2 - string.len(string)/2
- term.setCursorPos(xPosition, height)
- term.write(string)
- end
- function rPrint(height, string)
- local w,h = term.getSize()
- local xPos = w - string.len(string)
- term.setCursorPos(xPos, height)
- term.write(string)
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- ----------------------
- -- Networking related functions --
- function connect()
- clear()
- if fs.exists("NeXuS/Website/history") == false then
- term.setCursorPos(1,1)
- write("Previous connections: ")
- local file = fs.open("NeXuS/Website/history", "w")
- file.close()
- else
- file = fs.open("NeXuS/Website/history", "r")
- local fileContents = file.readAll()
- file.close()
- term.setCursorPos(1,1)
- write("Previous connections: ")
- term.setCursorPos(1,2)
- write(fileContents)
- end
- cPrint(6, "Website Address: ")
- local server = read()
- clear()
- file = fs.open("NeXuS/Website/history", "r")
- fileContents = file.readAll()
- file.close()
- if not string.find(tostring(fileContents), server) then
- file = fs.open("NeXuS/Website/history", "w")
- file.write(tostring(server).."\n"..tostring(fileContents))
- file.close()
- end
- rednet.send(tonumber(server), "connect")
- sender, message = rednet.receive(1) -- Waiting for server code to be sent for execution
- shell.run("mkdir", "NeXuS/Website/"..server.."/")
- file = fs.open("NeXuS/Website/"..server.."/code", "w")
- file.write(tostring(message))
- file.close()
- shell.run("NeXuS/Website/"..server.."/code", server)
- end
- function disconnect(server)
- rednet.send(server, "disconnect")
- fs.delete("NeXuS/Website/"..server)
- end
- ----------------------------------
- -- Menues and other screens --
- function printMenu()
- if selection == 1 then cPrint(6, "[Connect]")
- else cPrint(6, " Connect ") end
- if selection == 2 then cPrint(7, " [Exit] ")
- else cPrint(7, " Exit ") end
- end
- function printHeader()
- term.setCursorPos(1,1)
- write("Welcome User")
- rPrint(16, "Version: "..VERSION)
- cPrint(1, "NeXuS WebBrowser")
- end
- ------------------------------
- clear()
- print("\n\n\n\n")
- print(" _ _ __ __ _____ _ ")
- print("| \\ | | \\ \\ / / | ___| | ")
- print("| \\| | ___ \\ V /__ __| |__ | |__ ")
- print("| . ` |/ _ \\/ \\\\ \\ /\\ / /| __|| '_ \\ ")
- print("| |\\ | __/ /^\\ \\\\ V V / | |___| |_) |")
- print("\\_| \\_/\\___\\/ \\/ \\_/\\_/ \\____/|_.__/ ")
- sleep(2)
- while true do
- clear()
- printHeader()
- printMenu()
- event, key = os.pullEvent("key")
- if key == 200 and selection > 1 then selection = selection-1
- elseif key == 208 and selection < 2 then selection = selection+1
- end
- if key == 28 and selection == 1 then connect() -- Will find a better name for this function later...
- elseif key == 28 and selection == 2 then clear(); os.reboot()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement