Guest User

Untitled

a guest
Dec 2nd, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. adminId = "ADMIN"
  2.  
  3. function OpenAll()
  4. for _,side in ipairs(rs.getSides()) do
  5. rednet.open(side)
  6. end
  7. end
  8.  
  9. function split(str, pat)
  10. local t = { }
  11. local fpat = "(.-)"..pat
  12. local last_end = 1
  13. local s, e, cap = str:find(fpat, 1)
  14. while s do
  15. if s ~= 1 or cap ~= "" then
  16. table.insert(t,cap)
  17. end
  18. last_end = e+1
  19. s, e, cap = str:find(fpat, last_end)
  20. end
  21. if last_end <= #str then
  22. cap = str:sub(last_end)
  23. table.insert(t, cap)
  24. end
  25. return t
  26. end
  27.  
  28. function runApp()
  29. OpenAll()
  30. id, msg, d = rednet.receive()
  31. if msg ~= nil then
  32. t = split(msg, "!SP!")
  33. usr = t[1]
  34. cmd = t[2]
  35. print("--------------------------------------------------")
  36. print("USER: "..usr)
  37. print("COMMAND: "..cmd)
  38. if cmd == "search" then
  39. usr2 = t[3]
  40. print("USER 2: "..usr2)
  41. print("--------------------------------------------------")
  42. elseif cmd == "status update" then
  43. status = t[3]
  44. print("STATUS: "..status)
  45. print("--------------------------------------------------")
  46. elseif cmd == "makeUser" then
  47. password = t[3]
  48. print("PASSWORD: "..password)
  49. print("--------------------------------------------------")
  50. elseif cmd == "logIn" then
  51. password = t[3]
  52. print("PASSWORD: "..password)
  53. print("--------------------------------------------------")
  54. elseif cmd == "sndfrq" then
  55. usr2 = t[3]
  56. print("USER 2: "..usr2)
  57. print("--------------------------------------------------")
  58. elseif cmd == "add friend" then
  59. usr2 = t[3]
  60. print("USER 2: "..usr2)
  61. print("--------------------------------------------------")
  62. elseif cmd == "list" then
  63. print("--------------------------------------------------")
  64. elseif cmd == "deleteUser" then
  65. usr2 = t[3]
  66. print("--------------------------------------------------")
  67. elseif cmd == "listUsers" then
  68. print("--------------------------------------------------")
  69. end
  70. if cmd == "search" then
  71. if fs.isDir("RedBook/"..usr2) == false then
  72. rednet.send(id, "USER DOES NOT EXIST")
  73. else
  74. if fs.exists("RedBook/"..usr2.."/status") == true then
  75. usrstatus1 = fs.open("RedBook/"..usr2.."/status", "r")
  76. usrstatus = usrstatus1.readAll()
  77. usrstatus1.close()
  78. end
  79. x = usr2.."!SP!"..usrstatus.."!SP!"
  80. rednet.send(id, x)
  81. end
  82. runApp()
  83. elseif cmd == "status update" then
  84. f = fs.open("RedBook/"..usr.."/status", "w")
  85. f.write(status)
  86. f.close()
  87. runApp()
  88. elseif cmd == "list" then
  89. h = fs.open("RedBook/"..usr.."/friendlist", "a")
  90. h.close()
  91. friends = fs.open("RedBook/"..usr.."/friendlist", "r")
  92. xyz = friends.readAll()
  93. print(xyz)
  94. rednet.send(id, xyz)
  95. runApp()
  96. elseif cmd == "sndfrq" then
  97. check = fs.open("RedBook/"..usr2.."/friendlist", "r")
  98. chck2 = check.readAll()
  99. chck3 = split(chck2, "!SP!")
  100. check.close()
  101. a = fs.open("RedBook/"..usr2.."/friendreq", "a")
  102. a.write("RedBook/"..usr.."!SP!")
  103. a.close()
  104. runApp()
  105. elseif cmd == "chck frnd req" then
  106. if fs.exists("RedBook/"..usr.."/friendreq") == false then
  107. go = fs.open(usr.."/friendreq", "a")
  108. go.close()
  109. end
  110. chck = fs.open("RedBook/"..usr.."/friendreq", "r")
  111. cv = chck.readAll()
  112. chck.close()
  113. clear = fs.open("RedBook/"..usr.."/friendreq", "w")
  114. clear.close()
  115. print(cv)
  116. rednet.send(id, cv)
  117. print("SENT")
  118. print("--------------------------------------------------")
  119. chck.close()
  120. runApp()
  121. elseif cmd == "add friend" then
  122. print(usr2)
  123. nFriend = usr2.."!SP!"
  124. nFriend2 = usr.."!SP!"
  125. print(nFriend)
  126. gol = fs.open("RedBook/"..usr.."/friendlist", "a")
  127. gol.write(nFriend)
  128. gol.close()
  129. gold = fs.open("RedBook/"..usr2.."/friendlist", "a")
  130. gold.write(nFriend2)
  131. gold.close()
  132. runApp()
  133. elseif cmd == "logIn" then
  134. if fs.isDir("RedBook/"..usr) == true then
  135. w = fs.open("RedBook/"..usr.."/password", "r")
  136. y = w.readAll()
  137. if y == password then
  138. rednet.send(id, "YOU HAVE BEEN LOGGED IN")
  139. else
  140. rednet.send(id, "ERROR: WRONG PASSWORD")
  141. end
  142. else
  143. rednet.send(id, "ERROR: WRONG USERNAME")
  144. end
  145. runApp()
  146. elseif cmd == "makeUser" then
  147. fs.makeDir("RedBook/"..usr)
  148. make1 = fs.open("RedBook/"..usr.."/friendreq", "a")
  149. make1.close()
  150. make2 = fs.open("RedBook/"..usr.."/status", "a")
  151. make2.close()
  152. make3 = fs.open("RedBook/"..usr.."/friendlist", "a")
  153. make3.close()
  154. make4 = fs.open("RedBook/"..usr.."/password", "w")
  155. make4.write(password)
  156. make4.close()
  157. rednet.send(id, "USER HAS BEEN CREATED")
  158. runApp()
  159. elseif cmd == "listUsers" and usr == "ADMIN" then
  160. list = fs.list("RedBook/")
  161. list2 = textutils.serialize(list)
  162. rednet.send(adminId, list2)
  163. runApp()
  164. elseif cmd == "deleteUser" and usr == "ADMIN" then
  165. if fs.exists("RedBook/"..usr2) then
  166. fs.delete("RedBook/"..usr2)
  167. rednet.send(adminId, "USER IS GONE >:^D")
  168. else
  169. rednet.send(adminId, "USER DOES NOT EXIST")
  170. end
  171. runApp()
  172. end
  173. end
  174. end
  175.  
  176. runApp()
Add Comment
Please, Sign In to add comment