Guest User

Untitled

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