SuicidalSTDz

EnderOS v2.2

Feb 2nd, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.32 KB | None | 0 0
  1. --License:
  2. --The code of "EnderOS" in any form is intellectual
  3. --property of SuicidalSTDz. You may not reproduce,
  4. --redistribute, or modify it in any way!
  5.  
  6. --This OS stores User information in a hashed form. Making "hackers" tremble in fear >:) Not really...
  7. --The hash that EnderOS uses is Sha-256 and makes storage safer :)
  8.  
  9.  
  10.  
  11. os.pullEvent = os.pullEventRaw
  12. term.clear()
  13. term.setCursorPos(1,1)
  14. function sha256(msg)
  15. function band(int1, int2, int3, ...)
  16. local ret =
  17. ((int1%0x00000002>=0x00000001 and int2%0x00000002>=0x00000001 and 0x00000001) or 0)+
  18. ((int1%0x00000004>=0x00000002 and int2%0x00000004>=0x00000002 and 0x00000002) or 0)+
  19. ((int1%0x00000008>=0x00000004 and int2%0x00000008>=0x00000004 and 0x00000004) or 0)+
  20. ((int1%0x00000010>=0x00000008 and int2%0x00000010>=0x00000008 and 0x00000008) or 0)+
  21. ((int1%0x00000020>=0x00000010 and int2%0x00000020>=0x00000010 and 0x00000010) or 0)+
  22. ((int1%0x00000040>=0x00000020 and int2%0x00000040>=0x00000020 and 0x00000020) or 0)+
  23. ((int1%0x00000080>=0x00000040 and int2%0x00000080>=0x00000040 and 0x00000040) or 0)+
  24. ((int1%0x00000100>=0x00000080 and int2%0x00000100>=0x00000080 and 0x00000080) or 0)+
  25. ((int1%0x00000200>=0x00000100 and int2%0x00000200>=0x00000100 and 0x00000100) or 0)+
  26. ((int1%0x00000400>=0x00000200 and int2%0x00000400>=0x00000200 and 0x00000200) or 0)+
  27. ((int1%0x00000800>=0x00000400 and int2%0x00000800>=0x00000400 and 0x00000400) or 0)+
  28. ((int1%0x00001000>=0x00000800 and int2%0x00001000>=0x00000800 and 0x00000800) or 0)+
  29. ((int1%0x00002000>=0x00001000 and int2%0x00002000>=0x00001000 and 0x00001000) or 0)+
  30. ((int1%0x00004000>=0x00002000 and int2%0x00004000>=0x00002000 and 0x00002000) or 0)+
  31. ((int1%0x00008000>=0x00004000 and int2%0x00008000>=0x00004000 and 0x00004000) or 0)+
  32. ((int1%0x00010000>=0x00008000 and int2%0x00010000>=0x00008000 and 0x00008000) or 0)+
  33. ((int1%0x00020000>=0x00010000 and int2%0x00020000>=0x00010000 and 0x00010000) or 0)+
  34. ((int1%0x00040000>=0x00020000 and int2%0x00040000>=0x00020000 and 0x00020000) or 0)+
  35. ((int1%0x00080000>=0x00040000 and int2%0x00080000>=0x00040000 and 0x00040000) or 0)+
  36. ((int1%0x00100000>=0x00080000 and int2%0x00100000>=0x00080000 and 0x00080000) or 0)+
  37. ((int1%0x00200000>=0x00100000 and int2%0x00200000>=0x00100000 and 0x00100000) or 0)+
  38. ((int1%0x00400000>=0x00200000 and int2%0x00400000>=0x00200000 and 0x00200000) or 0)+
  39. ((int1%0x00800000>=0x00400000 and int2%0x00800000>=0x00400000 and 0x00400000) or 0)+
  40. ((int1%0x01000000>=0x00800000 and int2%0x01000000>=0x00800000 and 0x00800000) or 0)+
  41. ((int1%0x02000000>=0x01000000 and int2%0x02000000>=0x01000000 and 0x01000000) or 0)+
  42. ((int1%0x04000000>=0x02000000 and int2%0x04000000>=0x02000000 and 0x02000000) or 0)+
  43. ((int1%0x08000000>=0x04000000 and int2%0x08000000>=0x04000000 and 0x04000000) or 0)+
  44. ((int1%0x10000000>=0x08000000 and int2%0x10000000>=0x08000000 and 0x08000000) or 0)+
  45. ((int1%0x20000000>=0x10000000 and int2%0x20000000>=0x10000000 and 0x10000000) or 0)+
  46. ((int1%0x40000000>=0x20000000 and int2%0x40000000>=0x20000000 and 0x20000000) or 0)+
  47. ((int1%0x80000000>=0x40000000 and int2%0x80000000>=0x40000000 and 0x40000000) or 0)+
  48. ((int1>=0x80000000 and int2>=0x80000000 and 0x80000000) or 0)
  49.  
  50. return (int3 and band(ret, int3, ...)) or ret
  51. end
  52.  
  53. local function bxor(int1, int2, int3, ...)
  54. local ret =
  55. ((int1%0x00000002>=0x00000001 ~= (int2%0x00000002>=0x00000001) and 0x00000001) or 0)+
  56. ((int1%0x00000004>=0x00000002 ~= (int2%0x00000004>=0x00000002) and 0x00000002) or 0)+
  57. ((int1%0x00000008>=0x00000004 ~= (int2%0x00000008>=0x00000004) and 0x00000004) or 0)+
  58. ((int1%0x00000010>=0x00000008 ~= (int2%0x00000010>=0x00000008) and 0x00000008) or 0)+
  59. ((int1%0x00000020>=0x00000010 ~= (int2%0x00000020>=0x00000010) and 0x00000010) or 0)+
  60. ((int1%0x00000040>=0x00000020 ~= (int2%0x00000040>=0x00000020) and 0x00000020) or 0)+
  61. ((int1%0x00000080>=0x00000040 ~= (int2%0x00000080>=0x00000040) and 0x00000040) or 0)+
  62. ((int1%0x00000100>=0x00000080 ~= (int2%0x00000100>=0x00000080) and 0x00000080) or 0)+
  63. ((int1%0x00000200>=0x00000100 ~= (int2%0x00000200>=0x00000100) and 0x00000100) or 0)+
  64. ((int1%0x00000400>=0x00000200 ~= (int2%0x00000400>=0x00000200) and 0x00000200) or 0)+
  65. ((int1%0x00000800>=0x00000400 ~= (int2%0x00000800>=0x00000400) and 0x00000400) or 0)+
  66. ((int1%0x00001000>=0x00000800 ~= (int2%0x00001000>=0x00000800) and 0x00000800) or 0)+
  67. ((int1%0x00002000>=0x00001000 ~= (int2%0x00002000>=0x00001000) and 0x00001000) or 0)+
  68. ((int1%0x00004000>=0x00002000 ~= (int2%0x00004000>=0x00002000) and 0x00002000) or 0)+
  69. ((int1%0x00008000>=0x00004000 ~= (int2%0x00008000>=0x00004000) and 0x00004000) or 0)+
  70. ((int1%0x00010000>=0x00008000 ~= (int2%0x00010000>=0x00008000) and 0x00008000) or 0)+
  71. ((int1%0x00020000>=0x00010000 ~= (int2%0x00020000>=0x00010000) and 0x00010000) or 0)+
  72. ((int1%0x00040000>=0x00020000 ~= (int2%0x00040000>=0x00020000) and 0x00020000) or 0)+
  73. ((int1%0x00080000>=0x00040000 ~= (int2%0x00080000>=0x00040000) and 0x00040000) or 0)+
  74. ((int1%0x00100000>=0x00080000 ~= (int2%0x00100000>=0x00080000) and 0x00080000) or 0)+
  75. ((int1%0x00200000>=0x00100000 ~= (int2%0x00200000>=0x00100000) and 0x00100000) or 0)+
  76. ((int1%0x00400000>=0x00200000 ~= (int2%0x00400000>=0x00200000) and 0x00200000) or 0)+
  77. ((int1%0x00800000>=0x00400000 ~= (int2%0x00800000>=0x00400000) and 0x00400000) or 0)+
  78. ((int1%0x01000000>=0x00800000 ~= (int2%0x01000000>=0x00800000) and 0x00800000) or 0)+
  79. ((int1%0x02000000>=0x01000000 ~= (int2%0x02000000>=0x01000000) and 0x01000000) or 0)+
  80. ((int1%0x04000000>=0x02000000 ~= (int2%0x04000000>=0x02000000) and 0x02000000) or 0)+
  81. ((int1%0x08000000>=0x04000000 ~= (int2%0x08000000>=0x04000000) and 0x04000000) or 0)+
  82. ((int1%0x10000000>=0x08000000 ~= (int2%0x10000000>=0x08000000) and 0x08000000) or 0)+
  83. ((int1%0x20000000>=0x10000000 ~= (int2%0x20000000>=0x10000000) and 0x10000000) or 0)+
  84. ((int1%0x40000000>=0x20000000 ~= (int2%0x40000000>=0x20000000) and 0x20000000) or 0)+
  85. ((int1%0x80000000>=0x40000000 ~= (int2%0x80000000>=0x40000000) and 0x40000000) or 0)+
  86. ((int1>=0x80000000 ~= (int2>=0x80000000) and 0x80000000) or 0)
  87.  
  88. return (int3 and bxor(ret, int3, ...)) or ret
  89. end
  90.  
  91. local function bnot(int)
  92. return 4294967295 - int
  93. end
  94.  
  95. local function rshift(int, by)
  96. local shifted = int / (2 ^ by)
  97. return shifted - shifted % 1
  98. end
  99.  
  100. local function rrotate(int, by)
  101. local shifted = int / (2 ^ by)
  102. local fraction = shifted % 1
  103. return (shifted - fraction) + fraction * (2 ^ 32)
  104. end
  105.  
  106. local k = {
  107. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  108. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  109. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  110. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  111. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  112. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  113. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  114. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  115. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  116. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  117. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  118. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  119. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  120. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  121. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  122. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
  123. }
  124.  
  125. local function str2hexa(s)
  126. local h = string.gsub(s, ".", function(c)
  127. return string.format("%02x", string.byte(c))
  128. end)
  129. return h
  130. end
  131.  
  132. local function num2s(l, n)
  133. local s = ""
  134. for i = 1, n do
  135. local rem = l % 256
  136. s = string.char(rem) .. s
  137. l = (l - rem) / 256
  138. end
  139. return s
  140. end
  141.  
  142. local function s232num(s, i)
  143. local n = 0
  144. for i = i, i + 3 do n = n*256 + string.byte(s, i) end
  145. return n
  146. end
  147.  
  148. local function preproc(msg, len)
  149. local extra = 64 - ((len + 1 + 8) % 64)
  150. len = num2s(8 * len, 8)
  151. msg = msg .. "\128" .. string.rep("\0", extra) .. len
  152. return msg
  153. end
  154.  
  155. local function initH256(H)
  156. H[1] = 0x6a09e667
  157. H[2] = 0xbb67ae85
  158. H[3] = 0x3c6ef372
  159. H[4] = 0xa54ff53a
  160. H[5] = 0x510e527f
  161. H[6] = 0x9b05688c
  162. H[7] = 0x1f83d9ab
  163. H[8] = 0x5be0cd19
  164. return H
  165. end
  166.  
  167. local function digestblock(msg, i, H)
  168. local w = {}
  169. for j = 1, 16 do w[j] = s232num(msg, i + (j - 1) * 4) end
  170. for j = 17, 64 do
  171. local v = w[j - 15]
  172. local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
  173. v = w[j - 2]
  174. local s1 = bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
  175. w[j] = w[j - 16] + s0 + w[j - 7] + s1
  176. end
  177.  
  178. local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]
  179. for i = 1, 64 do
  180. local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
  181. local maj = bxor(band(a, b), band(a, c), band(b, c))
  182. local t2 = s0 + maj
  183. local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
  184. local ch = bxor (band(e, f), band(bnot(e), g))
  185. local t1 = h + s1 + ch + k[i] + w[i]
  186. h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
  187. end
  188.  
  189. H[1] = band(H[1], a)
  190. H[2] = band(H[2], b)
  191. H[3] = band(H[3], c)
  192. H[4] = band(H[4], d)
  193. H[5] = band(H[5], e)
  194. H[6] = band(H[6], f)
  195. H[7] = band(H[7], g)
  196. H[8] = band(H[8], h)
  197. end
  198.  
  199. msg = preproc(msg, #msg)
  200. local H = initH256({})
  201. for i = 1, #msg, 64 do digestblock(msg, i, H) end
  202. return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
  203. num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
  204. end
  205. saltHash = "T01hFg62zY"
  206. function settingsChangeUser()
  207. reset()
  208. term.setTextColor(colors.orange)
  209. local passFile = io.open("/.EnderOS/.passInfo", "r")
  210. local passContents = passFile:read()
  211. passFile:close()
  212. print("Please enter your password: ")
  213. local input = read("*")
  214. local hash = sha256(input)
  215. if hash..saltHash ~= passContents then
  216. print("Invalid password")
  217. sleep(1.5)
  218. settingsChangeUser()
  219. else
  220. local user = ("/.EnderOS/.userInfo")
  221. local username = io.open(user, "w")
  222. print("Enter new username: ")
  223. writeUser = read()
  224. local hash = sha256(writeUser)
  225. writeN = username:write(hash..saltHash)
  226. username:close()
  227. print("Your new username is "..writeUser)
  228. sleep(2)
  229. startScreen()
  230. end
  231. term.setTextColor(colors.white)
  232. end
  233. function settingsChangePass()
  234. reset()
  235. term.setTextColor(colors.orange)
  236. local passFile = io.open("/.EnderOS/.passInfo", "r")
  237. local passContents = passFile:read()
  238. passFile:close()
  239. print("Please enter your password: ")
  240. local input = read("*")
  241. local hash = sha256(input)
  242. if hash..saltHash ~= passContents then
  243. print("Invalid password")
  244. sleep(1.5)
  245. settingsChangePass()
  246. else
  247. local pass = ("/.EnderOS/.passInfo")
  248. local password = io.open(pass, "w")
  249. print("Enter new password: ")
  250. local writePass = read("*")
  251. local hash = sha256(writePass)
  252. local writeN = password:write(hash..saltHash)
  253. password:close()
  254. print("Your new password is "..writePass)
  255. sleep(2)
  256. startScreen()
  257. end
  258. term.setTextColor(colors.white)
  259. end
  260. function settingsChangeHint()
  261. reset()
  262. term.setTextColor(colors.orange)
  263. local passFile = io.open("/.EnderOS/.passInfo", "r")
  264. local passContents = passFile:read()
  265. passFile:close()
  266. print("Please enter your password: ")
  267. local input = read("*")
  268. local hash = sha256(input)
  269. if hash..saltHash ~= passContents then
  270. print("Invalid password")
  271. sleep(1.5)
  272. settingsChangeHint()
  273. else
  274. local hint = ("/.EnderOS/.userHint")
  275. local uHint = io.open(hint, "w")
  276. print("Enter new hint: ")
  277. local writeHint = read()
  278. local writeN = uHint:write(writeHint)
  279. uHint:close()
  280. print("Your new hint is "..writeHint)
  281. sleep(2)
  282. startScreen()
  283. end
  284. term.setTextColor(colors.white)
  285. end
  286. version = "v2.2"
  287. userfile = shell.getRunningProgram()
  288. local v = ".(Period)"
  289. function reset()
  290. term.clear()
  291. term.setCursorPos(1,1)
  292. end
  293. function userInfo()
  294. reset()
  295. fs.makeDir("/.EnderOS/")
  296. user = ("/.EnderOS/.userInfo")
  297. username = io.open(user, "w")
  298. print("Please enter your desired Username")
  299. writeUser = read()
  300. local hash = sha256(writeUser)
  301. writeIsFailUser = username:write(hash..saltHash)
  302. username:close()
  303. pass = ("/.EnderOS/.passInfo")
  304. password = io.open(pass, "w")
  305. print("Please enter your desired Password")
  306. writePass = read("*")
  307. local hash = sha256(writePass)
  308. writeIsFailPass = password:write(hash..saltHash)
  309. password:close()
  310. hint = ("/.EnderOS/.userHint")
  311. uHint = io.open(hint, "w")
  312. print("Please enter your desired Password hint")
  313. writeHint = read()
  314. writeIsFailHint = uHint:write(writeHint)
  315. uHint:close()
  316. local installC = fs.open("/.EnderOS/.EnderOSisInstalled", "w")
  317. installC:close()
  318. end
  319. function frame()
  320. print("+-------------------------------------------------+")
  321. for i = 1,17 do
  322. print("| |")
  323. end
  324. term.write("+-------------------------------------------------+")
  325. end
  326. function no()
  327. term.clear()
  328. term.setTextColor(colors.red)
  329. term.setCursorPos(1,1)
  330. print("Sorry, I have not coded this in yet. Please be patient.")
  331. sleep(3)
  332. end
  333. function screen()
  334. reset()
  335. term.setTextColor(colors.lime)
  336. print("+-------------------------------------------------+")
  337. print("| |")
  338. print("| ")
  339. term.setCursorPos(19,3)
  340. term.setTextColor(colors.purple)
  341. write("EnderOS "..version)
  342. term.setTextColor(colors.lime)
  343. term.setCursorPos(31,3)
  344. print(" |")
  345. print("| |")
  346. print("| |")
  347. print("| |")
  348. print("| |")
  349. print("| ")
  350. term.setCursorPos(10,8)
  351. term.setTextColor(colors.orange)
  352. print("Username:")
  353. term.setCursorPos(19,8)
  354. print(" ")
  355. term.setCursorPos(50,8)
  356. term.setTextColor(colors.lime)
  357. print(" |")
  358. print("| |")
  359. print("| ")
  360. term.setTextColor(colors.orange)
  361. term.setCursorPos(10,10)
  362. print("Password:")
  363. term.setCursorPos(19,10)
  364. print(" ")
  365. term.setCursorPos(50,10)
  366. term.setTextColor(colors.lime)
  367. print(" |")
  368. print("| |")
  369. print("| |")
  370. print("| ")
  371. term.setCursorPos(8,13)
  372. term.setTextColor(colors.blue)
  373. print("forgot password ")
  374. term.setCursorPos(50,13)
  375. term.setTextColor(colors.lime)
  376. print(" |")
  377. print("| |")
  378. print("| |")
  379. print("| |")
  380. print("| |")
  381. print("| |")
  382. write("+-------------------------------------------------+")
  383. end
  384. function click()
  385. local userHint = io.open("/.EnderOS/.userHint", "r")
  386. hintContents = userHint:read()
  387. userHint:close()
  388. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  389. if button == 1 then
  390. if (xPos >=8 and xPos <=22 and yPos == 13) then
  391. term.setCursorPos(10,15)
  392. term.setTextColor(colors.lightGray)
  393. print("Hint: "..hintContents)
  394. term.setTextColor(colors.white)
  395. click()
  396. elseif (xPos >=10 and xPos <=18 and yPos == 8) then
  397. term.setCursorPos(20,8)
  398. else
  399. screen()
  400. click()
  401. end
  402. else
  403. click()
  404. end
  405. end
  406. function login()
  407. click()
  408. local userFile = io.open("/.EnderOS/.userInfo", "r")
  409. userContents = userFile:read()
  410. userFile:close()
  411. local passFile = io.open("/.EnderOS/.passInfo", "r")
  412. passContents = passFile:read()
  413. passFile:close()
  414. term.setTextColor(colors.white)
  415. local input = read()
  416. local hash = sha256(input)
  417. if hash..saltHash == userContents then
  418. term.setCursorPos(8,8)
  419. term.setTextColor(colors.lime)
  420. term.write("O")
  421. term.setTextColor(colors.white)
  422. term.setCursorPos(20,10)
  423. local input = read("*")
  424. local hash = sha256(input)
  425. if hash..saltHash == passContents then
  426. term.setCursorPos(8,10)
  427. term.setTextColor(colors.lime)
  428. term.write("O")
  429. term.setTextColor(colors.white)
  430. sleep(0.8)
  431. term.clear()
  432. term.setCursorPos(19,9)
  433. x,y = term.getCursorPos()
  434. print("Logging in")
  435. term.setCursorPos(x+10,9)
  436. sleep(0.7)
  437. print(".")
  438. sleep(0.7)
  439. term.setCursorPos(x+11,9)
  440. print(".")
  441. sleep(0.7)
  442. term.setCursorPos(x+12,9)
  443. print(".")
  444. sleep(0.7)
  445. reset()
  446. startScreen()
  447. else
  448. term.setCursorPos(8,10)
  449. term.setTextColor(colors.red)
  450. term.write("X")
  451. sleep(0.5)
  452. term.setTextColor(colors.white)
  453. screen()
  454. login()
  455. end
  456. else
  457. term.setCursorPos(8,8)
  458. term.setTextColor(colors.red)
  459. term.write("X")
  460. sleep(0.5)
  461. term.setTextColor(colors.white)
  462. screen()
  463. login()
  464. end
  465. end
  466. function settings()
  467. term.setTextColor(colors.purple)
  468. frame()
  469. term.setCursorPos(17,1)
  470. term.setTextColor(colors.lime)
  471. print("[EnderOS Settings]")
  472. term.setCursorPos(7,3)
  473. print("{Change Username} {Change Password}")
  474. term.setCursorPos(15,5)
  475. print("{Change Password Hint}")
  476. term.setCursorPos(3,1)
  477. term.setTextColor(colors.orange)
  478. term.write("[Back]")
  479. term.setTextColor(colors.white)
  480. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  481. if button == 1 then
  482. if (xPos >=7 and xPos <=23 and yPos == 3) then
  483. settingsChangeUser()
  484. elseif (xPos >=27 and xPos <=43 and yPos == 3) then
  485. settingsChangePass()
  486. elseif (xPos >=15 and xPos <=36 and yPos == 5) then
  487. settingsChangeHint()
  488. elseif (xPos >=3 and xPos <=9 and yPos == 1) then
  489. startScreen()
  490. else
  491. settings()
  492. end
  493. else
  494. sleep(1)--This is to prevent spamming, thus "overloading" EnderOS
  495. settings()
  496. end
  497. end
  498. function startScreen()
  499. reset()
  500. term.setTextColor(colors.purple)
  501. frame()
  502. term.setCursorPos(3,19)
  503. term.setTextColor(colors.orange)
  504. term.write("[Log Out]")
  505. term.setCursorPos(17,1)
  506. term.setTextColor(colors.lime)
  507. print("[EnderOS Commands]")
  508. term.setCursorPos(3,3)
  509. print("{Settings} {SkullPong} {Exit}")
  510. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  511. if button == 1 then
  512. if (xPos >=16 and xPos <=26 and yPos == 3) then
  513. SkullPong()
  514. elseif (xPos >=3 and xPos <=12 and yPos == 3) then
  515. settings()
  516. elseif (xPos >=30 and xPos <=35 and yPos == 3) then
  517. reset()
  518. elseif (xPos >=3 and xPos <=11 and yPos == 19) then
  519. reset()
  520. screen()
  521. login()
  522. else
  523. startScreen()
  524. end
  525. else
  526. sleep(1)--This is to prevent spamming, thus "overloading" EnderOS
  527. startScreen()
  528. end
  529. end
  530. function SkullPong()
  531. --Code By SkullBlade(Skullblade213)
  532. --You are allowed to modify and redistribute
  533. --You are not allowed to modify this header
  534. function Draw()
  535. term.setBackgroundColor(counter)
  536. term.clear()
  537. term.setBackgroundColor(colors.white)
  538. term.setCursorPos(Ball[1], Ball[2])
  539. print(" ")
  540. term.setBackgroundColor(colors.lime)
  541. term.setCursorPos(You[1], You[2])
  542. print(" ")
  543. term.setCursorPos(You[1], You[3])
  544. print(" ")
  545. term.setCursorPos(You[1], You[4])
  546. print(" ")
  547. term.setBackgroundColor(colors.red)
  548. term.setCursorPos(Op[1], Op[2])
  549. print(" ")
  550. term.setCursorPos(Op[1], Op[3])
  551. print(" ")
  552. term.setCursorPos(Op[1], Op[4])
  553. print(" ")
  554. end
  555. function Update()
  556. Ball={Ball[1]+Ball[3],Ball[2]+Ball[4],Ball[3],Ball[4]}
  557. if Ball[1]==3 or Ball[1]==49 then
  558. if Ball[1]==3 then
  559. Check="L"
  560. end
  561. if Ball[1]==49 then
  562. Check="R"
  563. end
  564. if (Ball[2]==You[2] and Check=="L") or (Ball[2]==Op[2] and Check=="R") then
  565. Ball[3]=Ball[3]*-1
  566. Ball[4]=-1
  567. rans=math.random(1,5)
  568. end
  569. if (Ball[2]==You[3] and Check=="L") or (Ball[2]==Op[3] and Check=="R") then
  570. Ball[3]=Ball[3]*-1
  571. Ball[4]=Ball[4]*-1
  572. end
  573. if (Ball[2]==You[4] and Check=="L") or (Ball[2]==Op[4] and Check=="R") then
  574. Ball[3]=Ball[3]*-1
  575. Ball[4]=1
  576. end
  577. end
  578. if Ball[2]==1 or Ball[2]==18 or Ball[2]==0 or Ball[2]==19 then
  579. Ball[4]=Ball[4]*-1
  580. end
  581. if Ball[1]==1 then
  582. score2=score2+1
  583. Start()
  584. end
  585. if Ball[1]==51 then
  586. score=score+1
  587. Start()
  588. end
  589. end
  590. function Move()
  591. if key==200 then
  592. You[2]=You[2]-1
  593. end
  594. if key==208 then
  595. You[2]=You[2]+1
  596. end
  597. end
  598. function AI()
  599. if Ball[2]+Ball[4]>Op[2]+2 then
  600. if Op[2]+3~=19 then
  601. Op={Op[1],Op[2]+1,Op[2]+2,Op[2]+3}
  602. end
  603. end
  604. if Ball[2]+Ball[4]<Op[2] then
  605. if Op[2]-1~=0 then
  606. Op={Op[1],Op[2]-1,Op[2],Op[2]+1}
  607. end
  608. end
  609. end
  610. function Start()
  611. You={2,9,10,11}
  612. Op={50,9,10,11}
  613. ran=math.random(-1,1)
  614. ran2=math.random(-1,1)
  615. while ran==0 do
  616. ran=math.random(-1,1)
  617. end
  618. while ran2==0 do
  619. ran2=math.random(-1,1)
  620. end
  621. Ball={25,10,ran,ran2}
  622. term.setCursorPos(20,10)
  623. print(score.." VS "..score2)
  624. if vars=="surv" and score2==1 then
  625. ends="true"
  626. end
  627. sleep(1)
  628. end
  629. function Single(v)
  630. vars=v
  631. ends="false"
  632. score=0
  633. score2=0
  634. if resume~="true" then
  635. Start()
  636. end
  637. counter=1
  638. breaks="false"
  639. while true do
  640. if vars=="surv" then
  641. counter=counter*2
  642. if counter==32 or counter==16384 then
  643. counter=counter*2
  644. end
  645. if counter==32768 then
  646. counter=2
  647. end
  648. term.setBackgroundColor(counter)
  649. end
  650. if vars~="surv" then
  651. counter=32768
  652. end
  653. Draw()
  654. os.startTimer(.1)
  655. while true do
  656. event, key = os.pullEvent()
  657. if event=="key" then
  658. if vars~="Local" then
  659. Move()
  660. end
  661. if key==59 and (vars=="surv" or vars=="norm" or vars=="Local") then
  662. Menu("Paused","Resume","Info/Help","Quit")
  663. breaks="true"
  664. break
  665. end
  666. if vars=="Local" then
  667. if key==17 then
  668. You[2]=You[2]-1
  669. end
  670. if key==31 then
  671. You[2]=You[2]+1
  672. end
  673. if key==200 then
  674. Op[2]=Op[2]-1
  675. end
  676. if key==208 then
  677. Op[2]=Op[2]+1
  678. end
  679. if You[2]==0 then
  680. You[2]=1
  681. end
  682. if You[2]==17 then
  683. You[2]=16
  684. end
  685. if Op[2]==0 then
  686. Op[2]=1
  687. end
  688. if Op[2]==17 then
  689. Op[2]=16
  690. end
  691. You={You[1],You[2],You[2]+1,You[2]+2}
  692. Op={Op[1],Op[2],Op[2]+1,Op[2]+2}
  693. end
  694. if You[2]==0 then
  695. You[2]=1
  696. end
  697. if You[2]==17 then
  698. You[2]=16
  699. end
  700. You={You[1],You[2],You[2]+1,You[2]+2}
  701. end
  702. if event=="timer" then
  703. break
  704. end
  705. end
  706. if breaks=="true" then
  707. break
  708. end
  709. if vars~="Local" then
  710. AI()
  711. end
  712. Update()
  713. if ends=="true" then
  714. ends="false"
  715. Menu("SinglePlayer","Normal","Survival","Back")
  716. break
  717. end
  718. end
  719. end
  720. function Set(x1,y1)
  721. x=x1
  722. y=y1
  723. term.setCursorPos(x1,y1)
  724. end
  725. function PrintCenter(text)
  726. textLen=string.len(text)
  727. x = ((51-textLen)/2)
  728. term.setCursorPos(x,y)
  729. print(text)
  730. y=y+1
  731. end
  732. function Menu(title,opt1,opt2,opt3)
  733. resume="false"
  734. term.setBackgroundColor(colors.black)
  735. select=1
  736. while true do
  737. term.clear()
  738. term.setCursorPos(1,1)
  739. term.setTextColor(colors.lime)
  740. print("SkullPong V1.10")
  741. Set(1,6)
  742. PrintCenter(title)
  743. PrintCenter("------------")
  744. term.setTextColor(colors.white)
  745. PrintCenter(opt1)
  746. PrintCenter(opt2)
  747. PrintCenter(opt3)
  748. if select==1 then
  749. Set(1,8)
  750. term.setTextColor(colors.blue)
  751. PrintCenter(opt1)
  752. term.setTextColor(colors.white)
  753. end
  754. if select==2 then
  755. Set(1,9)
  756. term.setTextColor(colors.blue)
  757. PrintCenter(opt2)
  758. term.setTextColor(colors.white)
  759. end
  760. if select==3 then
  761. Set(1,10)
  762. term.setTextColor(colors.blue)
  763. PrintCenter(opt3)
  764. term.setTextColor(colors.white)
  765. end
  766. event, param1, param2, param3 = os.pullEvent()
  767. if event=="mouse_click" then
  768. if param3==8 or param3==9 or param3==10 then
  769. sel=select
  770. if param3==8 then
  771. text=opt1
  772. select=1
  773. end
  774. if param3==9 then
  775. text=opt2
  776. select=2
  777. end
  778. if param3==10 then
  779. text=opt3
  780. select=3
  781. end
  782. strLen=string.len(text)
  783. start=(51-strLen)/2-1
  784. if param2>start and param2<start+strLen then
  785. if select==1 then
  786. if opt1=="SinglePlayer" then
  787. Menu("SinglePlayer","Normal","Survival","Back")
  788. break
  789. end
  790. if opt1=="Normal" then
  791. Single("norm")
  792. break
  793. end
  794. if opt1=="Resume" then
  795. resume="true"
  796. Single(vars)
  797. break
  798. end
  799. if opt1=="Local" then
  800. Single("Local")
  801. break
  802. end
  803. end
  804. if select==2 then
  805. if opt1=="SinglePlayer" then
  806. Menu("MultiPlayer","Local","Rednet","Back")
  807. break
  808. end
  809. if opt1=="Normal" then
  810. Single("surv")
  811. break
  812. end
  813. if opt1=="Resume" then
  814. if vars~="Local" then
  815. term.clear()
  816. term.setTextColor(colors.lime)
  817. term.setBackgroundColor(colors.black)
  818. term.setCursorPos(1,1)
  819.  
  820. print("SkullPong V1.10")
  821. print("Help")
  822. print("---------------")
  823. term.setTextColor(colors.white)
  824. print("")
  825. print("Controls")
  826. print("UpArrow: Paddle Up")
  827. print("DownArrow: Paddle Down")
  828. print("Objective")
  829. print("Don't let the ball get pass the green paddle{You}")
  830. print("Get the ball pass the red paddle{AI}")
  831. print("")
  832. print("Press any key to continue")
  833. os.pullEvent("key")
  834. end
  835. if vars=="Local" then
  836. term.clear()
  837. term.setTextColor(colors.lime)
  838. term.setBackgroundColor(colors.black)
  839. term.setCursorPos(1,1)
  840. print("SkullPong V1.10")
  841. print("Help")
  842. print("---------------")
  843. term.setTextColor(colors.white)
  844. print("")
  845. print("Controls")
  846. print("UpArrow: Paddle Up-Red")
  847. print("DownArrow: Paddle Down-Red")
  848. print("W: Paddle Up-Green")
  849. print("A: Paddle Down-Green")
  850. print("Objective")
  851. print("Don't let the ball get pass the your paddle")
  852. print("Get the ball pass your opponent's paddle")
  853. print("")
  854. print("Press any key to continue")
  855. os.pullEvent("key")
  856. end
  857. end
  858. if opt1=="Local" then
  859. error("Not Implimented!")
  860. end
  861. end
  862. if select==3 then
  863. if opt1=="SinglePlayer" then
  864. term.clear()
  865. term.setCursorPos(1,1)
  866. break
  867. else
  868. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  869. break
  870. end
  871. end
  872. else
  873. select=sel
  874. end
  875. end
  876. end
  877. if event=="key" then
  878. if param1==200 then
  879. select=select-1
  880. end
  881. if param1==208 then
  882. select=select+1
  883. end
  884. if param1==28 then
  885. if select==1 then
  886. if opt1=="SinglePlayer" then
  887. Menu("SinglePlayer","Normal","Survival","Back")
  888. break
  889. end
  890. if opt1=="Normal" then
  891. Single("norm")
  892. break
  893. end
  894. if opt1=="Resume" then
  895. resume="true"
  896. Single(vars)
  897. break
  898. end
  899. if opt1=="Local" then
  900. Single("Local")
  901. break
  902. end
  903. end
  904. if select==2 then
  905. if opt1=="SinglePlayer" then
  906. Menu("MultiPlayer","Local","Rednet","Back")
  907. break
  908. end
  909. if opt1=="Normal" then
  910. Single("surv")
  911. break
  912. end
  913. if opt1=="Resume" then
  914. if vars~="Local" then
  915. term.clear()
  916. term.setTextColor(colors.lime)
  917. term.setBackgroundColor(colors.black)
  918. term.setCursorPos(1,1)
  919.  
  920. print("SkullPong V1.10")
  921. print("Help")
  922. print("---------------")
  923. term.setTextColor(colors.white)
  924. print("")
  925. print("Controls")
  926. print("UpArrow: Paddle Up")
  927. print("DownArrow: Paddle Down")
  928. print("Objective")
  929. print("Don't let the ball get pass the green paddle{You}")
  930. print("Get the ball pass the red paddle{AI}")
  931. print("")
  932. print("Press any key to continue")
  933. os.pullEvent("key")
  934. end
  935. if vars=="Local" then
  936. term.clear()
  937. term.setTextColor(colors.lime)
  938. term.setBackgroundColor(colors.black)
  939. term.setCursorPos(1,1)
  940. print("SkullPong V1.10")
  941. print("Help")
  942. print("---------------")
  943. term.setTextColor(colors.white)
  944. print("")
  945. print("Controls")
  946. print("UpArrow: Paddle Up-Red")
  947. print("DownArrow: Paddle Down-Red")
  948. print("W: Paddle Up-Green")
  949. print("A: Paddle Down-Green")
  950. print("Objective")
  951. print("Don't let the ball get pass the your paddle")
  952. print("Get the ball pass your opponent's paddle")
  953. print("")
  954. print("Press any key to continue")
  955. os.pullEvent("key")
  956. end
  957. end
  958. if opt1=="Local" then
  959. error("Not Implimented!")
  960. end
  961. end
  962. if select==3 then
  963. if opt1=="SinglePlayer" then
  964. term.clear()
  965. term.setCursorPos(1,1)
  966. break
  967. else
  968. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  969. break
  970. end
  971. end
  972. end
  973. if select==0 then
  974. select=3
  975. end
  976. if select==4 then
  977. select=1
  978. end
  979. end
  980. end
  981. end
  982. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  983. startScreen()
  984. end
  985.  
  986. --EnderOS
  987. if not term.isColor() then
  988. term.clear()
  989. term.setCursorPos(1,1)
  990. print("EnderOS does not support non-color computers!")
  991. sleep(3)
  992. os.shutdown()
  993. end
  994. if shell.getRunningProgram() ~= "startup" then
  995. term.clear()
  996. term.setCursorPos(1,1)
  997. print("It is recommended that this file is named startup!")
  998. sleep(5)
  999. end
  1000. if not fs.exists("/.EnderOS/.EnderOSisInstalled") then
  1001. userInfo()
  1002. end
  1003. reset()
  1004. term.setTextColor(colors.purple)
  1005. term.setCursorPos(13,7)
  1006. print("EnderOS "..version.." Initializing")
  1007. term.setTextColor(colors.white)
  1008. term.setBackgroundColor(colors.lime)
  1009. for i = 14,36 do
  1010. term.setCursorPos(i,9)
  1011. term.write(" ")
  1012. sleep(0.3)
  1013. end
  1014. term.setBackgroundColor(colors.black)
  1015. sleep(0.5)
  1016. screen()
  1017. login()
  1018. startScreen()
Advertisement
Add Comment
Please, Sign In to add comment