Guest User

Untitled

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