Advertisement
Chocobot

CookieSystem v1.1

Jan 21st, 2012
1,146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.83 KB | None | 0 0
  1. function createfolders()
  2. fs.makeDir("/CookieSystem")
  3. fs.makeDir("/CookieSystem/CS System")
  4. fs.makeDir("/CookieSystem/DB")
  5. fs.makeDir("/CookieSystem/DB/DBlog")
  6. fs.makeDir("/CookieSystem/DB/DBlevels")
  7. fs.makeDir("/CookieSystem/DB/DBlevels/uselevel")
  8. fs.makeDir("/CookieSystem/DB/DBlevels/editlevel")
  9. end
  10.  
  11. function createadminaccount()
  12. file = io.open("CookieSystem/DB/DBlog/admin", "w")
  13. file:write("admin\n4")
  14. file:close()
  15. end
  16.  
  17. function createlevelfiles()
  18. file = io.open("CookieSystem/DB/DBlevels/editlevel/1", "w")
  19. file:close()
  20. file = io.open("CookieSystem/DB/DBlevels/editlevel/2", "w")
  21. file:close()
  22. file = io.open("CookieSystem/DB/DBlevels/editlevel/3", "w")
  23. file:close()
  24. file = io.open("CookieSystem/DB/DBlevels/uselevel/1", "w")
  25. file:write([[/CookieSystem/changepass
  26. /rom/programs/id
  27. /rom/programs/label
  28. /rom/programs/reboot
  29. /rom/programs/shutdown
  30. /rom/programs/worm
  31.  
  32. ]])
  33. file:close()
  34. file = io.open("CookieSystem/DB/DBlevels/uselevel/2", "w")
  35. file:write([[/CookieSystem/create
  36. ]])
  37. file:close()
  38. file = io.open("CookieSystem/DB/DBlevels/uselevel/3", "w")
  39. file:write([[/CookieSystem/delete
  40. /CookieSystem/setlvl
  41. ]])
  42. file:close()
  43. end
  44.  
  45. function createlogin()
  46. file = io.open("CookieSystem/login", "w")
  47. file:write([[term.clear()
  48. term.setCursorPos(10,5)
  49. write("==============================")
  50. term.setCursorPos(10,14)
  51. write("==============================")
  52. for n=6,13 do
  53. term.setCursorPos(10,n)
  54. write("|")
  55. term.setCursorPos(39,n)
  56. write("|")
  57. end
  58. term.setCursorPos(22,7)
  59. write("LOGIN")
  60. term.setCursorPos(15,9)
  61. write("Name:")
  62. term.setCursorPos(15,11)
  63. write("Pass:")
  64.  
  65. term.setCursorPos(21,9)
  66. curname = read()
  67. term.setCursorPos(21,11)
  68. pass = read("*")
  69.  
  70. corlogin = false
  71.  
  72. DB = io.open("/CookieSystem/DB/DBlog/" ..curname)
  73. if DB
  74. then
  75. corpass = DB:read()
  76. DB:close()
  77. if pass == corpass
  78. then
  79. corlogin = true
  80. end
  81. end
  82.  
  83. if corlogin == false
  84. then
  85. term.setCursorPos(18,13)
  86. write("Login denied")
  87. sleep(2)
  88. os.shutdown()
  89. end
  90. ]])
  91. file:close()
  92. end
  93.  
  94. function createcreate()
  95. file = io.open("/CookieSystem/create", "w")
  96. file:write([[term.clear()
  97. term.setCursorPos(18,3)
  98. print("Account Creation")
  99.  
  100. term.setCursorPos(10,8)
  101. write("Name: ")
  102. term.setCursorPos(10,10)
  103. write("Password: ")
  104. term.setCursorPos(20,8)
  105. local newname = read()
  106. term.setCursorPos(20,10)
  107. local newpass = read()
  108.  
  109. term.setCursorPos(5,12)
  110.  
  111. DB = io.open("/CookieSystem/DB/DBlog/"..newname, "r")
  112. if DB
  113. then
  114. DB:close()
  115. print("Username already exists")
  116. else
  117. DB = io.open("/CookieSystem/DB/DBlog/"..newname, "w")
  118. DB:write(newpass.."\n"..1)
  119. DB:close()
  120. print("New account created")
  121. end ]])
  122. file:close()
  123. end
  124.  
  125. function createdelete()
  126. file = io.open("/CookieSystem/delete", "w")
  127. file:write([[term.clear()
  128. term.setCursorPos(20,3)
  129. print("Account Deletion")
  130. term.setCursorPos(5,6)
  131. print("Which account do you want to delete?")
  132. term.setCursorPos(10,8)
  133. local delname = read()
  134. term.setCursorPos(5,10)
  135.  
  136. if delname ~= curname and delname ~= "admin" then
  137. db = io.open("/CookieSystem/DB/DBlog/"..delname,"r" )
  138. if db
  139. then
  140. db:close()
  141. shell.run("rm", "/CookieSystem/DB/DBlog/"..delname)
  142. print("Account deleted")
  143. else
  144. print("Account doesn't exist.")
  145. end
  146. end
  147.  
  148. sleep(1)]])
  149. file:close()
  150. end
  151.  
  152. function createsetlvl()
  153. file = io.open("/CookieSystem/setlvl", "w")
  154. file:write([[term.clear()
  155. term.setCursorPos(17,4)
  156. print("Set Clearance level")
  157. term.setCursorPos(5,6)
  158. print("Who's level do you want to change?")
  159. term.setCursorPos(10,8)
  160. local clname = read()
  161. term.setCursorPos(5,10)
  162. print("What do you want to set the level to?")
  163. term.setCursorPos(10,12)
  164. local newlevel = read()
  165. newlevel = tonumber(newlevel)
  166. term.setCursorPos(5,14)
  167. sleep(1)
  168. DB = io.open("/CookieSystem/DB/DBlog/"..clname, "r")
  169. if DB
  170. then
  171. local tarpass = DB:read()
  172. local tarlevel = DB:read()
  173. tarlevel = tonumber(tarlevel)
  174. DB:close()
  175. if curlevel > tarlevel
  176. then
  177. if curlevel > newlevel
  178. then
  179. DB = io.open("/CookieSystem/DB/DBlog/"..clname, "w")
  180. DB:write(tarpass.."\n"..newlevel)
  181. DB:close()
  182. print(clname.."'s level changed to "..newlevel)
  183. else
  184. print("The desired level must be lower than your own")
  185. end
  186. else
  187. print("Target's level is too high to be changed")
  188. end
  189. else
  190. print("Name not found")
  191. end
  192.  
  193. sleep(1) ]])
  194. file:close()
  195. end
  196.  
  197. function createchangepass()
  198.  
  199. file = io.open("/CookieSystem/changepass", "w")
  200. file:write([[term.clear()
  201. term.setCursorPos(18,3)
  202. print("Change Password")
  203. term.setCursorPos(5,5)
  204. print("Do you want to change your password?")
  205. term.setCursorPos(10,7)
  206. local answer = read()
  207. if answer == "yes"
  208. then
  209. term.setCursorPos(5,9)
  210. print("Give your current password")
  211. term.setCursorPos(10,11)
  212. local passtry = read()
  213. if passtry == curpass
  214. then
  215. term.setCursorPos(5,13)
  216. print("What do you want your new password to be?")
  217. term.setCursorPos(10,15)
  218. local newpass = read()
  219. DB = io.open("/CookieSystem/DB/DBlog/"..curname, "w")
  220. DB:write(newpass.."\n"..curlevel)
  221. DB:close()
  222. curpass = newpass
  223. term.setCursorPos(5,17)
  224. print("New password set")
  225. else
  226. term.setCursorPos(5,13)
  227. print("Password incorrect")
  228. end
  229. end
  230. sleep(1)
  231. ]])
  232. file:close()
  233. end
  234.  
  235. function createinterface()
  236.  
  237. file = io.open("/CookieSystem/CS System/interface", "w")
  238. file:write([[
  239. function ini()
  240. path = "/"
  241. curselx = 1
  242. cursely = 1
  243. preselx = 1
  244. presely = 1
  245. curselthing = ""
  246. cmdln = ""
  247. curtabloc = 1
  248. curpage = 1
  249. infoline = ""
  250. curselminuselvl = 4
  251. curselmineditlvl = 4
  252. maintenance = false
  253. comtabsel = 1
  254.  
  255. DBlog = io.open("/CookieSystem/DB/DBlog/"..curname, "r")
  256. curpass = DBlog:read()
  257. curlevel = DBlog:read()
  258. curlevel = tonumber(curlevel)
  259. DBlog:close()
  260. end
  261.  
  262. function getsizestuff()
  263. screenmaxx, screenmaxy = term.getSize()
  264. lowesty = screenmaxy
  265. topuisizey = 2
  266. bottomuisizey = 4
  267. useablespacey = (screenmaxy - (topuisizey + bottomuisizey))
  268. tilesizex = 10
  269. tilesizey = 3
  270. spacefortilesx = math.floor(screenmaxx/tilesizex)
  271. spacefortilesyrawr = (math.floor(useablespacey/tilesizey))
  272. maxamountsideprograms = math.floor((spacefortilesyrawr-1)/2)
  273. spacefortilesy = (spacefortilesyrawr - 2 * amountofsideprogramsrunning)
  274. tilesperpage = spacefortilesx * spacefortilesy
  275. end
  276.  
  277. function bordersui()
  278. for n=2, lowesty-3 do
  279. if n == 2
  280. then
  281. local printtopline = string.rep("=", math.floor((screenmaxx-12)/2))
  282. printtopline = (printtopline.."CookieSystem"..printtopline)
  283. if string.len(printtopline) >= screenmaxx
  284. then term.setCursorPos(1,1)
  285. else term.setCursorPos(1,2) end
  286. write(printtopline)
  287. elseif n == (lowesty-3)
  288. then
  289. term.setCursorPos(1,lowesty-3)
  290. write(string.rep("=", screenmaxx-1))
  291. else
  292. term.setCursorPos(1,n-1)
  293. write(string.rep("|", screenmaxx))
  294. end
  295. end
  296. for n=3, (lowesty-4) do
  297. for i=2,(screenmaxx-1) do
  298. term.setCursorPos(i,n)
  299. write(" ")
  300. end
  301. end
  302. end
  303.  
  304.  
  305. function topui()
  306. term.setCursorPos(1,1)
  307. term.clearLine()
  308. write(curname.." | "..curlevel)
  309. term.setCursorPos(screenmaxx-11,1)
  310. time = textutils.formatTime(os.time(), true)
  311. write("V1.1 "..time)
  312. end
  313.  
  314. function comtabdisplay()
  315. comtabname = {"Use", "Edit", "Copy", "Paste"}
  316. term.setCursorPos(1,lowesty-2)
  317. for k=1, 4 do
  318. if k == comtabsel
  319. then write("*"..k.."."..comtabname[k].."*")
  320. else write("|"..k.."."..comtabname[k].."|")
  321. end
  322. end
  323. end
  324.  
  325. function bottomui()
  326. term.setCursorPos(1,lowesty)
  327. term.clearLine()
  328. showpath = path
  329. maxpathlength = ((screenmaxx/2) - 7)
  330. if string.len(path) > maxpathlength
  331. then showpath = string.sub(path, -maxpathlength)
  332. end
  333. write("Path: "..showpath)
  334. term.setCursorPos(screenmaxx/2,lowesty)
  335. write(" Sel: "..curselthing)
  336. term.setCursorPos(1,lowesty-1)
  337. term.clearLine()
  338. write("Info: "..infoline)
  339. term.setCursorPos(1,lowesty-2)
  340. term.clearLine()
  341. if curtabloc == 1 then comtabdisplay() end
  342. end
  343.  
  344. function basescreen()
  345. term.clear()
  346. topui()
  347. bordersui()
  348. bottomui()
  349. end
  350.  
  351. function getlist(path)
  352. fullist = {}
  353. fulllist = fs.list(path)
  354. folderlist = {}
  355. programlist = {}
  356. local nl = 0
  357. local il = 0
  358. local jl = 0
  359. while true do
  360. nl = nl + 1
  361. if fulllist[nl] == nil then break end
  362. if fs.isDir(path..fulllist[nl])
  363. then
  364. il = il + 1
  365. folderlist[il] = fulllist[nl]
  366. else
  367. jl = jl + 1
  368. programlist[jl] = fulllist[nl]
  369. end
  370. end
  371. end
  372.  
  373. function getdisplayname(thingy)
  374. displayname = thingy
  375. displaylength = string.len(displayname)
  376. if displaylength < 8
  377. then firsteightchar = string.sub(displayname,1,displaylength)
  378. else firsteightchar = string.sub(displayname,1,8)
  379. end
  380.  
  381. if displaylength > 8
  382. then secondeightchar = string.sub(displayname, 9, 16)
  383. else secondeightchar = ""
  384. end
  385. if fs.isDir(path..thingy) then
  386. displaylineone = "=folder="
  387. else
  388. if string.sub(displayname,-4) == ".txt"
  389. then displaylineone = "==text=="
  390. else displaylineone = "=progrm="
  391. end
  392. end
  393. displaylinetwo = firsteightchar
  394. displaylinethree = secondeightchar
  395. end
  396.  
  397. function getcoordspot(n)
  398. x = n%spacefortilesx
  399. if x == 0 then x = spacefortilesx end
  400. y = n/spacefortilesx - x/spacefortilesx +1
  401.  
  402. prx = (1 + ((x-1)*10))
  403. pry = (y*3)
  404. end
  405.  
  406. function printtileborders(prx,pry)
  407. term.setCursorPos(prx,pry)
  408. write("|")
  409. term.setCursorPos(prx,pry+1)
  410. write("|")
  411. term.setCursorPos(prx,pry+2)
  412. write("|")
  413. term.setCursorPos(prx+9,pry)
  414. write("|")
  415. term.setCursorPos(prx+9,pry+1)
  416. write("|")
  417. term.setCursorPos(prx+9,pry+2)
  418. write("|")
  419. end
  420.  
  421. function printtilebordersselected(prx,pry)
  422. term.setCursorPos(prx,pry)
  423. write("*")
  424. term.setCursorPos(prx,pry+1)
  425. write("*")
  426. term.setCursorPos(prx,pry+2)
  427. write("*")
  428. term.setCursorPos(prx+9,pry)
  429. write("*")
  430. term.setCursorPos(prx+9,pry+1)
  431. write("*")
  432. term.setCursorPos(prx+9,pry+2)
  433. write("*")
  434. end
  435.  
  436. function printtile(prx,pry)
  437. term.setCursorPos(prx+1, pry)
  438. write(displaylineone)
  439. term.setCursorPos(prx+1, pry+1)
  440. write(displaylinetwo)
  441. if displaylinethree ~= nil
  442. then
  443. term.setCursorPos(prx+1, pry+2)
  444. write(displaylinethree)
  445. end
  446. end
  447.  
  448. function showstuff()
  449. getlist(path)
  450. maxpage = (math.floor(#fulllist/tilesperpage) + 1)
  451. i=0
  452. for n=((curpage*tilesperpage)-tilesperpage+1), (curpage*tilesperpage) do
  453. i = i + 1
  454. if fulllist[n] == nil then break end
  455. getdisplayname(fulllist[n])
  456. getcoordspot(i)
  457. printtile(prx,pry)
  458. end
  459. for n=1, tilesperpage do
  460. getcoordspot(n)
  461. printtileborders(prx,pry)
  462. end
  463. end
  464.  
  465. function pagedown()
  466. if curpage < maxpage
  467. then
  468. curpage = curpage + 1
  469. fullrefresh()
  470. end
  471. end
  472.  
  473. function pageup()
  474. if curpage > 1
  475. then
  476. curpage = curpage - 1
  477. fullrefresh()
  478. end
  479. end
  480.  
  481. function movecursor(direction)
  482. if direction == "left"
  483. then
  484. if curselx > 1
  485. then
  486. preselx = curselx
  487. curselx = curselx - 1
  488. end
  489. end
  490. if direction == "right"
  491. then
  492. if curselx < spacefortilesx
  493. then
  494. preselx = curselx
  495. curselx = curselx + 1
  496. end
  497. end
  498. if direction == "up"
  499. then
  500. if cursely > 1
  501. then
  502. presely = cursely
  503. cursely = cursely - 1
  504. end
  505. end
  506. if direction == "down"
  507. then
  508. if cursely < spacefortilesy
  509. then
  510. presely = cursely
  511. cursely = cursely + 1
  512. end
  513. end
  514. end
  515.  
  516. function getminimumlevel()
  517. curselminuselvl = 4
  518. curselmineditlvl = 4
  519. for k=3, 1,-1 do
  520. DBU = io.open("/CookieSystem/DB/DBlevels/uselevel/"..k, "r")
  521. while true do
  522. ucheck = DBU:read()
  523. if ucheck == nil then break end
  524. if (path..curselthing) == ucheck then curselminuselvl = k end
  525. end
  526. DBU:close()
  527. DBE = io.open("/CookieSystem/DB/DBlevels/editlevel/"..k, "r")
  528. while true do
  529. echeck = DBE:read()
  530. if echeck == nil then break end
  531. if (path..curselthing) == echeck then curselmineditlvl = k end
  532. end
  533. DBE:close()
  534. end
  535. end
  536.  
  537. function use()
  538. if curselthing ~= "empty spot" then
  539. if fs.isDir(path..curselthing)
  540. then
  541. path = (path..curselthing.."/")
  542. else
  543. getminimumlevel()
  544. if curselminuselvl <= curlevel
  545. then
  546. if string.sub(curselthing, -4) == ".txt"
  547. then shell.run("edit", path..curselthing)
  548. else shell.run(path..curselthing)
  549. end
  550. sleep(1)
  551. else
  552. infoline = "Level too low"
  553. end
  554. end
  555. curpage = 1
  556. fullrefresh()
  557. end
  558. end
  559.  
  560. function back()
  561. if path ~= "/"
  562. then
  563. pathhelp = path
  564. pathhelpn = 1
  565. pathhelpnrawr = 0
  566. pathhelpnpre = 0
  567. while true do
  568. pathhelpnrawr = pathhelpnpre
  569. pathhelpnpre = pathhelpn
  570. pathhelpn = pathhelpn - pathhelpnrawr
  571. if pathhelp == "" or pathhelp == nil then break end
  572. pathhelp = string.sub(pathhelp, pathhelpn+1)
  573. if pathhelp == "" or pathhelp == nil then break end
  574. pathhelpn = string.find(pathhelp, "/")
  575. end
  576. path = string.sub(path,1,pathhelpnrawr)
  577. end
  578. curpage = 1
  579. fullrefresh()
  580. end
  581.  
  582. function tabkey()
  583. tabmax = 2
  584. if curtabloc == 1 then newtabloc = (curtabloc + 1) end
  585. if curtabloc == tabmax then newtabloc = 1 end
  586. curtabloc = newtabloc
  587. end
  588.  
  589. function home()
  590. curpage = 1
  591. path = "/"
  592. curselx = 1
  593. cursely = 1
  594. basescreen()
  595. showstuff()
  596. getcurselthing()
  597. end
  598.  
  599. function exdelete()
  600. if cursel ~= "empty spot"
  601. then
  602. getminimumlevel()
  603. if curselmineditlvl <= curlevel
  604. then
  605. shell.run("rm", path..curselthing)
  606. fullrefresh()
  607. else
  608. infoline = "Level too low"
  609. end
  610. else
  611. infoline = "Select something first"
  612. end
  613. end
  614.  
  615. function exedit()
  616. if curselthing ~= "empty spot"
  617. then
  618. getminimumlevel()
  619. if curselmineditlvl <= curlevel
  620. then
  621. shell.run("edit", path..curselthing)
  622. fullrefresh()
  623. else
  624. infoline = "Level too low"
  625. end
  626. else
  627. infoline = "Select something first"
  628. end
  629. end
  630.  
  631. function excopy()
  632. if curselthing ~= "empty spot"
  633. then
  634. curcopysel = (path..curselthing)
  635. infoline = ("Copying "..curselthing)
  636. else
  637. infoline = "Select something first."
  638. end
  639. end
  640.  
  641. function expaste()
  642. shell.run("cp", curcopysel, path)
  643. fullrefresh()
  644. end
  645.  
  646. function executecomtab()
  647. if comtabsel == 1 then use() end
  648. if comtabsel == 2 then exedit() end
  649. if comtabsel == 3 then excopy() end
  650. if comtabsel == 4 then expaste() end
  651. end
  652.  
  653. function interfacebrowser()
  654. event, argument = os.pullEvent()
  655. if event == "key" and argument == 203 then movecursor("left") end
  656. if event == "key" and argument == 205 then movecursor("right") end
  657. if event == "key" and argument == 200 then movecursor("up") end
  658. if event == "key" and argument == 208 then movecursor("down") end
  659. if event == "key" and argument == 28 then executecomtab() end
  660. if event == "key" and argument == 14 then back() end
  661. if event == "key" and argument == 15 then tabkey() end
  662. if event == "key" and argument == 209 then pagedown() end
  663. if event == "key" and argument == 201 then pageup() end
  664. if event == "key" and argument == 211 then exdelete() end
  665. if event == "key" and argument == 199 then home() end
  666. if event == "key" and argument == 2 then comtabsel = 1 end
  667. if event == "key" and argument == 3 then comtabsel = 2 end
  668. if event == "key" and argument == 4 then comtabsel = 3 end
  669. if event == "key" and argument == 5 then comtabsel = 4 end
  670. end
  671.  
  672. function getcurselthing()
  673. local ns = ((cursely-1)*spacefortilesx + curselx)+((curpage-1)*tilesperpage)
  674. if ns <= #fulllist
  675. then
  676. curselthing = fulllist[ns]
  677. else
  678. curselthing = "empty spot"
  679. end
  680. end
  681.  
  682.  
  683.  
  684. function exnew()
  685. if string.sub(cmdln, 5, 11) == "program"
  686. then
  687. newprogramname = string.sub(cmdln, 13)
  688. if newprogramname ~= nil and newprogramname ~= ""
  689. then
  690. if fs.exists(path..newprogramname) == false
  691. then
  692. shell.run("edit", path..newprogramname)
  693. fullrefresh()
  694. else
  695. infoline = "That name already exists"
  696. end
  697. else
  698. infoline = "Command is New <folder/program> <name>"
  699. end
  700. elseif string.sub(cmdln, 5, 10) == "folder"
  701. then
  702. newfoldername = string.sub(cmdln, 12)
  703. if newfoldername ~= nil and newfoldername ~= ""
  704. then
  705. if fs.exists(path..newfoldername) == false
  706. then
  707. fs.makeDir(path..newfoldername)
  708. fullrefresh()
  709. else
  710. infoline = "That name already exists"
  711. end
  712. else
  713. infoline = "Command is New <folder/program> <name>"
  714. end
  715. else
  716. infoline = "Command is New <folder/program> <name>"
  717. end
  718. end
  719.  
  720. function exshutdown()
  721. infoline = "Shutting down computer..."
  722. bottomui()
  723. sleep(2)
  724. os.shutdown()
  725. end
  726.  
  727. function exhelp()
  728. local helprawr = string.sub(cmdln,6)
  729. term.clear()
  730. term.setCursorPos(1,1)
  731. shell.run("help", helprawr)
  732. term.setCursorPos(5,18)
  733. write("Press any key to continue")
  734. while true do
  735. event = os.pullEvent()
  736. if event == "key" then break end
  737. end
  738. fullrefresh()
  739. end
  740.  
  741. function exsetlevel()
  742. local editoruse = "rawr"
  743. local setnewlevel = 0
  744. if string.sub(cmdln,10,12) == "use" then
  745. editoruse = "use"
  746. if string.sub(cmdln, 14,14) == "1" then setnewlevel = "1"
  747. elseif string.sub(cmdln, 14,14) == "2" then setnewlevel = "2"
  748. elseif string.sub(cmdln, 14,14) == "3" then setnewlevel = "3"
  749. else infoline = "Command is setlevel use/edit 1/2/3"
  750. end
  751. else infoline = "Command is setlevel use/edit 1/2/3"
  752. end
  753. if string.sub(cmdln,10,13) == "edit" then
  754. editoruse = "edit"
  755. if string.sub(cmdln, 15,15) == "1" then setnewlevel = "1"
  756. elseif string.sub(cmdln, 15,15) == "2" then setnewlevel = "2"
  757. elseif string.sub(cmdln, 15,15) == "3" then setnewlevel = "3"
  758. else infoline = "Command is setlevel use/edit 1/2/3"
  759. end
  760. else infoline = "Command is setlevel use/edit 1/2/3"
  761. end
  762.  
  763. if setnewlevel ~= 0 then
  764. local curselthingmem = curselthing
  765. local pathmem = path
  766. path = ("/cookiesystem/DB/DBlevels/"..editoruse.."level/")
  767. curselthing = setnewlevel
  768.  
  769. getminimumlevel()
  770. if curselmineditlvl <= curlevel
  771. then
  772. file = io.open(path..curselthing, "a")
  773. file:write("\n"..pathmem..curselthingmem)
  774. file:close()
  775. else
  776. infoline = "Your level is too low"
  777. end
  778. path = pathmem
  779. curselthing = curselthingmem
  780. end
  781. end
  782.  
  783. function exrename()
  784. if curselthing ~= "empty spot"
  785. then
  786. local newname = string.sub(cmdln, 8)
  787. shell.run("move", path..curselthing, path..newname)
  788. fullrefresh()
  789. else
  790. infoline = "select something first"
  791. end
  792. end
  793.  
  794. function executeline()
  795. if cmdln == "edit" then exedit() end
  796. if string.sub(cmdln,1,3) == "new" then exnew() end
  797. if cmdln == "delete" then exdelete() end
  798. if cmdln == "shutdown" then exshutdown() end
  799. if string.sub(cmdln,1,4) == "help" then exhelp() end
  800. if cmdln == "copy" then excopy() end
  801. if cmdln == "paste" then expaste() end
  802. if string.sub(cmdln,1,8) == "setlevel" then exsetlevel() end
  803. if cmdln == "maintenance" and curname == "admin" then maintenance = true infoline = "Maintenance mode activated, hold ctrl+T" end
  804. if string.sub(cmdln,1,6) == "rename" then exrename() end
  805. cmdln = ""
  806. end
  807.  
  808. function commandline()
  809. bottomui()
  810. term.setCursorPos(1,lowesty-2)
  811. write(">"..cmdln)
  812. while true do
  813. event, argument = os.pullEvent()
  814. if event == "key" and argument == 15 then tabkey() break end
  815. if event == "key" and argument == 28 then executeline() break end
  816. if event == "key" and argument == 14
  817. then
  818. if string.len(cmdln) > 0 then
  819. cmdln = string.sub(cmdln, 1, (string.len(cmdln)-1))
  820. term.setCursorPos(1,lowesty-2)
  821. write(">"..cmdln.." ")
  822. end end
  823. if event == "char"
  824. then
  825. term.setCursorPos(1,lowesty-2)
  826. cmdln = (cmdln..argument)
  827. write(">"..cmdln)
  828. end
  829. end
  830. term.setCursorPos(1,lowesty-2)
  831. write(" ")
  832. end
  833.  
  834. function interfaceupdate()
  835. topui()
  836. bottomui()
  837.  
  838. prpsx = (1 + ((preselx-1)*10))
  839. prpsy = (presely*3)
  840. printtileborders(prpsx,prpsy)
  841.  
  842. prselx = (1 + ((curselx-1)*10))
  843. prsely = (cursely*3)
  844. printtilebordersselected(prselx,prsely)
  845.  
  846. preselx = curselx
  847. presely = cursely
  848. end
  849.  
  850. function fullrefresh()
  851. curselx = 1
  852. cursely = 1
  853. basescreen()
  854. showstuff()
  855. getcurselthing()
  856. end
  857.  
  858.  
  859.  
  860. ini()
  861. getsizestuff()
  862. basescreen()
  863. showstuff()
  864. getcurselthing()
  865.  
  866. while true do
  867. interfaceupdate()
  868. if curtabloc == 1
  869. then
  870. interfacebrowser()
  871. getcurselthing()
  872. end
  873. if curtabloc == 2
  874. then
  875. commandline()
  876. end
  877.  
  878. end
  879. ]])
  880. file:close()
  881. end
  882.  
  883. function createhelpfiles()
  884.  
  885. file = io.open("/CookieSystem/CS-Help", "w")
  886. file:write([[term.clear()
  887. term.setCursorPos(1,1)
  888. print("===================CookieSystem==================")
  889. print("Press tab to change between tab modes.If there is")
  890. print("a > before the commandline you're in cmdln mode. ")
  891. print("In navigation mode you can move trough the field ")
  892. print("with the arrow keys, if there are more than 20 ")
  893. print("items you can move trough pages with pageup/down ")
  894. print("Use backspace to move up a level and enter to go ")
  895. print("in a folder or execute a program. Press home to ")
  896. print("return to the main page and delete to delete. ")
  897. print("In cmdln mode you can use the following commands:")
  898. print("shutdown, help (same as normal), copy, paste, ")
  899. print("delete, rename, setlevel and maintenance (admin ")
  900. print("only). Commands like delete and copy apply to the")
  901. print("currently selected program . ")
  902. print("Add .txt to the end of a program to make a text ")
  903. print("file. These are opened in edit mode when executed")
  904. print("")
  905. term.setCursorPos(5,18)
  906. write("Press any key to continue")
  907. while true do
  908. event = os.pullEvent()
  909. if event == "key" then break end
  910. end
  911. term.clear()
  912. term.setCursorPos(1,1)
  913. ]])
  914. file:close()
  915.  
  916.  
  917. file = io.open("/CookieSystem/CS-Help levels", "w")
  918. file:write([[term.clear()
  919. term.setCursorPos(1,1)
  920. print("===================CookieSystem==================")
  921. print("If the computer is used by multiple players then ")
  922. print("you might want to set up different accounts and ")
  923. print("access levels. The current account level can be ")
  924. print("seen in the top left corner. To set a level you ")
  925. print("must be able to edit the correct file in the DB ")
  926. print("folder. Open it and add the path and name of the ")
  927. print("program or go to the program itself and use the ")
  928. print("command setlevel use/edit 1/2/3 ")
  929. print("To use the command your level needs to be able to")
  930. print("edit the right files. So if you want to set a ")
  931. print("programs use level to 2, you need to be able to ")
  932. print("edit the file CookieSystem/DB/DBlevels/uselevel/2")
  933. print("")
  934. print("The level system treats program and text files ")
  935. print("in the same way, except that you can't execute ")
  936. print("text files like programs. ")
  937. term.setCursorPos(5,18)
  938. write("Press any key to continue")
  939. while true do
  940. event = os.pullEvent()
  941. if event == "key" then break end
  942. end
  943. term.clear()
  944. term.setCursorPos(1,1)
  945. ]])
  946. file:close()
  947. end
  948.  
  949. function createstartup()
  950. file = io.open("startup", "w")
  951. file:write([[maintenance = false
  952. newprogramstart = false
  953. amountofsideprogramsrunning = 0
  954.  
  955. while true do
  956. shell.run("/CookieSystem/login")
  957. if corlogin then break end
  958. end
  959.  
  960. while true do
  961. while true do
  962. shell.run("/CookieSystem/CS System/interface")
  963. if maintenance then break end
  964. if newprogramstart == true
  965. then
  966. newprogramstart = false
  967. break
  968. end
  969. end
  970. if maintenance then break end
  971. end
  972.  
  973. term.clear()
  974. term.setCursorPos(1,1)]])
  975. file:close()
  976. end
  977.  
  978. function createuninstall()
  979. file = io.open("/CookieSystem/CS System/uninstall", "w")
  980. file:write([[
  981. term.clear()
  982. term.setCursorPos(1,1)
  983. print("do you want to uninstall CookieSystem?")
  984. answer = read()
  985. if answer == "yes"
  986. then
  987. shell.run("rm", "/CookieSystem")
  988. shell.run("rm", "startup")
  989. os.reboot()
  990. else
  991. print("Uninstal aborted")
  992. end
  993. ]])
  994. file:close()
  995. end
  996.  
  997.  
  998. ----------------------------------
  999. ----------------------------------
  1000.  
  1001. function install()
  1002. createfolders()
  1003. createlevelfiles()
  1004. createadminaccount()
  1005. createlogin()
  1006. createcreate()
  1007. createdelete()
  1008. createsetlvl()
  1009. createchangepass()
  1010. createinterface()
  1011. createhelpfiles()
  1012. createstartup()
  1013. createuninstall()
  1014. end
  1015.  
  1016. function topthing()
  1017. term.clear()
  1018. term.setCursorPos(13,2)
  1019. write("========================")
  1020. term.setCursorPos(13,3)
  1021. write("|CookieSystem Installer|")
  1022. term.setCursorPos(13,4)
  1023. write("========================")
  1024. end
  1025.  
  1026. topthing()
  1027. term.setCursorPos(1,5)
  1028. print("Do you want to install CSv1.1 on your computer?")
  1029. answer = read()
  1030. if answer == "yes"
  1031. then
  1032. install()
  1033. else
  1034. term.setCursorPos(15,8)
  1035. print("Installation aborted.")
  1036. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement