Guest User

Untitled

a guest
Jan 21st, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.25 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!browseScripts!SP!"
  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" or "None" or "NOne" or "NONe" or "NONE" or "nONE" or "noNE" or "nonE" or "NoNe" or "nOne" or "noNe" or "nonE" or "nONe" or "nOnE" or "NonE" then
  59. p = crntname.."!SP!downloadScript!SP!"..app
  60. rednet.send(server, p)
  61. id, smsg, d = rednet.receive(2)
  62. if smsg ~= nil then
  63. nScript = fs.open(app, "w")
  64. nScript.write(nScript)
  65. nScript.close()
  66. end
  67. end
  68. end
  69. loadRandomCrap2()
  70. end
  71.  
  72. function testLogIn()
  73. shell.run("clear")
  74. if msg1 == "YOU HAVE BEEN LOGGED IN" then
  75. print(msg1..": "..crntname)
  76. term.setCursorBlink(false)
  77. read()
  78. else
  79. print(msg1)
  80. term.setCursorBlink(false)
  81. read()
  82. end
  83. if msg1 == "YOU HAVE BEEN LOGGED IN" then
  84. pickNewBanner()
  85. mineBook()
  86. else
  87. pickNewBanner()
  88. loadRandomCrap()
  89. end
  90. end
  91.  
  92. function errorQuit()
  93. a = jkfdls+fjdsjfal
  94. print(a)
  95. end
  96.  
  97. function searchUser()
  98. shell.run("clear")
  99. term.write("ENTER USER: ")
  100. user2 = read()
  101. if user2 ~= crntname then
  102. sndsrch = crntname.."!SP!search!SP!"..user2
  103. rednet.send(server, sndsrch)
  104. id3, msg3, d3 = rednet.receive(5)
  105. if msg3 ~= nil then
  106. srch = split(msg3, "!SP!")
  107. nuser = srch[1]
  108. nstatus = srch[2]
  109. nfriends = srch[3]
  110. if nstatus == nil then
  111. nstatus = ""
  112. end
  113. shell.run("clear")
  114. print("|||||||||||||||||||||||||||")
  115. print("|| ||")
  116. print("|| USER SEARCH RESULTS ||")
  117. print("|| ||")
  118. print("|||||||||||||||||||||||||||")
  119. print("")
  120. print("")
  121. print("User Name: "..nuser)
  122. print("")
  123. print("Status: "..nstatus)
  124. print("")
  125. print("")
  126. print("PRESS S TO SEND FRIEND REQUEST OR E TO EXIT")
  127. while true do
  128. event9, param9 = os.pullEvent()
  129. if event9 == "key" and param9 == 31 and nuser then
  130. sndmsg = crntname.."!SP!sndfrq!SP!"..nuser
  131. shell.run("clear")
  132. rednet.send(server, sndmsg)
  133. id8, msg8, d8 = rednet.receive(1)
  134. if msg8 == nil then
  135. print("REQUEST SENT")
  136. read()
  137. pickNewBanner()
  138. loadRandomCrap2()
  139. break
  140. else
  141. print("YOU ARE ALREADY FRIENDS WITH THIS PERSON")
  142. read()
  143. pickNewBanner()
  144. loadRandomCrap2()
  145. break
  146. end
  147. elseif event9 == "key" and param9 == 18 then
  148. pickNewBanner()
  149. loadRandomCrap2()
  150. break
  151. end
  152. end
  153. else
  154. shell.run("clear")
  155. print("SERVER ERROR")
  156. read()
  157. pickNewBanner()
  158. loadRandomCrap2()
  159. end
  160. else
  161. shell.run("clear")
  162. print("YOU CAN NOT SEARCH YOURSELF")
  163. sleep(1)
  164. pickNewBanner()
  165. loadRandomCrap2()
  166. end
  167. end
  168.  
  169. function prntFrq()
  170. shell.run("clear")
  171. print("FRIEND REQUESTS")
  172. print("")
  173. print(frq[gcur])
  174. print("")
  175. print("PRESS A TO ACCEPT OR D TO DECLINE")
  176. end
  177.  
  178. function printFrndReq()
  179. gcur = 1
  180. prntFrq()
  181. while true do
  182. event2, param2 = os.pullEvent()
  183. if event2 == "key" and param2 == 30 then
  184. shell.run("clear")
  185. print("USER ADDED")
  186. ju = crntname.."!SP!add friend!SP!"..frq[gcur]
  187. rednet.send(server, ju)
  188. gcur = gcur+1
  189. read()
  190. if gcur > gmax then
  191. loadRandomCrap2()
  192. break
  193. else
  194. prntFrq()
  195. end
  196. elseif event2 == "key" and param2 == 32 then
  197. shell.run("clear")
  198. print("USER DECLINED")
  199. gcur = gcur+1
  200. read()
  201. if gcur > gmax then
  202. pickNewBanner()
  203. loadRandomCrap2()
  204. break
  205. else
  206. prntFrq()
  207. end
  208. end
  209. end
  210. end
  211.  
  212. function checkFrndReq()
  213. jk = crntname.."!SP!chck frnd req"
  214. rednet.send(server, jk)
  215. id, msg, d = rednet.receive(5)
  216. if msg ~= nil then
  217. frq = split(msg, "!SP!")
  218. gmax = #frq
  219. gmin = 1
  220. if gmax >= gmin then
  221. shell.run("clear")
  222. printFrndReq()
  223. else
  224. shell.run("clear")
  225. print("NO NEW REQUESTS")
  226. read()
  227. end
  228. loadRandomCrap2()
  229. end
  230. end
  231.  
  232. function updateStatus()
  233. shell.run("clear")
  234. stat = read()
  235. h = crntname.."!SP!status update!SP!"..stat
  236. rednet.send(server, h)
  237. g = fs.open("MINEBOOK/STATUS", "w")
  238. g.write(stat)
  239. g.close()
  240. end
  241.  
  242. function listFriends()
  243. y = "list"
  244. x = crntname.."!SP!"..y
  245. rednet.send(server, x)
  246. id, msg, d = rednet.receive(4)
  247. if msg == nil then
  248. shell.run("clear")
  249. print("ERROR")
  250. read()
  251. loadRandomCrap2()
  252. else
  253. shell.run("clear")
  254. r = split(msg, "!SP!")
  255. print("FRIEND LIST")
  256. textutils.tabulate(r)
  257. read()
  258. loadRandomCrap2()
  259. end
  260. end
  261.  
  262. function testLogInTwo()
  263. shell.run("clear")
  264. print(msg2)
  265. term.setCursorBlink(false)
  266. read()
  267. end
  268.  
  269. function OpenAll()
  270. for _,side in ipairs(rs.getSides()) do
  271. rednet.open(side)
  272. end
  273. end
  274.  
  275. function mineBook()
  276.  
  277. w1 = "Search"
  278. w2 = "Change Status"
  279. w3 = "Friends"
  280. w4 = "Check Friend Request"
  281. w5 = "Upload a Script"
  282. w6 = "Browse Scripts"
  283. w7 = "Exit"
  284.  
  285. min = 1
  286. max = 7
  287. cur = min
  288.  
  289. function doThings2()
  290. if cur == 3 then
  291. listFriends()
  292. elseif cur == 4 then
  293. checkFrndReq()
  294. elseif cur == 1 then
  295. searchUser()
  296. elseif cur == 2 then
  297. updateStatus()
  298. pickNewBanner()
  299. loadRandomCrap2()
  300. elseif cur == 5 then
  301. uploadScript()
  302. elseif cur == 6 then
  303. browseScripts()
  304. end
  305. end
  306.  
  307.  
  308. function loadRandomCrap2()
  309. OpenAll()
  310. term.clear()
  311. term.setCursorPos(1,1)
  312. print("|----------------------| WELLCOME: "..crntname)
  313. print("| RedBook 1.2 |")
  314. print(banners[curBanner])
  315. print("|----------------------|")
  316. print("")
  317. print("")
  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