Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- awsomiaOS --
- -- Developed by awsomia --
- os.pullEvent = os.pullEventRaw
- constant = {
- ver = "awsomiaOS 2.6.2",
- chatChannel = 1
- }
- x, y = term.getCursorPos()
- au = {
- clear = function()
- term.clear()
- term.setCursorPos(1, 1)
- end,
- setGui = function()
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.black)
- end,
- resetGui = function()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end,
- title = function(txt, clickToReturn)
- au.clear()
- au.setGui()
- local x, y = term.getSize()
- if clickToReturn then
- lengthLeft = x-#txt-17
- write(txt)
- for i = 1, lengthLeft do
- write(" ")
- end
- write("[Click to return]")
- else
- local lengthLeft = x-#txt
- write(txt)
- for i = 1, lengthLeft do
- write(" ")
- end
- end
- term.setCursorPos(1, 2)
- au.resetGui()
- print("")
- end,
- titleNoClear = function(txt, clickToReturn)
- term.setCursorPos(1, 1)
- au.setGui()
- local x, y = term.getSize()
- if clickToReturn then
- lengthLeft = x-#txt-17
- write(txt)
- for i = 1, lengthLeft do
- write(" ")
- end
- write("[Click to return]")
- else
- local lengthLeft = x-#txt
- write(txt)
- for i = 1, lengthLeft do
- write(" ")
- end
- end
- term.setCursorPos(1, 2)
- au.resetGui()
- print("")
- end,
- menu = function(top, clickToReturn, items)
- if clickToReturn then
- au.title(top, true)
- else
- au.title(top)
- end
- local xCur, yCur = term.getCursorPos()
- for i, j in pairs(items) do
- print("["..j.."]")
- end
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- return yPos
- end,
- loadData = function()
- h = fs.open("data", "r")
- sData = h.readAll()
- data = {}
- data = textutils.unserialize(sData)
- h.close()
- end,
- uploadData = function()
- if not data.admin then
- data.admin = {true}
- end
- sData = textutils.serialize(data)
- h = fs.open("data", "w")
- h.write(sData)
- h.close()
- end
- }
- function updateOS()
- fs.delete("startup")
- shell.run("pastebin", "get", "cFtU2K06", "startup")
- print("Update downloaded. Shutting down...")
- sleep(2)
- os.shutdown()
- end
- function newUserSetup()
- data = {user={}, pass={}, admin={}}
- au.title("New account setup", false)
- write ("Computer Label:")
- local l = read()
- os.setComputerLabel(l)
- write ("Username:")
- local u = read()
- table.insert(data.user, u)
- write ("Password:")
- local p = read("*")
- write ("Confirm Password:")
- local pC = read("*")
- if p == pC then
- table.insert(data.pass, p)
- else
- print("Passwords do not match!")
- sleep(2)
- newUserSetup()
- end
- table.insert(data.admin, true)
- au.uploadData()
- print("Signup Successful")
- sleep(2)
- os.reboot()
- end
- settings = {
- newPassword = function()
- au.title("New Password", true)
- print("Current Password: "..data.pass[ID])
- write("New Password: ")
- local f1 = function()
- local p = read("*")
- write("Confirm Password: ")
- local p2 = read("*")
- if p == p2 then
- table.remove(data.pass, ID)
- table.insert(data.pass, ID, p)
- au.uploadData()
- else
- print("Passwords do not match!")
- end
- end
- local f2 = function()
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- while not yPos == 1 do
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- end
- return true
- end
- parallel.waitForAny (f1, f2)
- settings.au.menu()
- end,
- newLabel = function()
- au.title("New Label", true)
- print("Current Label: "..os.getComputerLabel())
- write("New Label: ")
- local f1 = function()
- local l = read()
- os.setComputerLabel(l)
- end
- local f2 = function()
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- while not yPos == 1 do
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- end
- return true
- end
- parallel.waitForAny (f1, f2)
- settings.au.menu()
- end,
- menu = function()
- term.setCursorBlink(false)
- selection = au.menu("Settings Menu", true, {"Update awsomiaOS", "Change Computer Label", "Change Password"})
- if selection == 1 then
- mainMenu()
- elseif yPos == 3 then
- updateOS()
- elseif yPos == 4 then
- settings.newLabel()
- elseif yPos == 5 then
- settings.newPassword()
- else
- settings.menu()
- end
- end
- }
- function myArea()
- local dir = "aOS/"..IDName.."/"
- if not fs.exists(dir) then
- fs.makeDir(dir)
- end
- listForMenu = fs.list(dir)
- table.insert(listForMenu, "New File")
- selection = au.menu("My area", true, listForMenu)
- if selection == 1 then
- mainMenu()
- elseif selection > 2 and selection < #listForMenu+2 then
- local x, y = term.getSize()
- local start = math.floor((x + #listForMenu[selection])/2)+1
- term.setCursorPos(start, selection+2)
- write(" [Run] [Edit] [Delete]")
- local event, button, xPos, newYPos = os.pullEvent("mouse_click")
- if newYPos == 1 then
- mainMenu()
- elseif newYPos == yPos then
- if xPos > start+1 and xPos < start+6 then
- shell.run(dir..listForMenu[yPos-2])
- print("Press any key to continue")
- os.pullEvent("key")
- myArea()
- elseif xPos > start+6 and xPos < start+12 then
- shell.run("edit", dir..listForMenu[yPos-2])
- myArea()
- elseif xPos > start+12 and xPos < start+20 then
- fs.delete(dir..listForMenu[yPos-2])
- myArea()
- else
- myArea()
- end
- else
- myArea()
- end
- elseif yPos == #listForMenu then
- write("Filename: ")
- fileName = read()
- shell.run("edit", dir..fileName)
- mainMenu()
- else
- myArea()
- end
- end
- function runProgram()
- term.setCursorBlink(true)
- au.title("Programs", true)
- write(">")
- local textInput = function()
- sleep(0.1)
- programInput = read()
- end
- local checkForClick = function()
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- while not yPos == 1 do
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- end
- return true
- end
- local no = parallel.waitForAny (textInput, checkForClick)
- term.setCursorBlink(false)
- if no == 1 then
- shell.run(programInput)
- print("Press any key to continue")
- os.pullEvent("key")
- runProgram()
- elseif no == 2 then
- mainMenu()
- end
- end
- function chat()
- term.setCursorBlink(false)
- for a,b in pairs(rs.getSides()) do
- if peripheral.getType(b) == "modem" then
- modem = peripheral.wrap(b)
- end
- end
- if not modem then
- print("Modem not detected")
- sleep(2)
- mainMenu()
- end
- modem.open(constant.chatChannel)
- au.title("Chat", true)
- modem.transmit(constant.chatChannel, constant.chatChannel, IDName.." has entered chat")
- local checkForClick = function()
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- while not yPos == 1 do
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- end
- return true
- end
- local readMessage = function()
- while true do
- term.setCursorBlink(false)
- local x, y = term.getSize()
- term.setCursorPos(1, y)
- write(">")
- local message = read()
- term.setCursorPos(1, y-1)
- term.clearLine()
- modem.transmit(constant.chatChannel, constant.chatChannel, "["..IDName.."] : "..message)
- au.titleNoClear("Chat", true)
- term.setCursorBlink(false)
- end
- end
- local checkForMessages = function()
- messages = {}
- term.setCursorBlink(false)
- while true do
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- table.insert(messages, 1, message)
- local x, y = term.getSize()
- au.title("Chat", true)
- for i = 1, y - 4 do
- print(messages[(y-4)-i])
- end
- term.setCursorBlink(false)
- end
- end
- parallel.waitForAny(checkForClick, readMessage, checkForMessages)
- term.setCursorBlink(true)
- modem.transmit(constant.chatChannel, constant.chatChannel, IDName.." has entered chat")
- modem.closeAll()
- mainMenu()
- end
- function mainMenu()
- term.setCursorBlink(false)
- local f1 = function()
- yPos = au.menu(constant.ver.." - "..IDName, false, {"Run Program","My area", "Chat", "Settings", "Reboot", "Shutdown"})
- end
- local f2 = function()
- while true do
- term.setCursorPos(40, 1)
- print(" "..textutils.formatTime(os.time(), true).." ")
- sleep(0.01)
- end
- end
- parallel.waitForAny(f1, f2)
- if yPos == 3 then
- runProgram()
- elseif yPos == 4 then
- myArea()
- elseif yPos == 5 then
- chat()
- elseif yPos == 6 then
- settings.menu()
- elseif yPos == 7 then
- os.reboot()
- elseif yPos == 8 then
- os.shutdown()
- else
- mainMenu()
- end
- end
- startup = {
- loadingScreen = function()
- term.setCursorBlink(false)
- au.clear()
- au.setGui()
- local x, y = term.getSize()
- for i = 1, y do
- term.setCursorPos(1, i)
- for i = 1, x do
- write(" ")
- end
- end
- xCur = math.floor((x-#constant.ver)/2)
- yCur = math.floor(y/2)
- term.setCursorPos(xCur, yCur)
- print(constant.ver)
- local xPos, yPos = term.getCursorPos()
- xCur = math.floor((x-19)/2)
- term.setCursorPos(xCur, yPos+1)
- au.resetGui()
- textutils.slowWrite(" ", 10)
- sleep(1)
- au.clear()
- for i = 1, y do
- term.setCursorPos(1, i)
- for i = 1, x do
- write(" ")
- end
- end
- end,
- signup = function()
- local f1 = function()
- au.title("Sign Up", true)
- write ("Username:")
- local u = read()
- for i=1,#data.user do
- if u == data.user[i] then
- print("Username already exists!")
- sleep(2)
- end
- end
- table.insert(data.user, u)
- write ("Password:")
- local p = read("*")
- write ("Confirm Password:")
- local pC = read("*")
- if p == pC then
- table.insert(data.pass, p)
- else
- print("Passwords do not match!")
- sleep(2)
- signUp()
- end
- au.uploadData()
- print("Signup successful")
- end
- local f2 = function()
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- while not yPos == 1 do
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- end
- return true
- end
- if parallel.waitForAny(f1, f2) == 1 then
- ID = #data.user
- mainMenu()
- else
- startup.menu()
- end
- end,
- login = function()
- local f1 = function()
- while true do
- au.title("Log In", true)
- write ("Username:")
- local u = read()
- write ("Password:")
- local p = read("*")
- for i = 1, #data.user do
- if data.user[i] == u then
- userCorrect = true
- if data.pass[i] == p then
- passCorrect = true
- ID = i
- IDName = data.user[ID]
- end
- end
- end
- if userCorrect and passCorrect then
- return true
- elseif userCorrect then
- print("Password incorrect")
- sleep(2)
- else
- print("Username not found")
- sleep(2)
- end
- end
- end
- local f2 = function()
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- while not yPos == 1 do
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- end
- return true
- end
- local no = parallel.waitForAny(f1, f2)
- if no == 1 then
- mainMenu()
- else
- startup.menu()
- end
- end,
- menu = function()
- term.setCursorBlink(false)
- yPos = au.menu("Welcome to "..constant.ver, false, {"Login", "Sign Up", "Shut down"})
- if yPos == 3 then
- startup.login()
- elseif yPos == 4 then
- startup.signup()
- elseif yPos == 5 then
- os.shutdown()
- else
- startup.menu()
- end
- end,
- boot = function(debugMode)
- term.setCursorBlink(false)
- if fs.exists("data") then
- au.loadData()
- if data.user[1] == nil then
- newUserSetup()
- end
- else
- newUserSetup()
- end
- if debugMode then
- ID = 1
- au.loadData()
- mainMenu()
- end
- startup.loadingScreen()
- startup.menu()
- end
- }
- startup.boot(false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement