Guest User

Untitled

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