Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- revolutOS alpha by Sylvyrfysh
- ]]
- --version vars
- local maj_build="alpha_1.0";
- local rev=5;
- local build=32;
- --putting the version together
- local version=maj_build.."."..rev.." (build num "..build..")";
- --file system info
- local dir=".revolutOS/";
- local apis=dir.."apis/";
- local userdat=dir.."users/";
- local sys=dir..".sys/";
- local apis=dir.."APIS/";
- local cfgFile=dir.."cfg";
- local logFile=dir.."log.txt";
- local pssFile="/.hpc";
- local uFile="/prefs";
- local public="rOS-public/";
- local pubScrSave=public.."screenshots/";
- --screen info
- local sX,sY=term.getSize();
- --temp login info
- local usnm="";
- local pss="";
- local desktop={};
- --user info
- local user;
- --prefs value lookup
- prefs={
- --colors
- ["tColor"]=(function()
- if term.isColor() then
- return colors.gray
- else
- return colors.white
- end
- end)(),
- ["bColor"]=(function()
- if term.isColor() then
- return colors.white
- else
- return colors.black
- end
- end)(),
- ["eColor"]=(function()
- if term.isColor() then
- return colors.red
- else
- return colors.white
- end
- end)(),
- ["oColor"]=(function()
- if term.isColor() then
- return colors.blue
- else
- return colors.white
- end
- end)(),
- }
- --Log
- logger={
- add=function(message,tag)
- file=fs.open(logFile,"a");
- if tag then
- file.write(tag..string.rep(" ",19-#tag).."> "..message.."\n");
- else
- file.write("tagless"..string.rep(" ",19-#"tagless").."> "..message.."\n");
- end
- file.close();
- end
- }
- --functions
- fc={
- boot=function()
- file=fs.open(logFile,"w");
- file.write("revolutOS LOG FILE- ver "..version.."\n");
- file.close();
- if term.isColor() then
- logger.add("Is color","boot:info");
- else
- logger.add("Not color","boot:info");
- end
- os.loadAPI(apis.."sha");
- os.loadAPI(apis.."json");
- os.loadAPI(apis.."graphics");
- t=textutils;
- tm=term;
- eLoginInfo="";
- pc=paintutils;
- fc.wrapPeripherals();
- end,
- loginScreen=function()
- logger.add("Begin login","booted:login");
- fc.p.paintFullScreen(bgCol);
- tm.setCursorPos(3,3);
- tm.setTextColor(colors.white);
- write("Username: ");
- pc.drawLine(13,3,sX-13,3,colors.white);
- tm.setCursorPos(3,5);
- tm.setBackgroundColor(bgCol);
- write("Password: ")
- pc.drawLine(13,5,sX-13,5,colors.white);
- tm.setCursorPos(13,3);
- tm.setTextColor(colors.black);
- write(usnm);
- tm.setCursorPos(13,5);
- for i=1,#pss do
- write("*");
- end
- term.setTextColor(colors.red);
- term.setCursorPos(13,9);
- if eLoginInfo then
- write(eLoginInfo);
- end
- enterpss=false;
- os.startTimer(0.5);
- blink=false;
- while true do
- local event={os.pullEvent()};
- if event[1]:upper()=="TIMER" then
- os.startTimer(1);
- blink=not blink;
- elseif enterpss then
- if event[1]=="char" then
- pss=pss..event[2];
- elseif event[1]=="key" then
- if event[2]==keys.enter then
- break;
- elseif event[2]==keys.backspace then
- pss=pss:sub(1,#pss-1);
- end
- end
- else
- if event[1]=="char" then
- usnm=usnm..event[2];
- elseif event[1]=="key" then
- if event[2]==keys.enter then
- enterpss=true;
- elseif event[2]==keys.backspace then
- usnm=usnm:sub(1,#usnm-1);
- end
- end
- end
- pc.drawLine(13,3,sX-13,3,colors.white);
- pc.drawLine(13,5,sX-13,5,colors.white);
- tm.setCursorPos(13,3);
- term.setTextColor(colors.black);
- write(usnm);
- tm.setCursorPos(13,5);
- for i=1,#pss do
- write("*");
- end
- if blink then
- if enterpss then
- pc.drawLine(13+#pss,5,13+#pss,5,colors.green);
- else
- pc.drawLine(13+#usnm,3,13+#usnm,3,colors.green);
- end
- end
- end
- logger.add("End login input","booted:logging_in");
- logger.add("Userfile exists? "..tostring(fs.exists(userdat..usnm)),"booted:logging_in");
- function g()
- if fs.exists(userdat..usnm) then
- logger.add(userdat..usnm..pssFile,"booted:login_info");
- w=fs.open(userdat..usnm..pssFile,"r");
- readPss=w.readLine();
- if sha.sha256(pss)==readPss then
- logger.add("Logged in as "..usnm,"booted:login_done");
- user=usnm;
- return true;
- else
- logger.add("Bad password","booted:login_info");
- eLoginInfo="Incorrect password.";
- return false;
- end
- else
- logger.add("Bad username","booted:login_info");
- eLoginInfo="Bad username.";
- return false;
- end
- end
- if not g() then
- pss="";
- fc.loginScreen();
- else
- pss="";
- fc.loadUserPreferences(user);
- fc.desktop();
- end
- end,
- wrapPeripherals=function()
- for k,v in pairs(rs.getSides()) do
- temp=peripheral.getType(v)
- if temp then
- logger.add("Found peripheral "..temp.." on side "..v,"boot:peripherals");
- if temp=="modem" and peripheral.call(v,"isWireless") then
- modem=peripheral.wrap(v);
- elseif temp=="modem" and not peripheral.call(v,"isWireless") then
- w_modem=peripheral.wrap(v);
- end
- end
- end
- end,
- loadUserPreferences=function(name)
- logger.add("Loading "..user.."'s preferences.","booted:logging_in");
- if fs.exists(userdat..user..uFile) then
- local uf=fs.open(userdat..user..uFile,"r");
- local data=json.decode(uf.readAll());
- uf.close();
- shell.run("clear");
- for t,y in pairs(data.tree) do
- fc.decodePref(y);
- end
- else
- logger.add("User has no custom prefs. loading default","booted:logging_in");
- end
- end,
- decodePref=function(obj)
- logger.add("Decoding "..obj.name,"booted:logging_in");
- name=obj.name;
- value=obj.value;
- if prefs[name] then
- logger.add(obj.name.." has entry","booted:logging_in");
- prefs[name]=value;
- end
- end,
- desktop=function()
- graphics.paintFullScreen(prefs["bColor"]);
- graphics.paintSizedBorder(1,1,sX,sY-5,prefs["oColor"]);
- pc.drawImage(pc.loadImage(sys.."SysInfoLogo"),1,sY-4);
- pc.drawImage(pc.loadImage(sys.."ShutdownOptions"),7,sY-4);
- term.setCursorPos(sX-(#user),2);
- write(user);
- fc.startEventHandler();
- end,
- eventHandler=function(event)
- logger.add("event handler called","eventhandler");
- end,
- startEventHandler=function()
- c=coroutine.create((function()
- while true do
- x={os.pullEvent()};
- fc.eventHandler(x);
- end
- end)());
- coroutine.resume(c);
- end,
- }
- if args then
- if not args[1]=="--asapi" then
- fc.boot();
- if #fs.list(".revolutOS/users/")==0 then
- fc.mkusr();
- else
- fc.loginScreen();
- end
- end
- else
- fc.boot();
- if #fs.list(".revolutOS/users/")==0 then
- fc.mkusr();
- else
- fc.loginScreen();
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement