Guest User

Untitled

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