Guest User

Untitled

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