Guest User

Untitled

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