Guest User

Untitled

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