Guest User

Untitled

a guest
Jan 21st, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.13 KB | None | 0 0
  1. --CONFIGURATION
  2.  
  3. server = 2 -- put the server's computer id here
  4. cursor = "<> " -- this is the cursor for the welcome screen
  5. cursor2 = "<> " -- this is the cursor for the actual Minebook
  6. maxUserNameLength = 10 --The max ammount of charecters allowed in a username
  7. banners = {"| Only One |", "| Multiple Features |", "| Admin Added |", "| Super Addicting |", "| Updates Coming Soon |"} --This is the banners (what it says under RedBook 1.2) to learn how to add custum banners read the Banner ReadMe
  8.  
  9. -- |----------------------|
  10. -- | RedBook 1.2 |
  11. -- | Updates Coming Soon |
  12. -- |----------------------|
  13.  
  14. -- Banner Template ^
  15.  
  16. --Do not touch anything below this unless you know what you are doing
  17.  
  18. function uploadScript()
  19. shell.run("clear")
  20. print("Pick a file to upload")
  21. sApp = read()
  22. if fs.exists(sApp) then
  23. fProgram = fs.open(sApp, "r")
  24. program = fProgram.readAll()
  25. fProgram.close()
  26. s = crntname.."!SP!uploadScript!SP!"..sApp.."!SP!"..program
  27. rednet.send(server, s)
  28. id, msg, d = rednet.receive(2)
  29. if msg ~= nil then
  30. print(msg)
  31. os.sleep(2)
  32. end
  33. loadRandomCrap2()
  34. else
  35. shell.run("clear")
  36. print("NOT A PROGRAM")
  37. loadRandomCrap2()
  38. end
  39. end
  40.  
  41. function browseScripts()
  42. hj = crntname.."!SP!downloadScript!SP!"..browseScripts
  43. rednet.send(server, hj)
  44. id, msg, d = rednet.receive(2)
  45. if msg == nil then
  46. shell.run("Clear")
  47. print("SERVER ERROR")
  48. os.sleep(2)
  49. else
  50. t = textutils.unserialize(msg)
  51. shell.run("clear")
  52. textutils.tabulate(t)
  53. print("")
  54. print("Pick a software to download. If you dont want to download anything then type none")
  55. print("")
  56. term.write("Enter software: ")
  57. app = read()
  58. if app ~= "none" then
  59. p = crntname.."!SP!downloadScript!SP!"..app
  60. rednet.send(server, p)
  61. end
  62. end
  63. loadRandomCrap2()
  64. end
  65.  
  66. function testLogIn()
  67. shell.run("clear")
  68. if msg1 == "YOU HAVE BEEN LOGGED IN" then
  69. print(msg1..": "..crntname)
  70. term.setCursorBlink(false)
  71. read()
  72. else
  73. print(msg1)
  74. term.setCursorBlink(false)
  75. read()
  76. end
  77. if msg1 == "YOU HAVE BEEN LOGGED IN" then
  78. pickNewBanner()
  79. mineBook()
  80. else
  81. pickNewBanner()
  82. loadRandomCrap()
  83. end
  84. end
  85.  
  86. function errorQuit()
  87. a = jkfdls+fjdsjfal
  88. print(a)
  89. end
  90.  
  91. function searchUser()
  92. shell.run("clear")
  93. term.write("ENTER USER: ")
  94. user2 = read()
  95. if user2 ~= crntname then
  96. sndsrch = crntname.."!SP!search!SP!"..user2
  97. rednet.send(server, sndsrch)
  98. id3, msg3, d3 = rednet.receive(5)
  99. if msg3 ~= nil then
  100. srch = split(msg3, "!SP!")
  101. nuser = srch[1]
  102. nstatus = srch[2]
  103. nfriends = srch[3]
  104. if nstatus == nil then
  105. nstatus = ""
  106. end
  107. shell.run("clear")
  108. print("|||||||||||||||||||||||||||")
  109. print("|| ||")
  110. print("|| USER SEARCH RESULTS ||")
  111. print("|| ||")
  112. print("|||||||||||||||||||||||||||")
  113. print("")
  114. print("")
  115. print("User Name: "..nuser)
  116. print("")
  117. print("Status: "..nstatus)
  118. print("")
  119. print("")
  120. print("PRESS S TO SEND FRIEND REQUEST OR E TO EXIT")
  121. while true do
  122. event9, param9 = os.pullEvent()
  123. if event9 == "key" and param9 == 31 and nuser then
  124. sndmsg = crntname.."!SP!sndfrq!SP!"..nuser
  125. shell.run("clear")
  126. rednet.send(server, sndmsg)
  127. id8, msg8, d8 = rednet.receive(1)
  128. if msg8 == nil then
  129. print("REQUEST SENT")
  130. read()
  131. pickNewBanner()
  132. loadRandomCrap2()
  133. break
  134. else
  135. print("YOU ARE ALREADY FRIENDS WITH THIS PERSON")
  136. read()
  137. pickNewBanner()
  138. loadRandomCrap2()
  139. break
  140. end
  141. elseif event9 == "key" and param9 == 18 then
  142. pickNewBanner()
  143. loadRandomCrap2()
  144. break
  145. end
  146. end
  147. else
  148. shell.run("clear")
  149. print("SERVER ERROR")
  150. read()
  151. pickNewBanner()
  152. loadRandomCrap2()
  153. end
  154. else
  155. shell.run("clear")
  156. print("YOU CAN NOT SEARCH YOURSELF")
  157. sleep(1)
  158. pickNewBanner()
  159. loadRandomCrap2()
  160. end
  161. end
  162.  
  163. function prntFrq()
  164. shell.run("clear")
  165. print("FRIEND REQUESTS")
  166. print("")
  167. print(frq[gcur])
  168. print("")
  169. print("PRESS A TO ACCEPT OR D TO DECLINE")
  170. end
  171.  
  172. function printFrndReq()
  173. gcur = 1
  174. prntFrq()
  175. while true do
  176. event2, param2 = os.pullEvent()
  177. if event2 == "key" and param2 == 30 then
  178. shell.run("clear")
  179. print("USER ADDED")
  180. ju = crntname.."!SP!add friend!SP!"..frq[gcur]
  181. rednet.send(server, ju)
  182. gcur = gcur+1
  183. read()
  184. if gcur > gmax then
  185. loadRandomCrap2()
  186. break
  187. else
  188. prntFrq()
  189. end
  190. elseif event2 == "key" and param2 == 32 then
  191. shell.run("clear")
  192. print("USER DECLINED")
  193. gcur = gcur+1
  194. read()
  195. if gcur > gmax then
  196. pickNewBanner()
  197. loadRandomCrap2()
  198. break
  199. else
  200. prntFrq()
  201. end
  202. end
  203. end
  204. end
  205.  
  206. function checkFrndReq()
  207. jk = crntname.."!SP!chck frnd req"
  208. rednet.send(server, jk)
  209. id, msg, d = rednet.receive(5)
  210. if msg ~= nil then
  211. frq = split(msg, "!SP!")
  212. gmax = #frq
  213. gmin = 1
  214. if gmax >= gmin then
  215. shell.run("clear")
  216. printFrndReq()
  217. else
  218. shell.run("clear")
  219. print("NO NEW REQUESTS")
  220. read()
  221. end
  222. loadRandomCrap2()
  223. end
  224. end
  225.  
  226. function updateStatus()
  227. shell.run("clear")
  228. stat = read()
  229. h = crntname.."!SP!status update!SP!"..stat
  230. rednet.send(server, h)
  231. g = fs.open("MINEBOOK/STATUS", "w")
  232. g.write(stat)
  233. g.close()
  234. end
  235.  
  236. function listFriends()
  237. y = "list"
  238. x = crntname.."!SP!"..y
  239. rednet.send(server, x)
  240. id, msg, d = rednet.receive(4)
  241. if msg == nil then
  242. shell.run("clear")
  243. print("ERROR")
  244. read()
  245. loadRandomCrap2()
  246. else
  247. shell.run("clear")
  248. r = split(msg, "!SP!")
  249. print("FRIEND LIST")
  250. textutils.tabulate(r)
  251. read()
  252. loadRandomCrap2()
  253. end
  254. end
  255.  
  256. function testLogInTwo()
  257. shell.run("clear")
  258. print(msg2)
  259. term.setCursorBlink(false)
  260. read()
  261. end
  262.  
  263. function OpenAll()
  264. for _,side in ipairs(rs.getSides()) do
  265. rednet.open(side)
  266. end
  267. end
  268.  
  269. function mineBook()
  270.  
  271. w1 = "Search"
  272. w2 = "Change Status"
  273. w3 = "Friends"
  274. w4 = "Check Friend Request"
  275. w5 = "Upload a Script"
  276. w6 = "Browse Scripts"
  277. w7 = "Exit"
  278.  
  279. min = 1
  280. max = 7
  281. cur = min
  282.  
  283. function doThings2()
  284. if cur == 3 then
  285. listFriends()
  286. elseif cur == 4 then
  287. checkFrndReq()
  288. elseif cur == 1 then
  289. searchUser()
  290. elseif cur == 2 then
  291. updateStatus()
  292. pickNewBanner()
  293. loadRandomCrap2()
  294. elseif cur == 5 then
  295. uploadScript()
  296. elseif cur == 6 then
  297. browseScripts()
  298. end
  299. end
  300.  
  301.  
  302. function loadRandomCrap2()
  303. OpenAll()
  304. term.clear()
  305. term.setCursorPos(1,1)
  306. y = fs.open("MINEBOOK/STATUS", "a")
  307. y.close()
  308. l = fs.open("MINEBOOK/STATUS", "r")
  309. ju = l.readAll()
  310. crntstatus = ju
  311. print("|----------------------| WELLCOME: "..crntname)
  312. print("| RedBook 1.2 |")
  313. print(banners[curBanner])
  314. print("|----------------------|")
  315. print("")
  316. print("")
  317. print("STATUS: "..ju)
  318. if cur == 1 then
  319. term.setCursorPos(1,11)
  320. print(""..cursor2..""..w1.."")
  321. else
  322. term.setCursorPos(1,11)
  323. print(w1)
  324. end
  325. if cur == 2 then
  326. term.setCursorPos(1,12)
  327. print(""..cursor2..""..w2.."")
  328. else
  329. term.setCursorPos(1,12)
  330. print(w2)
  331. end
  332. if cur == 3 then
  333. term.setCursorPos(1,13)
  334. print(""..cursor2..""..w3.."")
  335. else
  336. term.setCursorPos(1,13)
  337. print(w3)
  338. end
  339. if cur == 4 then
  340. term.setCursorPos(1,14)
  341. print(""..cursor2..""..w4.."")
  342. else
  343. term.setCursorPos(1,14)
  344. print(w4)
  345. end
  346. if cur == 5 then
  347. term.setCursorPos(1,15)
  348. print(""..cursor2..""..w5.."")
  349. else
  350. term.setCursorPos(1,15)
  351. print(w5)
  352. end
  353. if cur == 6 then
  354. term.setCursorPos(1,16)
  355. print(""..cursor2..""..w6.."")
  356. else
  357. term.setCursorPos(1,16)
  358. print(w6)
  359. end
  360. if cur == 7 then
  361. term.setCursorPos(1,17)
  362. print(""..cursor2..""..w7.."")
  363. else
  364. term.setCursorPos(1,17)
  365. print(w7)
  366. end
  367. end
  368.  
  369. function runMineBook()
  370. loadRandomCrap2()
  371. while true do
  372. event, param1 = os.pullEvent()
  373. if event == "key" and param1 == 200 then
  374. if cur == min then
  375. cur = max
  376. loadRandomCrap2()
  377. else
  378. cur = cur-1
  379. loadRandomCrap2()
  380. end
  381. elseif event == "key" and param1 == 208 then
  382. if cur == max then
  383. cur = min
  384. loadRandomCrap2()
  385. else
  386. cur = cur+1
  387. loadRandomCrap2()
  388. end
  389. elseif event == "key" and param1 == 28 then
  390. if cur == 7 then
  391. shell.run("clear")
  392. min = 1
  393. max = 4
  394. cur = min
  395. pickNewBanner()
  396. loadRandomCrap()
  397. break
  398. end
  399. doThings2()
  400. end
  401. end
  402. end
  403. runMineBook()
  404. end
  405.  
  406. function split(str, pat)
  407. local t = { }
  408. local fpat = "(.-)"..pat
  409. local last_end = 1
  410. local s, e, cap = str:find(fpat, 1)
  411. while s do
  412. if s ~= 1 or cap ~= "" then
  413. table.insert(t,cap)
  414. end
  415. last_end = e+1
  416. s, e, cap = str:find(fpat, last_end)
  417. end
  418. if last_end <= #str then
  419. cap = str:sub(last_end)
  420. table.insert(t, cap)
  421. end
  422. return t
  423. end
  424.  
  425. min = 1
  426. max = 4
  427. cur = min
  428.  
  429. function makeUser()
  430. shell.run("clear")
  431. term.write("ENTER DESIRED USERNAME: ")
  432. term.setCursorPos(1,3)
  433. term.write("ENTER DESIRED PASSWORD: ")
  434. term.setCursorPos(1,5)
  435. term.write("RE-ENTER DESIRED PASSWORD: ")
  436. term.setCursorPos(26,1)
  437. dusrnm = read()
  438. term.setCursorPos(26,3)
  439. dpw = read("*")
  440. term.setCursorPos(29,5)
  441. rdpw = read("*")
  442. if dpw == rdpw then
  443. if #dusrnm <= maxUserNameLength then
  444. y = dusrnm.."!SP!makeUser!SP!"..dpw
  445. rednet.send(server, y)
  446. id2, msg2, d2 = rednet.receive(1)
  447. if msg2 == nil then
  448. shell.run("clear")
  449. print("SERVER ERROR")
  450. read()
  451. loadRandomCrap()
  452. else
  453. username = dusrnm
  454. rednet.send(server, username.."!SP!status update!SP!DEFAULT STATUS")
  455. testLogInTwo()
  456. end
  457. else
  458. shell.run("clear")
  459. print("USERNAME IS TOO LONG")
  460. read()
  461. end
  462. else
  463. shell.run("clear")
  464. print("PASSWORDS DO NOT MATCH")
  465. read()
  466. end
  467. end
  468.  
  469. function logIn()
  470. shell.run("clear")
  471. term.write("ENTER USERNAME: ")
  472. term.setCursorPos(1,3)
  473. term.write("ENTER PASSWORD: ")
  474. term.setCursorPos(17,1)
  475. usrnm = read()
  476. term.setCursorPos(17,3)
  477. pswrd = read("*")
  478. x = usrnm.."!SP!logIn!SP!"..pswrd
  479. rednet.send(server, x)
  480. id1, msg1, d1 = rednet.receive(1)
  481. if msg1 == nil then
  482. shell.run("clear")
  483. print("SERVER ERROR")
  484. read()
  485. loadRandomCrap()
  486. else
  487. if msg1 == "YOU HAVE BEEN LOGGED IN" then
  488. crntname = usrnm
  489. testLogIn()
  490. else
  491. testLogIn()
  492. end
  493. end
  494. end
  495.  
  496. term.setCursorBlink(false)
  497. cursor = "=> "
  498.  
  499. s1 = "Log In"
  500. s2 = "Make Account"
  501. s3 = "Change Banner"
  502. s4 = "Exit"
  503.  
  504. function doThings()
  505. if cur == 3 then
  506. pickNewBanner()
  507. loadRandomCrap()
  508. elseif cur == 1 then
  509. logIn()
  510. elseif cur == 2 then
  511. makeUser()
  512. pickNewBanner()
  513. loadRandomCrap()
  514. end
  515. end
  516.  
  517. function pickNewBanner()
  518. maxBannerNumber = #banners
  519. curBanner = math.random(maxBannerNumber)
  520. end
  521.  
  522. function loadRandomCrap()
  523. OpenAll()
  524. term.clear()
  525. term.setCursorPos(1,1)
  526. print("|----------------------|")
  527. print("| RedBook 1.2 |")
  528. print(banners[curBanner])
  529. print("|----------------------|")
  530. if cur == 1 then
  531. term.setCursorPos(1,7)
  532. print(""..cursor..""..s1.."")
  533. else
  534. term.setCursorPos(1,7)
  535. print(s1)
  536. end
  537. if cur == 2 then
  538. term.setCursorPos(1,8)
  539. print(""..cursor..""..s2.."")
  540. else
  541. term.setCursorPos(1,8)
  542. print(s2)
  543. end
  544. if cur == 3 then
  545. term.setCursorPos(1,9)
  546. print(""..cursor..""..s3.."")
  547. else
  548. term.setCursorPos(1,9)
  549. print(s3)
  550. end
  551. if cur == 4 then
  552. term.setCursorPos(1,10)
  553. print(""..cursor..""..s4.."")
  554. else
  555. term.setCursorPos(1,10)
  556. print(s4)
  557. end
  558. end
  559.  
  560. function runProgram()
  561. fs.makeDir("MINEBOOK")
  562.  
  563. min = 1
  564. max = 4
  565. cur = min
  566.  
  567. loadRandomCrap()
  568. while true do
  569. event, param1 = os.pullEvent()
  570. if event == "key" and param1 == 200 then
  571. if cur == min then
  572. cur = max
  573. loadRandomCrap()
  574. else
  575. cur = cur-1
  576. loadRandomCrap()
  577. end
  578. elseif event == "key" and param1 == 208 then
  579. if cur == max then
  580. cur = min
  581. loadRandomCrap()
  582. else
  583. cur = cur+1
  584. loadRandomCrap()
  585. end
  586. elseif event == "key" and param1 == 28 then
  587. if cur == 4 then
  588. break
  589. end
  590. doThings()
  591. end
  592. end
  593. end
  594.  
  595. pickNewBanner()
  596. runProgram()
Add Comment
Please, Sign In to add comment