Advertisement
awsomia

awsomiaOS 2.6.2

May 4th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.42 KB | None | 0 0
  1. -- awsomiaOS --
  2. -- Developed by awsomia --
  3.  
  4. os.pullEvent = os.pullEventRaw
  5.  
  6. constant = {
  7.     ver = "awsomiaOS 2.6.2",
  8.     chatChannel = 1
  9. }
  10.  
  11. x, y = term.getCursorPos()
  12.  
  13. au = {
  14. clear = function()
  15.     term.clear()
  16.     term.setCursorPos(1, 1)
  17. end,
  18.  
  19. setGui = function()
  20.     term.setBackgroundColor(colors.yellow)
  21.     term.setTextColor(colors.black)
  22. end,
  23.  
  24. resetGui = function()
  25.     term.setBackgroundColor(colors.black)
  26.     term.setTextColor(colors.white)
  27. end,
  28.  
  29. title = function(txt, clickToReturn)
  30.     au.clear()
  31.     au.setGui()
  32.     local x, y = term.getSize()
  33.     if clickToReturn then
  34.         lengthLeft = x-#txt-17
  35.         write(txt)
  36.         for i = 1, lengthLeft do
  37.             write(" ")
  38.         end
  39.         write("[Click to return]")
  40.     else
  41.         local lengthLeft = x-#txt
  42.         write(txt)
  43.         for i = 1, lengthLeft do
  44.             write(" ")
  45.         end
  46.     end
  47.     term.setCursorPos(1, 2)
  48.     au.resetGui()
  49.     print("")
  50. end,
  51.  
  52. titleNoClear = function(txt, clickToReturn)
  53.     term.setCursorPos(1, 1)
  54.     au.setGui()
  55.     local x, y = term.getSize()
  56.     if clickToReturn then
  57.         lengthLeft = x-#txt-17
  58.         write(txt)
  59.         for i = 1, lengthLeft do
  60.             write(" ")
  61.         end
  62.         write("[Click to return]")
  63.     else
  64.         local lengthLeft = x-#txt
  65.         write(txt)
  66.         for i = 1, lengthLeft do
  67.             write(" ")
  68.         end
  69.     end
  70.     term.setCursorPos(1, 2)
  71.     au.resetGui()
  72.     print("")
  73. end,
  74.  
  75. menu = function(top, clickToReturn, items)
  76.     if clickToReturn then
  77.         au.title(top, true)
  78.     else
  79.         au.title(top)
  80.     end
  81.     local xCur, yCur = term.getCursorPos()
  82.     for i, j in pairs(items) do
  83.         print("["..j.."]")
  84.     end
  85.     local event, button, xPos, yPos = os.pullEvent("mouse_click")
  86.     return yPos
  87. end,
  88.  
  89. loadData = function()
  90.     h = fs.open("data", "r")
  91.     sData = h.readAll()
  92.     data = {}
  93.     data = textutils.unserialize(sData)
  94.     h.close()
  95. end,
  96.  
  97. uploadData = function()
  98.     if not data.admin then
  99.         data.admin = {true}
  100.     end
  101.     sData = textutils.serialize(data)
  102.     h = fs.open("data", "w")
  103.     h.write(sData)
  104.     h.close()
  105. end
  106.  
  107. }
  108.  
  109. function updateOS()
  110.     fs.delete("startup")
  111.     shell.run("pastebin", "get", "cFtU2K06", "startup")
  112.     print("Update downloaded. Shutting down...")
  113.     sleep(2)
  114.     os.shutdown()
  115. end
  116.  
  117. function newUserSetup()
  118.     data = {user={}, pass={}, admin={}}
  119.     au.title("New account setup", false)
  120.     write ("Computer Label:")
  121.     local l = read()
  122.     os.setComputerLabel(l)
  123.     write ("Username:")
  124.     local u = read()
  125.     table.insert(data.user, u)
  126.     write ("Password:")
  127.     local p = read("*")
  128.     write ("Confirm Password:")
  129.     local pC = read("*")
  130.     if p == pC then
  131.         table.insert(data.pass, p)
  132.     else
  133.         print("Passwords do not match!")
  134.         sleep(2)
  135.         newUserSetup()
  136.     end
  137.     table.insert(data.admin, true)
  138.     au.uploadData()
  139.     print("Signup Successful")
  140.     sleep(2)
  141.     os.reboot()
  142. end
  143.  
  144. settings = {
  145.     newPassword = function()
  146.         au.title("New Password", true)
  147.         print("Current Password: "..data.pass[ID])
  148.         write("New Password: ")
  149.         local f1 = function()
  150.             local p = read("*")
  151.             write("Confirm Password: ")
  152.             local p2 = read("*")
  153.             if p == p2 then
  154.                 table.remove(data.pass, ID)
  155.                 table.insert(data.pass, ID, p)
  156.                 au.uploadData()
  157.             else
  158.                 print("Passwords do not match!")
  159.             end
  160.         end
  161.         local f2 = function()
  162.             local event, button, xPos, yPos = os.pullEvent("mouse_click")
  163.             while not yPos == 1 do
  164.                 local event, button, xPos, yPos = os.pullEvent("mouse_click")
  165.             end
  166.             return true
  167.         end
  168.         parallel.waitForAny (f1, f2)
  169.         settings.au.menu()
  170.     end,
  171.     newLabel = function()
  172.         au.title("New Label", true)
  173.         print("Current Label: "..os.getComputerLabel())
  174.         write("New Label: ")
  175.         local f1 = function()
  176.             local l = read()
  177.             os.setComputerLabel(l)
  178.         end
  179.         local f2 = function()
  180.             local event, button, xPos, yPos = os.pullEvent("mouse_click")
  181.             while not yPos == 1 do
  182.                 local event, button, xPos, yPos = os.pullEvent("mouse_click")
  183.             end
  184.             return true
  185.         end
  186.         parallel.waitForAny (f1, f2)
  187.         settings.au.menu()
  188.     end,
  189.     menu = function()
  190.         term.setCursorBlink(false)
  191.         selection = au.menu("Settings Menu", true, {"Update awsomiaOS", "Change Computer Label", "Change Password"})
  192.         if selection == 1 then
  193.             mainMenu()
  194.         elseif yPos == 3 then
  195.             updateOS()
  196.         elseif yPos == 4 then
  197.             settings.newLabel()
  198.         elseif yPos == 5 then
  199.             settings.newPassword()
  200.         else
  201.             settings.menu()
  202.         end
  203.     end
  204. }
  205.  
  206. function myArea()
  207.     local dir = "aOS/"..IDName.."/"
  208.     if not fs.exists(dir) then
  209.         fs.makeDir(dir)
  210.     end
  211.     listForMenu = fs.list(dir)
  212.     table.insert(listForMenu, "New File")
  213.     selection = au.menu("My area", true, listForMenu)
  214.     if selection == 1 then
  215.         mainMenu()
  216.     elseif selection > 2 and selection < #listForMenu+2 then
  217.         local x, y = term.getSize()
  218.         local start =  math.floor((x + #listForMenu[selection])/2)+1
  219.         term.setCursorPos(start, selection+2)
  220.         write(" [Run] [Edit] [Delete]")
  221.         local event, button, xPos, newYPos = os.pullEvent("mouse_click")
  222.         if newYPos == 1 then
  223.             mainMenu()
  224.         elseif newYPos == yPos then
  225.             if xPos > start+1 and xPos < start+6 then
  226.                 shell.run(dir..listForMenu[yPos-2])
  227.                 print("Press any key to continue")
  228.                 os.pullEvent("key")
  229.                 myArea()
  230.             elseif xPos > start+6 and xPos < start+12 then
  231.                 shell.run("edit", dir..listForMenu[yPos-2])
  232.                 myArea()
  233.             elseif xPos > start+12 and xPos < start+20 then
  234.                 fs.delete(dir..listForMenu[yPos-2])
  235.                 myArea()
  236.             else
  237.                 myArea()
  238.             end
  239.         else
  240.             myArea()
  241.         end
  242.     elseif yPos == #listForMenu then
  243.         write("Filename: ")
  244.         fileName = read()
  245.         shell.run("edit", dir..fileName)
  246.         mainMenu()
  247.     else
  248.         myArea()
  249.     end
  250. end
  251.  
  252. function runProgram()
  253.     term.setCursorBlink(true)
  254.     au.title("Programs", true)
  255.     write(">")
  256.     local textInput = function()
  257.         sleep(0.1)
  258.         programInput = read()
  259.     end
  260.     local checkForClick = function()
  261.         local event, button, xPos, yPos = os.pullEvent("mouse_click")
  262.         while not yPos == 1 do
  263.             local event, button, xPos, yPos = os.pullEvent("mouse_click")
  264.         end
  265.         return true
  266.     end
  267.     local no = parallel.waitForAny (textInput, checkForClick)
  268.     term.setCursorBlink(false)
  269.     if no == 1 then
  270.         shell.run(programInput)
  271.         print("Press any key to continue")
  272.         os.pullEvent("key")
  273.         runProgram()
  274.     elseif no == 2 then
  275.         mainMenu()
  276.     end
  277. end
  278.  
  279. function chat()
  280.     term.setCursorBlink(false)
  281.     for a,b in pairs(rs.getSides()) do
  282.         if peripheral.getType(b) == "modem" then
  283.             modem = peripheral.wrap(b)
  284.         end
  285.     end
  286.     if not modem then
  287.         print("Modem not detected")
  288.         sleep(2)
  289.         mainMenu()
  290.     end
  291.     modem.open(constant.chatChannel)
  292.     au.title("Chat", true)
  293.     modem.transmit(constant.chatChannel, constant.chatChannel, IDName.." has entered chat")
  294.     local checkForClick = function()
  295.         local event, button, xPos, yPos = os.pullEvent("mouse_click")
  296.         while not yPos == 1 do
  297.             local event, button, xPos, yPos = os.pullEvent("mouse_click")
  298.         end
  299.         return true
  300.     end
  301.     local readMessage = function()
  302.         while true do
  303.             term.setCursorBlink(false)
  304.             local x, y = term.getSize()
  305.             term.setCursorPos(1, y)
  306.             write(">")
  307.             local message = read()
  308.             term.setCursorPos(1, y-1)
  309.             term.clearLine()
  310.             modem.transmit(constant.chatChannel, constant.chatChannel, "["..IDName.."] : "..message)
  311.             au.titleNoClear("Chat", true)
  312.             term.setCursorBlink(false)
  313.         end
  314.     end
  315.     local checkForMessages = function()
  316.         messages = {}
  317.         term.setCursorBlink(false)
  318.         while true do
  319.             local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  320.             table.insert(messages, 1, message)
  321.             local x, y = term.getSize()
  322.             au.title("Chat", true)
  323.             for i = 1, y - 4 do
  324.                 print(messages[(y-4)-i])
  325.             end
  326.             term.setCursorBlink(false)
  327.         end
  328.     end
  329.     parallel.waitForAny(checkForClick, readMessage, checkForMessages)
  330.     term.setCursorBlink(true)
  331.     modem.transmit(constant.chatChannel, constant.chatChannel, IDName.." has entered chat")
  332.     modem.closeAll()
  333.     mainMenu()
  334. end
  335.    
  336. function mainMenu()
  337.     term.setCursorBlink(false)
  338.     local f1 = function()
  339.         yPos = au.menu(constant.ver.." - "..IDName, false, {"Run Program","My area", "Chat", "Settings", "Reboot", "Shutdown"})
  340.     end
  341.     local f2 = function()
  342.         while true do
  343.             term.setCursorPos(40, 1)
  344.             print(" "..textutils.formatTime(os.time(), true).." ")
  345.             sleep(0.01)
  346.         end
  347.     end
  348.     parallel.waitForAny(f1, f2)
  349.     if yPos == 3 then
  350.         runProgram()
  351.     elseif yPos == 4 then
  352.         myArea()
  353.     elseif yPos == 5 then
  354.         chat()
  355.     elseif yPos == 6 then
  356.         settings.menu()
  357.     elseif yPos == 7 then
  358.         os.reboot()
  359.     elseif yPos == 8 then
  360.         os.shutdown()
  361.     else
  362.         mainMenu()
  363.     end
  364. end
  365.  
  366. startup = {
  367.     loadingScreen = function()
  368.         term.setCursorBlink(false)
  369.         au.clear()
  370.         au.setGui()
  371.         local x, y = term.getSize()
  372.         for i = 1, y do
  373.             term.setCursorPos(1, i)
  374.             for i = 1, x do
  375.                 write(" ")
  376.             end
  377.         end
  378.         xCur = math.floor((x-#constant.ver)/2)
  379.         yCur = math.floor(y/2)
  380.         term.setCursorPos(xCur, yCur)
  381.         print(constant.ver)
  382.         local xPos, yPos = term.getCursorPos()
  383.         xCur = math.floor((x-19)/2)
  384.         term.setCursorPos(xCur, yPos+1)
  385.         au.resetGui()
  386.         textutils.slowWrite("                   ", 10)
  387.         sleep(1)
  388.         au.clear()
  389.         for i = 1, y do
  390.             term.setCursorPos(1, i)
  391.             for i = 1, x do
  392.                 write(" ")
  393.             end
  394.         end
  395.     end,
  396.    
  397.     signup = function()
  398.         local f1 = function()
  399.             au.title("Sign Up", true)
  400.             write ("Username:")
  401.             local u = read()
  402.             for i=1,#data.user do
  403.                 if u == data.user[i] then
  404.                     print("Username already exists!")
  405.                     sleep(2)
  406.                 end
  407.             end
  408.             table.insert(data.user, u)
  409.             write ("Password:")
  410.             local p = read("*")
  411.             write ("Confirm Password:")
  412.             local pC = read("*")
  413.             if p == pC then
  414.                 table.insert(data.pass, p)
  415.             else
  416.                 print("Passwords do not match!")
  417.                 sleep(2)
  418.                 signUp()
  419.             end
  420.             au.uploadData()
  421.             print("Signup successful")
  422.         end
  423.         local f2 = function()
  424.             local event, button, xPos, yPos = os.pullEvent("mouse_click")
  425.             while not yPos == 1 do
  426.                 local event, button, xPos, yPos = os.pullEvent("mouse_click")
  427.             end
  428.             return true
  429.         end
  430.         if parallel.waitForAny(f1, f2) == 1 then
  431.             ID = #data.user
  432.             mainMenu()
  433.         else
  434.             startup.menu()
  435.         end
  436.     end,
  437.    
  438.     login = function()
  439.         local f1 = function()
  440.             while true do
  441.                 au.title("Log In", true)
  442.                 write ("Username:")
  443.                 local u = read()
  444.                 write ("Password:")
  445.                 local p = read("*")
  446.                 for i = 1, #data.user do
  447.                     if data.user[i] == u then
  448.                         userCorrect = true
  449.                         if data.pass[i] == p then
  450.                             passCorrect = true
  451.                             ID = i
  452.                             IDName = data.user[ID]
  453.                         end
  454.                     end
  455.                 end
  456.                 if userCorrect and passCorrect then
  457.                     return true
  458.                 elseif userCorrect then
  459.                     print("Password incorrect")
  460.                     sleep(2)
  461.                 else
  462.                     print("Username not found")
  463.                     sleep(2)
  464.                 end
  465.             end
  466.             end
  467.         local f2 = function()
  468.             local event, button, xPos, yPos = os.pullEvent("mouse_click")
  469.             while not yPos == 1 do
  470.                 local event, button, xPos, yPos = os.pullEvent("mouse_click")
  471.             end
  472.             return true
  473.         end
  474.         local no = parallel.waitForAny(f1, f2)
  475.         if no == 1 then
  476.             mainMenu()
  477.         else
  478.             startup.menu()
  479.         end
  480.     end,
  481.    
  482.     menu = function()
  483.         term.setCursorBlink(false)
  484.         yPos = au.menu("Welcome to "..constant.ver, false, {"Login", "Sign Up", "Shut down"})
  485.         if yPos == 3 then
  486.             startup.login()
  487.         elseif yPos == 4 then
  488.             startup.signup()
  489.         elseif yPos == 5 then
  490.             os.shutdown()
  491.         else
  492.             startup.menu()
  493.         end
  494.     end,
  495.  
  496.     boot = function(debugMode)
  497.         term.setCursorBlink(false)
  498.         if fs.exists("data") then
  499.             au.loadData()
  500.             if data.user[1] == nil then
  501.                 newUserSetup()
  502.             end
  503.         else
  504.             newUserSetup()
  505.         end
  506.         if debugMode then
  507.             ID = 1
  508.             au.loadData()
  509.             mainMenu()
  510.         end
  511.     startup.loadingScreen()
  512.     startup.menu()
  513.     end
  514. }
  515.  
  516. startup.boot(false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement