Guest User

Untitled

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