Advertisement
Guest User

Untitled

a guest
Apr 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.37 KB | None | 0 0
  1. oldpullEvent = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. -- Cannon OS by PaymentOption --
  5. VERSION = 1.85
  6. --------------------------------
  7.  
  8. rednet.open("top")
  9. rednet.open("bottom")
  10. rednet.open("back")
  11. rednet.open("front")
  12. rednet.open("right")
  13. rednet.open("left")
  14.  
  15. --[[ Notes:
  16. User information like passwords are located in the User/<computerID>/.info.
  17. E-Mails are stored in the /Mail Directory.
  18. E-Mail preferences are stored in /Mail/.prefs.
  19.  
  20. All printing functions like PrintMenu and PrintMainScreen do not clear the screen first; you must clear it before using them.
  21. --]]
  22.  
  23.  
  24. -- VARIABLES --
  25.  
  26. -- Update and Service Variables --
  27. nServerID = 12 -- Update and key check server ID
  28. ----------------------------------
  29.  
  30. -- Screen Variables --
  31. screenWidth, screenHeight = term.getSize()
  32. selection = 1
  33.  
  34. sMenuState = "main"
  35. ----------------------
  36.  
  37. -- Account Variables --
  38. sUserName = ""
  39. sPassword = ""
  40.  
  41. bNewUser = true
  42. bLogin = true
  43.  
  44. bAdmin = true -- Switch to false to disable the following features: CraftOS, Computer, Email, Account Manipulation
  45. -----------------------
  46.  
  47. -- Mail --
  48. if(fs.isDir("Mail")) then nMail = #(fs.list("Mail"))-1
  49. else nMailCount = 0 end
  50. ----------
  51. ---------------
  52.  
  53. clear()
  54. printMainScreen()
  55. sleep(2)
  56.  
  57. clear()
  58. printBorder()
  59.  
  60. cPrint(3, "Welcome!")
  61. cPrint(5, "You're about to install:")
  62. cPrint(6, "Cannon OS V:"..VERSION.."!")
  63. cPrint(7, " The installation wizard will walk you")
  64. cPrint(8, " through product validation to installation.")
  65. cPrint(10, "Before you continue, make sure that you have")
  66. cPrint(11, " the product key given by your distributor.")
  67.  
  68. cPrint(15, "[ Continue ]")
  69. while true do
  70. event, key = os.pullEvent("key")
  71.  
  72. if key == 28 then break end
  73. end
  74.  
  75. clear()
  76. printBorder()
  77.  
  78. rPrint(17, "Cannon OS Version: "..VERSION.."*")
  79. rPrint(16, "Software: LOCKED*")
  80.  
  81. cPrint(8, "Please enter your product key here:")
  82. term.setCursorPos(15, 9); write("Key: ")
  83. local sProductKey = newRead()
  84.  
  85. if checkKey(sProductKey) then
  86. clear()
  87. printBorder()
  88.  
  89. cPrint(9, "Congradulations,")
  90. cPrint(10, "Your software has successfully been")
  91. cPrint(11, "VALIDATED!")
  92. sleep(3)
  93.  
  94. local file = fs.open(".key", "w")
  95. file.writeLine(sProductKey)
  96. file.close()
  97. bIsAuthentic = true
  98. else
  99. clear()
  100. printBorder()
  101.  
  102. cPrint(8, "I'm sorry, but the key")
  103. cPrint(9, "entered doesn't seem to be valid.")
  104. sleep(3)
  105. os.shutdown()
  106. end
  107. end
  108. -------------------------
  109.  
  110.  
  111. -- Helper Functions --
  112. function cPrint(height, string)
  113. local xPos = screenWidth/2 - string.len(string)/2
  114. term.setCursorPos(xPos, height); term.write(string)
  115. end
  116.  
  117. function rPrint(height, string)
  118. local xPos = screenWidth - string.len(string)
  119. term.setCursorPos(xPos, height); term.write(string)
  120. end
  121.  
  122. function clear() term.clear(); term.setCursorPos(1,1) end
  123.  
  124. function printBorder()
  125. write(" "..string.rep("*", screenWidth-2).."n")
  126. for i=1, screenHeight-2 do
  127. write(" *"..string.rep(" ", screenWidth-4).."*n")
  128. end
  129. write(" "..string.rep("*", screenWidth-2))
  130. end
  131.  
  132. function customWrite(height, string)
  133. term.setCursorPos(3, height)
  134. term.write(string)
  135. end
  136.  
  137. function clearCenter()
  138. cPrint(2, "* "..sUserName.." *")
  139. cPrint(3, "*"..string.rep("*", string.len(sUserName)+2).."*")
  140. rPrint(17, "Cannon OS Version: "..VERSION.. "*")
  141.  
  142. local line = 4
  143. term.setCursorPos(34, 3); term.write(" ") -- Remove the very top part of the cannon logo
  144. repeat
  145. term.setCursorPos(1, line); term.clearLine()
  146. line = line+1
  147. until line == 12
  148.  
  149. line = 4
  150. term.setCursorPos(1, 4)
  151.  
  152. repeat
  153. write(" *"..string.rep(" ", screenWidth-4).."*n")
  154. line = line+1
  155. until line == 12
  156. end
  157.  
  158. function printContainer()
  159. term.setCursorPos(4, 5); term.write(string.rep("*", screenWidth-6))
  160. local y = 6
  161. for i=1, screenHeight - 13 do
  162. term.setCursorPos(4, y); term.write("*"..string.rep(" ", screenWidth-8).."*")
  163. y = y+1
  164. end
  165. term.setCursorPos(4, 11); term.write(string.rep("*", screenWidth-6))
  166. end
  167.  
  168. -- Perfecting the pullEvent backspace attempt 1! --
  169.  
  170. function newRead( _charLimit, _ReplaceChar) -- The filter can either be a 1, 0, or nil. 1 is Numbers only, 0 is letters only, and nil is both
  171. local sMessage = ""
  172. term.setCursorBlink(true)
  173. local originalCursorX, originalCursorY = term.getCursorPos()
  174.  
  175. while true do
  176. local cursorX, cursorY = term.getCursorPos()
  177. local event, p1 = os.pullEvent()
  178.  
  179. if _charLimit ~= nil then
  180. if string.len(sMessage) == _charLimit then term.setCursorBlink(false); return sMessage end
  181. end
  182.  
  183. if event == "char" then sMessage = sMessage..p1
  184. --[[elseif event == "key" then -- The escape key has keyID 1 so: 0 = keyID: 11, 1 = keyID: 2, 2 = keyID : 3 etc etc....
  185. if p1 == 11 or p1 == 2 or p1 == 3 or p1 == 4 or p1 == 5 or p1 == 6 or p1 == 7 or p1 == 8 or p1 == 9 or p1 == 10 then
  186. -- 0 1 2 3 4 5 6 7 8 9
  187. sMessage = sMessage..(p1-1)
  188. end--]]
  189. end
  190.  
  191. if event == "key" and p1 == 28 then term.setCursorBlink(false); return sMessage end-- Enter key; end the loop and let's see the string
  192.  
  193. if event == "key" and p1 == 14 then -- Backspace...
  194. sMessage = string.sub(sMessage, 1, string.len(sMessage)-1)
  195. -- Set our message to the substring of the first charcter
  196. -- To the length of the message minus 1 to achieve one less letter.
  197.  
  198. term.setCursorPos(originalCursorX, cursorY)
  199. term.write(sMessage.." ") -- Adding this empty space clears the removed character from the line, but may pose future issues
  200. end
  201.  
  202. term.setCursorPos(originalCursorX, cursorY); term.write(string.rep(" ", string.len(sMessage)))
  203. -- Clear the previous line just in case we get a new line
  204. -- Now write the message on the new line
  205. if _ReplaceChar ~= nil then
  206. term.setCursorPos(originalCursorX, cursorY)
  207. term.write(string.rep( _ReplaceChar, string.len(sMessage) ))
  208. else
  209. term.setCursorPos(originalCursorX, cursorY)
  210. term.write(sMessage)
  211. end
  212. end
  213. end
  214. ----------------------
  215.  
  216.  
  217. -- System Functions --
  218. function checkInstalltion()
  219. if fs.exists("SYSTEM/.installed") then return true
  220. else return false end
  221. end
  222.  
  223. function runShell() shell.run("/rom/programs/shell") end
  224.  
  225. function getVersion() return VERSION end
  226.  
  227. function checkVersion()
  228. local sCommand = "get"
  229. if sCommand == "get" then
  230. local sCode = "c17Hgq1A"
  231. local sPath = ".tempVersion"
  232.  
  233. while true do
  234. local response = http.get(
  235. "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
  236. )
  237.  
  238. if response then
  239. local sResponse = response.readAll()
  240. response.close()
  241. if tonumber(sResponse) > VERSION then return true
  242. else return false end
  243. break
  244. else return false end
  245. end
  246. end
  247. end
  248.  
  249. function updateSelf()
  250. local sCommand = "get"
  251. if sCommand == "get" then
  252. local sCode = "6a92bGGZ"
  253. local sFile = "startup"
  254. local sPath = shell.resolve( sFile )
  255.  
  256. while true do
  257. local response = http.get(
  258. "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
  259. )
  260.  
  261. if response then
  262. local sResponse = response.readAll()
  263. response.close()
  264.  
  265. local file = fs.open( sPath, "w" )
  266. file.write( sResponse )
  267. file.close()
  268. break
  269. else return false end
  270. end
  271. end
  272. end
  273.  
  274. function checkDirs()
  275. if not fs.isDir("Mail") then shell.run("rom/programs/mkdir", "Mail"); nMailCount = (#(fs.list("/Mail"))) end
  276. if not fs.isDir("User") then shell.run("rom/programs/mkdir", "User"); shell.run("rom/programs/mkdir", "User/"..tostring(os.getComputerID())) end
  277. if not fs.isDir("User/"..tostring(os.getComputerID()).."/Projects") then shell.run("rom/programs/mkdir", "User/"..tostring(os.getComputerID()).."/Projects") end
  278. if not fs.isDir("User/"..tostring(os.getComputerID()).."/Desktop") then shell.run("rom/programs/mkdir", "User/"..tostring(os.getComputerID()).."/Desktop") end
  279. if not fs.isDir("User/"..tostring(os.getComputerID()).."/Desktop/Shortcuts") then shell.run("rom/programs/mkdir", "User/"..tostring(os.getComputerID()).."/Desktop/Shortcuts") end
  280. if not fs.isDir("User/"..tostring(os.getComputerID()).."/Files") then shell.run("rom/programs/mkdir", "User/"..tostring(os.getComputerID()).."/Files") end
  281.  
  282. if not fs.isDir("Mail/Contacts") then shell.run("rom/programs/mkdir", "Mail/Contacts") end
  283. if not fs.isDir("SYSTEM") then shell.run("rom/programs/mkdir", "SYSTEM") end
  284. if not fs.exists("SYSTEM/Version") then
  285. local file = fs.open("SYSTEM/Version", "w"); file.writeLine(tostring(VERSION))
  286. file.close()
  287. end
  288. file = fs.open("SYSTEM/.installed", "w")
  289. file.writeLine("TRUE")
  290. file.close()
  291. end
  292.  
  293.  
  294. function checkUserInformation()
  295. if fs.exists("User/"..os.getComputerID().."/.info") then
  296. local file = fs.open("User/"..os.getComputerID().."/.info", "r")
  297. sUserName = file.readLine()
  298. sPassword = file.readLine()
  299. file.close()
  300. bNewUser = false
  301. else
  302. bNewUser = true
  303. end
  304. end
  305.  
  306. function getUserInformation()
  307. if bNewUser == false then return nil -- This is to prevent accidental account resets
  308. else
  309. printNewUserScreen()
  310. end
  311. end
  312.  
  313. function handleLogin()
  314. if fs.exists(".login") then
  315. file = fs.open(".login", "r")
  316. fileContents = file.readAll()
  317. file.close()
  318. fs.delete(".login")
  319. bLogin = false
  320.  
  321. if fileContents == "false" then return end
  322. end
  323.  
  324. if bNewUser == false then
  325. printMainScreen(); sleep(2)
  326. clear()
  327.  
  328. printBorder()
  329. cPrint(4, "***************************")
  330. cPrint(5, "* Identification required *")
  331. cPrint(6, "***************************")
  332.  
  333. cPrint(8, "Username: ")
  334. cPrint(9, "Password: ")
  335. rPrint(17, "Cannon OS Version: "..VERSION.."*")
  336. rPrint(16, "LOCKED*")
  337.  
  338. term.setCursorPos(screenWidth/2 - string.len("Username: ")/2 + string.len("Username: "), 8)
  339. local tempUserName = newRead(14, nil)
  340. term.setCursorPos(screenWidth/2 - string.len("Password: ")/2 + string.len("Password: "), 9)
  341. local tempPassword = newRead(14, "*")
  342.  
  343. if tempUserName == sUserName and tempPassword == sPassword then
  344. rPrint(16, "UNLOCKED*")
  345. cPrint(11, "**********************")
  346. cPrint(12, "* Successfull login! *")
  347. cPrint(13, "**********************")
  348. sleep(2)
  349. return
  350. else
  351. cPrint(11, "************************")
  352. cPrint(12, "* Unsuccessfull login! *")
  353. cPrint(13, "************************")
  354. sleep(2)
  355. os.shutdown()
  356. end
  357. end
  358. end
  359.  
  360. function printInstallation()
  361. if checkInstalltion() then return end
  362. printBorder()
  363. cPrint(4, "*************************")
  364. cPrint(5, "* Installation Progress *")
  365. cPrint(6, "*************************")
  366.  
  367. local progressPosition = 6; -- X position to represent where the progress bars will be drawn
  368. local nProgressPercent = 0;
  369.  
  370. cPrint(8, " * "..string.rep("*", screenWidth - 6))
  371. cPrint(9, " * *"..string.rep(" ", screenWidth - 8).."*")
  372. cPrint(10, " * "..string.rep("*", screenWidth - 6))
  373.  
  374. cPrint(12, "********")
  375. cPrint(13, "* "..string.rep(" ", string.len("100%")).." *")
  376. cPrint(14, "********")
  377.  
  378. for i=1, 80 do
  379. if i%2 == 0 then
  380. term.setCursorPos(progressPosition, 9); term.write("|")
  381. progressPosition = progressPosition+1
  382. sleep(0.2)
  383. end
  384. nProgressPercent = nProgressPercent+1
  385. if nProgressPercent == 75 then nProgressPercent = 95 end
  386. if nProgressPercent == 95 then sleep(1.1) end
  387. term.setCursorPos(24, 13); term.write(nProgressPercent)
  388. end
  389. checkDirs()
  390. end
  391.  
  392. -- Background Processes --
  393. function checkMail(sender, message)
  394. if string.find(message, "CANNONMAILMESSAGE") then
  395. local file = fs.open("Mail/Unread"..nMailCount, "w")
  396. message = string.gsub(message, "CANNONMAILMESSAGE", "")
  397. file.write(tostring(sender).."n"..tostring(message))
  398. file.close()
  399.  
  400. nMailCount = nMailCount+1
  401. end
  402. end
  403. --------------------------
  404. ----------------------
  405.  
  406.  
  407. -- Menues and other screens --
  408. function printNewUserScreen()
  409. if bNewUser == false then return end
  410. local bPasswordsMatch = false
  411.  
  412. printBorder()
  413. printWelcome()
  414. sleep(3)
  415. clear()
  416.  
  417. printBorder()
  418. cPrint(2, "* New User *")
  419. cPrint(3, "************")
  420.  
  421. rPrint(17, "Cannon OS Version: "..VERSION.."*")
  422.  
  423. cPrint(6, "Username: ")
  424. cPrint(7, "Password: ")
  425. cPrint(8, " Confirm: ")
  426. cPrint(12, "************************")
  427. cPrint(13, "*Password not optional!*")
  428. cPrint(14, "************************")
  429.  
  430. term.setCursorPos(screenWidth/2-string.len("Username: ")/2+string.len("Username: "), 6)
  431. sUserName = newRead(14, nil)
  432. if string.len(sUserName) > 14 then
  433. cPrint(10, "Username is too long!"); sleep(1.3)
  434. term.setCursorPos(1, 10); term.clearLine() -- Clear the line 10
  435. term.write(" *"..string.rep(" ", screenWidth-4).."*")
  436.  
  437. term.setCursorPos(1, 6); term.clearLine() -- Clear the line
  438. term.write(" *"..string.rep(" ", screenWidth-4).."*")
  439. cPrint(6, "Username: ")
  440. term.setCursorPos(screenWidth/2-string.len("Username: ")/2+string.len("Username: "), 6)
  441. sUserName = newRead(14, nil)
  442. end
  443. while bPasswordsMatch == false do
  444. term.setCursorPos(screenWidth/2-string.len("Password: ")/2+string.len("Password: "), 7)
  445. sPassword = newRead(14, "*")
  446. if sPassword ~= nil and sPassword ~= "" then
  447. term.setCursorPos(screenWidth/2-string.len(" Confirm: ")/2+string.len(" Confirm: "), 8)
  448. local sConfirm = newRead(14, "*")
  449. if sConfirm ~= sPassword then
  450. cPrint(10, "Passwords do not match!"); sleep(1.3)
  451. term.setCursorPos(1, 10); term.clearLine() -- Clear the line 10
  452. term.write(" *"..string.rep(" ", screenWidth-4).."*")
  453.  
  454. term.setCursorPos(1, 7); term.clearLine() -- Clear the line 7
  455. term.write(" *"..string.rep(" ", screenWidth-4).."*")
  456. cPrint(7, "Password: ")
  457.  
  458. term.setCursorPos(1, 8); term.clearLine() -- Clear the line 8
  459. term.write(" *"..string.rep(" ", screenWidth-4).."*")
  460. cPrint(8, " Confirm: ")
  461. else sPassword = sConfirm; bPasswordsMatch = true end
  462. else sPassword = ""
  463. end
  464. end
  465.  
  466. local file = fs.open("User/"..os.getComputerID().."/.info", "w")
  467. file.writeLine(tostring(sUserName))
  468. if sPassword == "" then file.writeLine("N/A")
  469. else file.writeLine(tostring(sPassword))
  470. end
  471. file.close()
  472.  
  473. cPrint(10, "Account '"..sUserName.. "' succesfully created!"); sleep(1.3)
  474. end
  475.  
  476. function printWelcome()
  477. customWrite(3, "__ __ _ ")
  478. customWrite(4, " / / | | ")
  479. customWrite(5, " / / /___| | ___ ___ _ __ ___ ___ ")
  480. customWrite(6, " / / // _ |/ __|/ _ | '_ ' _ / _ ")
  481. customWrite(7, " / /| __/ | (__| (_) | | | | | | __/")
  482. customWrite(8, " / / ___|_|___|___/|_| |_| |_|___|")
  483. customWrite(9, " _ _ ")
  484. customWrite(10, " | | | | ")
  485. customWrite(11, " | | | |___ ___ _ __ ")
  486. customWrite(12, " | | | / __|/ _ '__|")
  487. customWrite(13, " | |__| __ __/ | ")
  488. customWrite(14, " ____/|___/___|_| ")
  489.  
  490. rPrint(17, "Cannon OS Version: "..VERSION.."*")
  491. end
  492.  
  493. function printMainScreen()
  494. printBorder()
  495. customWrite(2, " ________")
  496. customWrite(3, " | ______o|")
  497. customWrite(4, " _______________ ||__---_||")
  498. customWrite(5, " | ___________ || ______ |")
  499. customWrite(6, " | | | |||______||")
  500. customWrite(7, " | | Cannon OS | ||--------|")
  501. customWrite(8, " | | By | || O |")
  502. customWrite(9, " | | Payment | || | |")
  503. customWrite(10, " | '-----------' || | |")
  504. customWrite(11, " |_____________-_|| | |")
  505. customWrite(12, " __/_________ |::::::::|")
  506. customWrite(13, " ________________'-.__")
  507. customWrite(14, " /:::::::::':::':: .---.")
  508. customWrite(15, " /::======::: .:.::: _) ")
  509. customWrite(16, ' """""""""""""""""""" -----')
  510.  
  511. term.setCursorPos(3, 17); term.write("By PaymentOption")
  512. rPrint(17, "Version: "..VERSION.. "*")
  513. end
  514.  
  515. function printLogo()
  516. term.setCursorPos(34, 3); term.write("__")
  517. customWrite(4, " / ")
  518. customWrite(5, " .-. | |")
  519. customWrite(6, " * _.-' __/")
  520. customWrite(7, " .-' ")
  521. customWrite(8, " / _/")
  522. customWrite(9, " | _ /")
  523. customWrite(10, " | /_'")
  524. customWrite(11, " _____/")
  525. end
  526.  
  527. function printLogout()
  528. term.setCursorPos(34, 3); term.write(" ")
  529.  
  530. clearCenter()
  531.  
  532. cPrint(5, "********")
  533. cPrint(6, "*Logout*")
  534. cPrint(7, "********")
  535. cPrint(8, "/ ")
  536. cPrint(9, "***************")
  537. cPrint(10, "*[ Yes ] No *")
  538. cPrint(11, "***************")
  539.  
  540. while true do
  541. event, key = os.pullEvent("key")
  542.  
  543. if key == 205 and selection < 2 then selection = 2
  544. elseif key == 203 and selection > 1 then selection = 1
  545.  
  546. elseif key == 28 and selection == 1 then os.reboot()
  547. elseif key == 28 and selection == 2 then sMenuState = "main"; selection = 6; break
  548. end
  549.  
  550. if selection == 1 then cPrint(10, "*[ Yes ] No *")
  551. else cPrint(10, "* Yes [ No ]*") end
  552. end
  553. end
  554.  
  555. function printMainMenu()
  556. printBorder()
  557. cPrint(2, "* "..sUserName.." *")
  558. cPrint(3, "*"..string.rep("*", string.len(sUserName)+2).."*")
  559. rPrint(17, "Cannon OS Version: "..VERSION.. "*")
  560.  
  561. if sMenuState == "main" then printLogo(); rPrint(2, "Mail: "..nMailCount.."*") end
  562.  
  563. if selection == 1 then cPrint(13, "[ Computer ] Craft OS IRC ")
  564. cPrint(15, " E-Mail Account Update ")
  565. end
  566.  
  567. if selection == 2 then cPrint(13, " Computer [ Craft OS ] IRC ")
  568. cPrint(15, " E-Mail Account Update ")
  569. end
  570.  
  571. if selection == 3 then cPrint(13, " Computer Craft OS [ IRC ] ")
  572. cPrint(15, " E-Mail Account Update ")
  573. end
  574.  
  575. if selection == 4 then cPrint(13, " Computer Craft OS IRC ")
  576. cPrint(15, "[ E-Mail ] Account Update ")
  577. end
  578.  
  579. if selection == 5 then cPrint(13, " Computer Craft OS IRC ")
  580. cPrint(15, " E-Mail [ Account ] Update ")
  581. end
  582.  
  583. if selection == 6 then cPrint(13, " Computer Craft OS IRC ")
  584. cPrint(15, " E-Mail Account [ Update ] ")
  585. end
  586. end
  587. ------------------------------
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600. -- Mail related things --
  601. function loadContacts()
  602. local tContacts = fs.list("Mail/Contacts")
  603. for i=1, #tContacts do -- Set the correct computer adress found
  604. local file = fs.open("Mail/Contacts/"..tContacts[i], "r")
  605. local fileContents = file.readAll()
  606. file.close()
  607. tContacts[i] = { name = tContacts[i], id = fileContents }
  608. end
  609.  
  610. return tContacts
  611. end
  612.  
  613. function mailMenu()
  614. recipientID = 0
  615. sLine1 = "" -- The message will be split into two lines due to lack of multiline functionality of newread()
  616. sLine2 = ""
  617. sMessage = "" -- The two lines will be combined into the whole message in this variable
  618.  
  619. selection = 1
  620. nMailCount = 0
  621. screenWidth, screenHeight = term.getSize()
  622.  
  623. function cPrint(height, string)
  624. local xPos = screenWidth/2 - string.len(string)/2
  625. term.setCursorPos(xPos, height)
  626. term.write(string)
  627. end
  628.  
  629. function rPrint(height, string)
  630. local xPos = screenWidth - string.len(string)
  631. term.setCursorPos(xPos, height)
  632. term.write(string)
  633. end
  634.  
  635. clearCenter() -- Remove the cannon logo
  636.  
  637. local function sendMessage()
  638. sMessage = ";alkdjien".."n"..sMessage
  639. rednet.send(tonumber(recipientID), sMessage)
  640. end
  641.  
  642. local function printMailMenu()
  643. rPrint(2, "Mail: "..tostring((#(fs.list("Mail"))-1).."*"))
  644.  
  645. cPrint(5, "***********")
  646. if selection == 1 then cPrint(6, "*[ Write ]*")
  647. else cPrint(6, "* Write *") end
  648.  
  649. if selection == 2 then cPrint(7, "*[ eMail ]*")
  650. else cPrint(7, "* eMail *") end
  651.  
  652. if selection == 3 then cPrint(8, "*[ Cont. ]*")
  653. else cPrint(8, "* Cont. *") end
  654.  
  655. if selection == 4 then cPrint(9, "*[ Leave ]*")
  656. else cPrint(9, "* Leave *") end
  657. cPrint(10, "***********")
  658. -- End these damn lines ^^
  659. end
  660.  
  661. local function printRevise()
  662. local nSelect = 1 -- Too much sharing of the 'select' variable
  663.  
  664. local function cDraw(width, height, string)
  665. term.setCursorPos(width, height)
  666. term.write(string)
  667. end
  668.  
  669. local function printRevMenu()
  670. cDraw(29, 5, "*****************")
  671. if nSelect == 1 then cDraw(29, 6, "*[ Send ] Exit *")
  672. else cDraw(29, 6, "* Send [ Exit ]*") end
  673. cDraw(29, 7, "*****************")
  674. end
  675.  
  676. while true do
  677. printRevMenu()
  678. event, key = os.pullEvent("key")
  679. -- Freakin' lines man ^^
  680.  
  681. if key == 205 and nSelect == 1 then nSelect = nSelect+1
  682. elseif key == 203 and nSelect == 2 then nSelect = nSelect-1
  683.  
  684. elseif key == 28 and nSelect == 1 then sendMessage(); clearCenter(); term.setCursorPos(4, 12); term.write(string.rep(" ", 42)); break
  685. elseif key == 28 and nSelect == 2 then clearCenter(); break
  686. end
  687. end
  688. end
  689.  
  690. local function composeMail()
  691. clearCenter()
  692.  
  693. term.setCursorPos(4, 5); term.write("****************************")
  694. term.setCursorPos(4, 6); term.write("*Recipient: *") -- 15 is the x position for the retrieving of 'recipietID'
  695. term.setCursorPos(4, 7); term.write("****************************")
  696.  
  697. term.setCursorPos(4, 9); term.write(string.rep("*", 42))
  698. term.setCursorPos(4, 10); term.write("*"..string.rep(" ", 40).."*") -- 2 lines to write the body of the message; 38 spaces per line
  699. term.setCursorPos(4, 11); term.write("*"..string.rep(" ", 40).."*")
  700. term.setCursorPos(4, 12); term.write(string.rep("*", 42))
  701.  
  702. term.setCursorPos(15, 6) -- Get the recipient ID
  703. recipientID = newRead(14) -- If they entered a contact name then find the id
  704. local tContacts = loadContacts()
  705.  
  706. for i=1, #tContacts do
  707. if tostring(recipientID) == tContacts[i].name then recipientID = tContacts[i].id end
  708. end
  709.  
  710. term.setCursorPos(6, 10); sLine1 = newRead(38) -- Character only filter
  711. term.setCursorPos(6, 11); sLine2 = newRead(38)
  712.  
  713. sMessage = sLine1.." "..sLine2
  714.  
  715. printRevise()
  716. end
  717.  
  718. local function contacts()
  719. local nSelect = 1
  720. local scroll = 0;
  721. local tContacts = fs.list("Mail/Contacts")
  722.  
  723. local function printContacts()
  724. local y = 6
  725. local tContacts = loadContacts()
  726.  
  727. for i = 1+scroll, #tContacts do
  728. term.setCursorPos(5, y)
  729. if nSelect == i then term.write("[ "..tContacts[i].name.." ]")
  730. else term.write(" "..tContacts[i].name.." ") end
  731.  
  732. term.setCursorPos(43, y); term.write(tContacts[i].id)
  733. y = y+1
  734. if y == 11 then break end
  735. end
  736.  
  737. term.setCursorPos(4, 3); term.write("********************")
  738. term.setCursorPos(4, 4); term.write("* Ctrl:New Contact *")
  739. end
  740.  
  741. while true do
  742. clearCenter()
  743. printContainer()
  744. printContacts()
  745.  
  746. local event, key = os.pullEvent("key")
  747. if key == 208 and nSelect < #(fs.list("Mail/Contacts")) then
  748. if nSelect >= 4 and scroll < #tContacts then scroll = scroll+1; nSelect = nSelect+1
  749. else nSelect = nSelect+1 end
  750. elseif key == 200 and nSelect > 1 then
  751. if nSelect >= 4 and scroll > 0 then scroll = scroll-1; nSelect = nSelect-1
  752. else nSelect = nSelect-1 end
  753. elseif key == 29 or key == 157 then
  754. term.setCursorPos(5, 6); term.write(string.rep(" ", screenWidth-8))
  755. term.setCursorPos(5, 6); term.write("Contact Name: ")
  756. local sContact = newRead(14)
  757.  
  758. term.setCursorPos(5, 6); term.write(string.rep(" ", screenWidth-8))
  759. term.setCursorPos(5, 6); term.write("Contact ID: ")
  760. local nContactID = newRead(14)
  761.  
  762. local file = fs.open("Mail/Contacts/"..sContact, "w")
  763. file.write(tostring(nContactID))
  764. file.close()
  765. elseif key == 14 then break
  766.  
  767. elseif key == 28 then
  768. nSelected = 1
  769. while true do
  770. if nSelected == 1 then
  771. term.setCursorPos(5, 6)
  772. term.write("Delete? [ Yes ] No ")
  773. else
  774. term.setCursorPos(5, 6)
  775. term.write("Delete? Yes [ No ]")
  776. end
  777.  
  778. local event, key = os.pullEvent("key")
  779.  
  780. if key == 205 and nSelected == 1 then nSelected = nSelected+1
  781. elseif key == 203 and nSelected == 2 then nSelected = nSelected-1
  782.  
  783. elseif key == 28 and nSelected == 1 then
  784. local tContacts = loadContacts()
  785.  
  786. for i=1, #tContacts do
  787. if nSelected == i then fs.delete("Mail/Contacts/"..tContacts[i].name) end
  788. end
  789. break
  790. elseif key == 28 and nSelected == 2 then break
  791. end
  792. end
  793. end
  794. end
  795. end
  796.  
  797. while true do
  798. printMailMenu()
  799.  
  800. event, key = os.pullEvent("key")
  801.  
  802. if key == 200 and selection > 1 then selection = selection-1
  803. elseif key == 208 and selection < 4 then selection = selection+1
  804.  
  805. elseif key == 28 and selection == 1 then composeMail(); sMenuState = "main"; break
  806. elseif key == 28 and selection == 2 then readMail(); sMenuState = "main"; break
  807. elseif key == 28 and selection == 3 then contacts(); selection = 1; term.setCursorPos(4, 3); term.write(string.rep(" ", 17)); clearCenter();
  808. elseif key == 28 and selection == 4 then selection = 4; sMenuState = "main"; break
  809. end
  810. end
  811. end
  812.  
  813. function newMessage(nSender, sContents)
  814. rPrint(2, "Mail: "..nMailCount.."*")
  815. sMenuState = "newMessage"
  816. local nSelect = 1
  817. local bReading = false -- This is to handle whether or not we should print the reception menu
  818. clearCenter()
  819.  
  820. local function printMessageMenu()
  821. cPrint(5, "*****************")
  822. cPrint(6, "* New Message *")
  823. cPrint(7, "*****************")
  824. if nSelect == 1 then cPrint(8, "*[ Read ] Exit *")
  825. else cPrint(8, "* Read [ Exit ]*") end
  826. cPrint(9, "*****************")
  827. end
  828.  
  829. while true do
  830. if not bReading then printMessageMenu() end
  831. local event, key = os.pullEvent("key")
  832.  
  833. if key == 205 then nSelect = nSelect+1
  834. elseif key == 203 then nSelect = nSelect-1
  835.  
  836. elseif key == 28 and nSelect == 1 then
  837. nMailCount = nMailCount-1
  838. bReading = true
  839. clearCenter()
  840. term.setCursorPos(4, 5); term.write("From: "..nSender)
  841. term.setCursorPos(4, 6); term.write("******"..string.rep("*", string.len(nSender)))
  842.  
  843. term.setCursorPos(4, 7)
  844. if string.len(sContents) > 42 then
  845. local sContentsLine1 = string.sub(sContents, 1, 42) -- Split the message into two lines if it is greater than 38
  846. local sContentsLine2 = string.sub(sContents, 43, string.len(sContents))
  847.  
  848. term.write(sContentsLine1)
  849. term.setCursorPos(4, 9)
  850. term.write(sContentsLine2)
  851. else
  852. term.write(sContents)
  853. end
  854. break -- Print the message then end
  855. elseif key == 28 and nSelect == 2 then
  856. clearCenter()
  857. sMenuState = "main"
  858. return
  859. end
  860. end
  861.  
  862. while true do
  863. cPrint(9, "**********")
  864. cPrint(10, "*[ Exit ]*")
  865. cPrint(11, "**********")
  866.  
  867. local event, key = os.pullEvent("key")
  868.  
  869. if key == 28 then sMenuState = "main"; break end
  870. end
  871. end
  872.  
  873. function readMail()
  874. local sFileOpen = ""
  875. sMenuState = "archive"
  876. clearCenter()
  877.  
  878. if #(fs.list("Mail"))-1 == 0 then
  879. cPrint(6, "***************")
  880. cPrint(7, "* No messages *")
  881. cPrint(8, "***************")
  882. sleep(1.3)
  883. clearCenter()
  884. cPrint(12, " ") -- Clear line 12
  885. return
  886. end
  887.  
  888. term.setCursorPos(4, 5); term.write(string.rep("*", screenWidth-6))
  889. local y = 6
  890. for i=1, screenHeight - 13 do
  891. term.setCursorPos(4, y); term.write("*"..string.rep(" ", screenWidth-8).."*")
  892. y = y+1
  893. end
  894. term.setCursorPos(4, 11); term.write(string.rep("*", screenWidth-6))
  895.  
  896. local tMessages = fs.list("Mail")
  897. local nSelections = #tMessages -- How many selections for mail we have
  898. local nSelected = 1
  899.  
  900. local function clearMessageRectangle()
  901. local y = 6
  902. for i=1, 5 do
  903. term.setCursorPos(5, y); term.write(string.rep(" ", screenWidth - 8))
  904. y = y+1
  905. end
  906. end
  907.  
  908. local function printMessages()
  909. term.setCursorPos(5, 13); term.write(string.rep(" ", screenWidth - (string.len("*********************")+2)))
  910. term.setCursorPos(screenWidth - (string.len("*********************")+2), 13)
  911. term.write("*********************")
  912. term.setCursorPos(screenWidth - (string.len("* Backspace to exit *")+2), 12)
  913. term.write("* Backspace to exit *")
  914.  
  915. tMessages = fs.list("Mail")
  916. for i=1, #tMessages do
  917. if tMessages[i] == "Contacts" then table.remove(tMessages, i) end
  918. end -- Remove the 'Contacts' directory from the list
  919.  
  920. term.setCursorPos(4, 5); term.write(string.rep("*", screenWidth-6))
  921. local y = 6
  922. for i=1, screenHeight - 13 do
  923. term.setCursorPos(4, y); term.write("*"..string.rep(" ", screenWidth-8).."*")
  924. y = y+1
  925. end
  926. term.setCursorPos(4, 11); term.write(string.rep("*", screenWidth-6))
  927.  
  928.  
  929. local recX = 6
  930. local recY = 6 -- Positions to hold the x and y coords of where we'll draw the mail
  931. for i=1, #tMessages do
  932. if recX > 41 or recX+string.len(tMessages[i]) > 41 then
  933. recY = recY+2
  934. recX = 6
  935. end
  936. if recY >= 10 then break end
  937.  
  938. if nSelected == i then recX = recX-1 end
  939. term.setCursorPos(recX, recY)
  940. if nSelected == i then term.write("["..tMessages[i].."]"); recX = recX+1 end
  941. if nSelected ~= i then term.write(tMessages[i]) end
  942.  
  943. if nSelected == i then
  944. recX = recX + string.len(tMessages[i]) + 2 -- The 2 is for the spaces between the options
  945. else recX = recX + string.len(tMessages[i]) + 2 end
  946. end
  947. end
  948.  
  949. while true do
  950. cPrint(12, " ") -- Clear the last line from the 'return' or 'delete' menu from reading a message
  951. printMessages()
  952.  
  953. local event, key = os.pullEvent("key")
  954.  
  955. if key == 205 and nSelected < #tMessages then nSelected = nSelected+1
  956. elseif key == 203 and nSelected > 1 then nSelected = nSelected-1
  957.  
  958. elseif key == 14 then clearCenter(); term.setCursorPos(5, 12); term.write(string.rep(" ", screenWidth - 7)); term.setCursorPos(5, 13); term.write(string.rep(" ", screenWidth - 7)); cPrint(13, " Computer Craft OS File Browser "); return
  959. elseif key == 28 then
  960. clearCenter()
  961. local sFileOpen = "Mail/"..tMessages[nSelected]
  962. local file = fs.open("Mail/"..tMessages[nSelected], "r")
  963. local nSender = file.readLine()
  964. local sMessage = file.readAll(); -- We'll be using the File Contents as the message to read
  965. file.close()
  966.  
  967. sMessage = string.gsub(sMessage, tostring(nSender), "") -- Get the message string without the sender
  968. if string.len(sMessage) > 38 then
  969. local sMessageLine1 = string.sub(sMessage, 1, 19)
  970. local sMessageLine2 = string.sub(sMessage, 20, 38)
  971. end
  972.  
  973. term.setCursorPos(4, 3); term.write("From: "..nSender)
  974. term.setCursorPos(4, 4); term.write("******"..string.rep("*", string.len(tostring(nSender))))
  975. term.setCursorPos(4, 5)
  976. if sMessageLine1 ~= nil then
  977. term.write(sMessageLine1)
  978. term.setCursorPos(4, 6)
  979. term.write(sMessageLine2)
  980. else
  981. term.write(sMessage)
  982. end
  983.  
  984. nSelected = 1 -- Reset the selection for the 'back' or 'delete' option
  985. term.setCursorPos(5, 12); term.write(string.rep(" ", screenWidth - 7)); term.setCursorPos(5, 13); term.write(string.rep(" ", screenWidth - 7))
  986. while true do
  987. cPrint(10, "*********************")
  988. if nSelected == 1 then cPrint(11, "*[ Return ] Delete *")
  989. else cPrint(11, "* Return [ Delete ]*") end
  990. cPrint(12, "*********************")
  991. --
  992.  
  993. local event, key = os.pullEvent("key")
  994.  
  995. if key == 205 and nSelected == 1 then nSelected = 2
  996. elseif key == 203 and nSelected == 2 then nSelected = 1
  997.  
  998. elseif key == 28 and nSelected == 1 then term.setCursorPos(4, 3); term.write(string.rep(" ", string.len("From: "..nSender))); term.setCursorPos(4, 4); term.write(string.rep(" ", string.len("From: "..nSender))) break
  999. elseif key == 28 and nSelected == 2 then
  1000. fs.delete(sFileOpen)
  1001. sFileOpened = ""
  1002. nSelected = 1
  1003. term.setCursorPos(4, 3); term.write(string.rep(" ", string.len("From: "..nSender)))
  1004. term.setCursorPos(4, 4); term.write(string.rep(" ", string.len("From: "..nSender)))
  1005. break
  1006. end
  1007. end
  1008. end
  1009. end
  1010. end
  1011. -------------------------
  1012.  
  1013.  
  1014. -- Filbrowser --
  1015. function fileBrowser()
  1016. sMenuState = "browseing"
  1017. clearCenter()
  1018.  
  1019. local scroll = 0
  1020. local y = 0
  1021. local sObjectName = ""
  1022. local sObjectType = ""
  1023. local nObjectHeight = 0
  1024.  
  1025. local nSelect = 1
  1026. local tFiles = {}
  1027.  
  1028. local function printOptionMenu()
  1029. local previousSelection = nSelect
  1030. nSelect = 1
  1031.  
  1032. while true do
  1033. term.setCursorPos(6, 8); term.write(string.rep(" ", 40))
  1034. if nSelect == 1 and sObjectType == "File" then cPrint(8, "[Run] Edit Delete Exit ")
  1035. elseif nSelect == 2 and sObjectType == "File" then cPrint(8, " Run [Edit] Delete Exit ")
  1036. elseif nSelect == 3 and sObjectType == "File" then cPrint(8, " Run Edit [Delete] Exit ")
  1037. elseif nSelect == 4 and sObjectType == "File" then cPrint(8, " Run Edit Delete [Exit]")
  1038. end
  1039.  
  1040. local event, key = os.pullEvent("key")
  1041.  
  1042. if key == 205 and nSelect < 4 then nSelect = nSelect+1
  1043. elseif key == 203 and nSelect > 1 then nSelect = nSelect-1
  1044. elseif key == 14 or key == 28 and nSelect == 4 then nSelect = previousSelection; return false
  1045. elseif nSelect == 1 and key == 28 then clear(); shell.run(sObjectName); sMenuState = "main"; return true
  1046. elseif nSelect == 2 and key == 28 then clear(); shell.run("edit", sObjectName); sMenuState = "main"; return true
  1047. elseif nSelect == 3 and key == 28 then fs.delete(shell.dir().."/"..sObjectName); sMenuState = "main"; return true
  1048. end
  1049. end
  1050. end
  1051.  
  1052. local function printFileContainer()
  1053. term.setCursorPos(4, 5); term.write(string.rep("*", screenWidth-6))
  1054. local y = 6
  1055. for i=1, screenHeight - 13 do
  1056. term.setCursorPos(4, y); term.write("*"..string.rep(" ", screenWidth-8).."*")
  1057. y = y+1
  1058. end
  1059. term.setCursorPos(4, 11); term.write(string.rep("*", screenWidth-6))
  1060. end
  1061.  
  1062. local function printFiles()
  1063. local sDir = shell.dir()
  1064. clearCenter()
  1065. printFileContainer() -- This is the rectangle we'll be displaying the options in
  1066. y = 6
  1067. tFiles = fs.list( sDir )
  1068.  
  1069.  
  1070. for i=1+scroll, #tFiles do
  1071. if i == nSelect then nObjectHeight = y end
  1072. sObjectName = tostring(shell.dir()).."/"..tFiles[nSelect]
  1073. if fs.isDir(tostring(shell.dir()).."/"..tFiles[nSelect]) then sObjectType = "Dir"
  1074. else sObjectType = "File"
  1075. end
  1076.  
  1077. term.setCursorPos(6, y)
  1078.  
  1079. if nSelect == i then term.write("["..tFiles[i].."]")
  1080. else term.write(" "..tFiles[i].." ") end
  1081.  
  1082. if fs.isDir(tostring(shell.dir()).."/"..tFiles[i]) then term.setCursorPos(42, y); term.write("D ")
  1083. else term.setCursorPos(42, y); term.write("F ") end
  1084.  
  1085. y = y+1
  1086. if y == 11 then break end
  1087. end
  1088. end
  1089.  
  1090. while true do
  1091. printFiles()
  1092.  
  1093. local event, key = os.pullEvent("key")
  1094.  
  1095. if key == 200 and nSelect == 1 then nSelect = 1
  1096. elseif key == 208 and nSelect == #tFiles then nSelect = #tFiles
  1097.  
  1098. elseif key == 208 and nSelect < #tFiles then
  1099. if nSelect >= 5 and scroll < #tFiles then scroll = scroll+1; nSelect = nSelect+1
  1100. else nSelect = nSelect+1 end
  1101. elseif key == 200 and nSelect > 1 then
  1102. if nSelect >= 5 and scroll > 0 then scroll = scroll-1; nSelect = nSelect-1
  1103. else nSelect = nSelect-1 end
  1104.  
  1105. elseif key == 28 and sObjectType == "File" then
  1106. if printOptionMenu() then return end
  1107. elseif key == 28 and sObjectType == "Dir" then shell.setDir(sObjectName); scroll = 0; nSelect = 1
  1108. elseif key == 14 and shell.dir() ~= "" then shell.run("cd", ".."); scroll = 0; nSelect = 1
  1109. elseif key == 14 and shell.dir() == "/" or shell.dir() == "" then sMenuState = "main"; break
  1110. end
  1111. end
  1112. end
  1113. ----------------
  1114.  
  1115.  
  1116. -- IRC Client --
  1117. function IRC_Client()
  1118. sMenuState = "irc"
  1119.  
  1120. -- VARS --
  1121. local sServerName = ""
  1122. local nServerID = 0
  1123. local bConnected = false
  1124.  
  1125. local sUserName = ""
  1126. local sText = ""
  1127.  
  1128. nConversationY = 3
  1129. ----------
  1130.  
  1131. -- Helper local functions --
  1132. local function newReadIRC( _charLimit, _ReplaceChar) -- The filter can either be a 1, 0, or nil. 1 is Numbers only, 0 is letters only, and nil is both
  1133. local sMessage = ""
  1134. term.setCursorBlink(true)
  1135. local originalCursorX, originalCursorY = term.getCursorPos()
  1136.  
  1137. while true do
  1138. local cursorX, cursorY = term.getCursorPos()
  1139. local event, p1, p2 = os.pullEvent()
  1140.  
  1141. if _charLimit ~= nil then
  1142. if string.len(sMessage) == _charLimit then term.setCursorBlink(false); return sMessage end
  1143. end
  1144.  
  1145. if event == "char" then sMessage = sMessage..p1
  1146. --[[elseif event == "key" then -- The escape key has keyID 1 so: 0 = keyID: 11, 1 = keyID: 2, 2 = keyID : 3 etc etc....
  1147. if p1 == 11 or p1 == 2 or p1 == 3 or p1 == 4 or p1 == 5 or p1 == 6 or p1 == 7 or p1 == 8 or p1 == 9 or p1 == 10 then
  1148. -- 0 1 2 3 4 5 6 7 8 9
  1149. sMessage = sMessage..(p1-1)
  1150. end--]]
  1151. end
  1152.  
  1153. if event == "key" and p1 == 28 then
  1154. term.setCursorBlink(false)
  1155. term.setCursorPos(1, screenHeight)
  1156. term.write(string.rep(" ", screenWidth))
  1157. return sMessage
  1158. end-- Enter key; end the loop and let's see the string
  1159.  
  1160. if event == "key" and p1 == 14 then -- Backspace...
  1161. sMessage = string.sub(sMessage, 1, string.len(sMessage)-1)
  1162. -- Set our message to the substring of the first charcter
  1163. -- To the length of the message minus 1 to achieve one less letter.
  1164.  
  1165. term.setCursorPos(originalCursorX, cursorY)
  1166. term.write(sMessage.." ") -- Adding this empty space clears the removed character from the line, but may pose future issues
  1167. end
  1168.  
  1169. if event == "rednet_message" and p1 == nServerID then
  1170. if nConversationY == 10 then
  1171. for i=3, 14 do
  1172. term.setCursorPos(3, i); term.write(string.rep(" ", screenWidth-4))
  1173. end
  1174.  
  1175. term.setCursorPos(3, 2); term.write(sServerName..":")
  1176. term.setCursorPos(5, screenHeight-1)
  1177. nConversationY = 3
  1178. end
  1179.  
  1180. if p1 == nServerID and p2 == "dlskjfiejdlijfklsdj" then bConnected = false; return nil end
  1181. term.setCursorPos(3, nConversationY); term.write(p2)
  1182. nConversationY = nConversationY+1
  1183. term.setCursorPos(string.len(sMessage)+6, screenHeight)
  1184. end
  1185.  
  1186. term.setCursorPos(originalCursorX, cursorY); term.write(string.rep(" ", string.len(sMessage)))
  1187. -- Clear the previous line just in case we get a new line
  1188. -- Now write the message on the new line
  1189. if _ReplaceChar ~= nil then
  1190. term.setCursorPos(originalCursorX, cursorY)
  1191. term.write(string.rep( _ReplaceChar, string.len(sMessage) ))
  1192. else
  1193. term.setCursorPos(originalCursorX, cursorY)
  1194. term.write(sMessage)
  1195. end
  1196. end
  1197. end
  1198. ----------------------
  1199.  
  1200. -- Input related local functions --
  1201. local function getInput()
  1202. cPrint(4, "IRC Version: Beta 1.0")
  1203. cPrint(5, "Server ID: ")
  1204. cPrint(6, " Username: ")
  1205.  
  1206. rPrint(17, "Common channels: 146, 174, 175, 176, 177*")
  1207.  
  1208. term.setCursorPos(screenWidth/2 - string.len("Server ID: ")/2 + string.len("Server ID: "), 5)
  1209. nServerID = tonumber(newRead(5))
  1210.  
  1211. term.setCursorPos(screenWidth/2 - string.len(" Username: ")/2 + string.len(" Username: "), 6)
  1212. sUserName = newRead(14)
  1213. end
  1214. -----------------------------
  1215.  
  1216. -- Networking related local functions --
  1217. local function connectToServer()
  1218. if bConnected == true then return nil end
  1219.  
  1220. if nServerID ~= nil then
  1221. rednet.send(tonumber(nServerID), "dlsk;fje3ijoidsjfl")
  1222.  
  1223. sender, message = rednet.receive(0.2)
  1224.  
  1225. if sender == nServerID and message == "a;sodifu39798d0f3" then
  1226. rednet.send(tonumber(nServerID), tostring(sUserName))
  1227.  
  1228. sender, message = rednet.receive(0.1)
  1229.  
  1230. if sender == nServerID and message == "ifjdslfije" then
  1231. bConnected = true
  1232.  
  1233. sender, message = rednet.receive(0.2)
  1234.  
  1235. if sender == nServerID then sServerName = message end
  1236. end
  1237. end
  1238. else os.shutdown() end
  1239. end
  1240.  
  1241. local function sendMessage( _sMessage )
  1242. rednet.send( tonumber(nServerID), _sMessage )
  1243. end
  1244. ----------------------------------
  1245.  
  1246. printBorder()
  1247. getInput()
  1248. connectToServer()
  1249. clear()
  1250. printBorder()
  1251. term.setCursorPos(3, 2); term.write(sServerName..":")
  1252. term.setCursorPos(3, screenHeight-1); term.write("> ")
  1253.  
  1254. while bConnected do
  1255. if nConversationY == 10 then
  1256. for i=3, 14 do
  1257. term.setCursorPos(3, i); term.write(string.rep(" ", screenWidth-4))
  1258. end
  1259.  
  1260. term.setCursorPos(3, 2); term.write(sServerName..":")
  1261. term.setCursorPos(5, screenHeight-1)
  1262. nConversationY = 3
  1263. end
  1264.  
  1265. sText = newReadIRC(screenWidth-7) -- This will be our disconnection message: dslifj
  1266. if sText == "!exit" then clear(); sMenuState = "main"; break end
  1267. if sText == nil then term.setCursorBlink(false); sMenuState = "main"; break end
  1268.  
  1269. if sText ~= sUserName then sendMessage(sText)
  1270. else nConversationY = nConversationY-1 end
  1271. sText = ""
  1272. term.setCursorPos(3, screenHeight-1); term.write(string.rep(" ", screenWidth-4))
  1273. term.setCursorPos(3, screenHeight-1); term.write("> ")
  1274.  
  1275. term.setCursorPos(2, screenHeight); term.write(string.rep("*", screenWidth-2))
  1276. term.setCursorPos(5, screenHeight-1)
  1277. end
  1278. clear()
  1279. sMenuState = "main"
  1280. end
  1281. ---------------------
  1282.  
  1283.  
  1284. -- Account --
  1285. function editAccount()
  1286. sMenuState = "account"
  1287. local nSelect = 1
  1288.  
  1289. clearCenter()
  1290. local function printInfoContainer()
  1291. term.setCursorPos(4, 5); term.write(string.rep("*", screenWidth-6))
  1292. local y = 6
  1293. for i=1, screenHeight - 13 do
  1294. term.setCursorPos(4, y); term.write("*"..string.rep(" ", screenWidth-8).."*")
  1295. y = y+1
  1296. end
  1297. term.setCursorPos(4, 11); term.write(string.rep("*", screenWidth-6))
  1298. end
  1299.  
  1300. printInfoContainer()
  1301. while true do
  1302. if nSelect == 3 then sMenuState = "main"; break end
  1303.  
  1304. term.setCursorPos(5, 7); term.write("Username: "..sUserName)
  1305. term.setCursorPos(5, 8); term.write("Password: "..string.rep("*", string.len(sPassword)))
  1306.  
  1307. if nSelect == 1 then term.setCursorPos((screenWidth-6)-(string.len("[ Change ]*")-4), 7); term.write("[ Change ]*")
  1308. else term.setCursorPos((screenWidth-6)-(string.len("[ Change ]*")-4), 7); term.write(" Change *") end
  1309.  
  1310. if nSelect == 2 then term.setCursorPos((screenWidth-6)-(string.len("[ Change ]*")-4), 8); term.write("[ Change ]*")
  1311. else term.setCursorPos((screenWidth-6)-(string.len("[ Change ]*")-4), 8); term.write(" Change *") end
  1312.  
  1313. local event, key = os.pullEvent("key")
  1314.  
  1315. if key == 208 and nSelect == 1 then nSelect = nSelect+1
  1316. elseif key == 200 and nSelect == 2 then nSelect = nSelect-1
  1317.  
  1318. elseif key == 28 and nSelect == 1 then
  1319. term.setCursorPos(5, 7); term.write(string.rep(" ", screenWidth-8))
  1320. term.setCursorPos(5, 7); term.write("New Username: ")
  1321. sUserName = newRead(14)
  1322. term.setCursorPos(5, 7); term.write(string.rep(" ", screenWidth-8))
  1323.  
  1324. local file = fs.open("User/"..os.getComputerID().."/.info", "w")
  1325. file.write(sUserName.."n"..sPassword)
  1326. file.close()
  1327. elseif key == 28 and nSelect == 2 then
  1328. term.setCursorPos(5, 8); term.write(string.rep(" ", screenWidth-8))
  1329. term.setCursorPos(5, 8); term.write("Old Password: ")
  1330. local sCheckPassword = newRead(14, "*")
  1331.  
  1332. if sCheckPassword == sPassword then
  1333. term.setCursorPos(5, 8); term.write(string.rep(" ", screenWidth-8))
  1334. term.setCursorPos(5, 8); term.write("New Password: ")
  1335. sPassword = newRead(14, "*")
  1336.  
  1337. local file = fs.open("User/"..os.getComputerID().."/.info", "w")
  1338. file.write(sUserName.."n"..sPassword)
  1339. file.close()
  1340. end
  1341. term.setCursorPos(5, 8); term.write(string.rep(" ", screenWidth-8))
  1342. elseif key == 14 then nSelect = 3
  1343. end
  1344. end
  1345. end
  1346. -------------
  1347.  
  1348. function printError()
  1349. sMenuState = "perms"; clearCenter()
  1350. cPrint(6, "*********************")
  1351. cPrint(7, "* Restricted Access *")
  1352. cPrint(8, "*********************")
  1353. sleep(2)
  1354. sMenuState = "main"
  1355. end
  1356.  
  1357.  
  1358.  
  1359. clear()
  1360. getKey() -- b8v2a6b8i1e2j8g91
  1361. clear()
  1362. printInstallation()
  1363. clear()
  1364. checkUserInformation()
  1365. getUserInformation()
  1366. handleLogin()
  1367.  
  1368. if bLogin then
  1369. if checkVersion() then
  1370. sMenuState = "updateScreen"
  1371. clear()
  1372. printBorder()
  1373. rPrint(17, "Cannon OS Version: "..VERSION.."*")
  1374. cPrint(6, "********************")
  1375. cPrint(7, "* Update Available *")
  1376. cPrint(8, "********************")
  1377.  
  1378. local select = 1
  1379. while true do
  1380. if select == 1 then cPrint(9, "* [ Yes ] No *")
  1381. else cPrint(9, "* Yes [ No ] *")
  1382. end
  1383. cPrint(10, "********************")
  1384.  
  1385. local event, key = os.pullEvent("key")
  1386.  
  1387. if key == 205 and select == 1 then select = 2
  1388. elseif key == 203 and select == 2 then select = 1
  1389.  
  1390. elseif key == 28 and select == 1 then clear(); printBorder(); rPrint(17, "Cannon OS Version: "..VERSION.."*"); fs.delete("SYSTEM"); fs.delete("User"); term.setCursorPos(screenWidth/2-string.len("Updating...")/2, 9); textutils.slowPrint("Updating..."); updateSelf(); shell.run("startup")
  1391. elseif key == 28 and select == 2 then sMenuState = "main"; clearCenter(); break
  1392. end
  1393. end
  1394. end
  1395. end
  1396.  
  1397. -- Main OS Loop --
  1398. while true do
  1399. clear()
  1400. nMailCount = #(fs.list("Mail"))-1 -- -1 To eliminate the 'Contacts' directory from the list
  1401. printMainMenu()
  1402.  
  1403. event, key, p2 = os.pullEvent() -- Key will be p1, laziness has struck again
  1404.  
  1405. if event == "key" and key == 205 and selection < 6 and selection ~= 3 then selection = selection+1
  1406. elseif event == "key" and key == 203 and selection > 1 and selection ~= 4 then selection = selection-1
  1407. elseif event == "key" and key == 208 and selection < 6 and selection+3 <= 6 then selection = selection+3
  1408. elseif event == "key" and key == 200 and selection > 1 and selection-3 >= 1 then selection = selection-3
  1409.  
  1410. elseif event == "key" and key == 28 and selection == 6 then
  1411. clear(); printBorder(); rPrint(17, "Cannon OS Version: "..VERSION.."*"); term.setCursorPos(screenWidth/2-string.len("Updating...")/2, 9); textutils.slowPrint("Updating...")
  1412. if not updateSelf() then cPrint(9, "Update Failed"); sleep(1.3); shell.run("startup")
  1413. else fs.delete("SYSTEM"); fs.delete("User"); cPrint(9, "Update Successfull"); sleep(1.3); shell.run("startup")
  1414. end
  1415. elseif event == "key" and key == 28 and selection == 2 and bAdmin then clear(); shell.run("shell")-- If exit to Craft OS
  1416. elseif event == "key" and key == 28 and selection == 2 and not bAdmin then printError()
  1417.  
  1418. elseif event == "key" and key == 28 and selection == 4 and bAdmin then mailMenu()
  1419. elseif event == "key" and key == 28 and selection == 4 and not bAdmin then printError()
  1420.  
  1421. elseif event == "key" and key == 28 and selection == 1 and bAdmin then fileBrowser()
  1422. elseif event == "key" and key == 28 and selection == 1 and not bAdmin then printError()
  1423.  
  1424. elseif event == "key" and key == 28 and selection == 3 then clear(); IRC_Client()
  1425.  
  1426. elseif event == "key" and key == 28 and selection == 5 and bAdmin then editAccount()
  1427. elseif event == "key" and key == 28 and selection == 5 and not bAdmin then printError()
  1428.  
  1429. elseif event == "rednet_message" then
  1430. if string.find( p2, ";alkdjien") then
  1431. p2 = string.sub( p2, string.len(";alkdjien"), string.len( p2 ))
  1432. p2 = string.sub( p2, 3, string.len( p2 )) -- 3 to remove the n from the message
  1433. local file = fs.open("Mail/message"..#(fs.list("Mail"))+1, "w")
  1434. file.writeLine(key)
  1435. file.writeLine(p2)
  1436. file.close()
  1437.  
  1438. nMailCount = nMailCount+1
  1439. newMessage(key, p2) -- Key being the senderID and p2 being the message received
  1440. end
  1441. elseif event == "reboot" then selection = 1; sMenuState = "logout"; printLogout()
  1442. end
  1443. end
  1444. ------------------
  1445.  
  1446. os.pullEvent = oldpullEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement