Guest User

Untitled

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