Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Made by Sapphire
- --Please do not edit!
- version = "Alpha 7.2"
- local modem = false
- local code_404 = "term.setBackgroundColor(colors.white) term.clear() term.setCursorPos(1,1) term.setTextColor(colors.lightGray) print('Uh oh, captin, we are lost!') print('Sorry, the page was not found on the server!')"
- local sides = {
- "top",
- "bottom",
- "back",
- "left",
- "right"
- }
- local size = { term.getSize() }
- if not fs.exists("domain_name") then
- term.setBackgroundColor(colors.white)
- term.clear()
- paintutils.drawFilledBox(1,1,size[1],4,colors.gray)
- term.setCursorPos(1,1)
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.gray)
- print("Setup server domain name")
- term.setBackgroundColor(colors.white)
- term.setCursorPos(1,6)
- print("(adds .cc) Enter domain name: ")
- local dmn = read()
- local dmn = (dmn..".cc")
- local domainf = fs.open("domain_name","w")
- domainf.write(dmn)
- domainf.close()
- term.clear()
- paintutils.drawFilledBox(1,1,size[1],4,colors.gray)
- term.setCursorPos(1,1)
- print("Setup server owner")
- term.setCursorPos(1,6)
- term.setBackgroundColor(colors.white)
- write("Enter server owner: ")
- local owner = read()
- local own = fs.open("server_owner","w")
- own.write(owner)
- end
- if not fs.exists("index") then
- term.setBackgroundColor(colors.white)
- term.clear()
- paintutils.drawFilledBox(1,1,size[1],4,colors.gray)
- term.setCursorPos(1,1)
- term.setTextColor(colors.lightGray)
- print("Uh oh,")
- term.setBackgroundColor(colors.white)
- term.setCursorPos(1,5)
- print("The main file, index is missing! Please create it then restart the server!")
- term.setTextColor(colors.cyan)
- term.setCursorPos(1,8)
- print("Click anywhere to shutdown")
- os.pullEvent("mouse_click")
- os.shutdown()
- else
- for i = 1, #sides do
- if peripheral.isPresent(sides[i]) then
- if peripheral.getType(sides[i]) == "modem" then
- local modem = peripheral.find("modem")
- if modem.isWireless() then
- rednet.open(sides[i])
- local modem = true
- end
- end
- end
- end
- local domainf = fs.open("domain_name","r")
- local domain = domainf.readAll()
- domainf.close()
- if modem then
- local function reqLoop()
- while true do
- local evnt = { rednet.receive() }
- if evnt[3] == domain then
- if fs.exists(evnt[2]) then
- local codef = fs.open(evnt[2])
- local code = codef.readAll()
- codef.close()
- rednet.send(evnt[1],code)
- else
- rednet.send(evnt[1],code_404)
- end
- end
- end
- end
- local main_loop = coroutine.create(reqLoop)
- coroutine.resume(main_loop)
- local function sep(sSep)
- local sub = {}
- for i = 1,#sSep do
- local toAdd = string.sub(sSep,1,i)
- table.insert(sub,toAdd)
- end
- return sub
- end
- local function drawMainPage()
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setTextColor(colors.lightGray)
- paintutils.drawFilledBox(1,1,size[1],4,colors.gray)
- term.setCursorPos(1,1)
- print("System Version "..version)
- paintutils.drawFilledBox(1,6,21,9,colors.cyan)
- term.setCursorPos(3,7)
- term.setTextColor(colors.white)
- print("Edit Domain Name")
- paintutils.drawFilledBox(31,6,51,9,colors.yellow)
- term.setCursorPos(36,7)
- print("View Details")
- paintutils.drawFilledBox(1,11,21,14,colors.lime)
- term.setCursorPos(9,12)
- print("Quit")
- paintutils.drawFilledBox(31,11,51,14,colors.orange)
- term.setCursorPos(38,12)
- print("Restart")
- paintutils.drawFilledBox(1,16,size[1],19,colors.red)
- term.setCursorPos(22,17)
- print("Shutdown")
- end
- local function drawEditDmnPage()
- term.setBackgroundColor(colors.white)
- term.clear()
- paintutils.drawFilledBox(1,1,size[1],4,colors.gray)
- term.setCursorPos(1,1)
- term.setTextColor(colors.lightGray)
- print("Domain name editor")
- term.setCursorPos(1,6)
- term.setBackgroundColor(colors.white)
- write("Enter new domain name: ")
- local new_name = read()
- local dmn = fs.open("domain_name","w")
- local new_name =(new_name..".cc")
- dmn.write(new_name)
- dmn.close()
- drawMainPage()
- end
- local function drawDetailsPage()
- term.setBackgroundColor(colors.white)
- term.clear()
- paintutils.drawFilledBox(1,1,size[1],4,colors.gray)
- term.setCursorPos(1,1)
- term.setTextColor(colors.lightGray)
- local dmnf = fs.open("domain_name","r")
- local dmn = dmnf.readAll()
- dmnf.close()
- local ownf = fs.open("server_owner","r")
- local own = ownf.readAll()
- ownf.close()
- print("System details")
- term.setCursorPos(1,6)
- term.setBackgroundColor(colors.white)
- print("Domain name: "..dmn)
- term.setCursorPos(1,8)
- print("Owner: "..own)
- term.setCursorPos(1,10)
- print("ID: "..os.getComputerID())
- term.setTextColor(colors.cyan)
- term.setCursorPos(1,14)
- print("Press anywhere to exit")
- os.pullEvent("mouse_click")
- drawMainPage()
- end
- os.pullEvent = os.pullEventRaw
- drawMainPage()
- while true do
- local evnt,btn,xPos,yPos = os.pullEvent("mouse_click")
- if xPos >= 1 and xPos <= 21 and yPos >= 6 and yPos <= 9 then
- drawEditDmnPage()
- elseif xPos >= 31 and xPos <= 51 and yPos >= 6 and yPos <= 9 then
- drawDetailsPage()
- elseif xPos >= 1 and xPos <= 21 and yPos >= 11 and yPos <= 14 then
- coroutine.yield(main_loop)
- break
- elseif xPos >= 31 and xPos <= 51 and yPos >= 11 and yPos <= 14 then
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setTextColor(colors.cyan)
- term.setCursorPos(1,1)
- print("Restarting...")
- sleep(1)
- os.reboot()
- elseif xPos >= 1 and xPos <= size[1] and yPos >= 16 and yPos <= 19 then
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setTextColor(colors.cyan)
- term.setCursorPos(1,1)
- print("Shutting down...")
- sleep(1)
- os.shutdown()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement