Guest User

Untitled

a guest
Apr 5th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. --[[ Local Variables ]]--
  2. -- Root Directories --
  3. Root = ".Network/"
  4. uRoot = ".Network/Users/"
  5.  
  6. --[[ Functions ]]--
  7. -- Printing --
  8. function clear()
  9. term.clear()
  10. term.setCursorPos(1, 1)
  11. end
  12.  
  13. function Reset()
  14. clear()
  15. term.setTextColor(colors.red)
  16. write("E-Mail Network")
  17. term.setTextColor(colors.yellow)
  18. printTR("- Server -")
  19. term.setTextColor(colors.white)
  20. printTM("[ ID: " .. os.getComputerID() .. " ]")
  21. w, h = term.getSize()
  22. print(string.rep("-", w)) write("\n")
  23. end
  24.  
  25. function printTM( text )
  26. local w, h = term.getSize()
  27. term.setCursorPos((w - #text) / 2, 1)
  28. write(text)
  29. end
  30.  
  31. function printTR( text )
  32. w, h = term.getSize()
  33. term.setCursorPos(w - #text, 1)
  34. write(text)
  35. end
  36.  
  37. --[[ Interface ]]--
  38. os.pullEvent = os.pullEventRaw
  39. -- Check For Rednet Modem --
  40. if peripheral.isPresent("right") and peripheral.getType("right") == "modem" then
  41. rednet.open("right")
  42. elseif peripheral.isPresent("left") and peripheral.getType("left") == "modem" then
  43. rednet.open("left")
  44. elseif peripheral.isPresent("top") and peripheral.getType("top") == "modem" then
  45. rednet.open("top")
  46. elseif peripheral.isPresent("bottom") and peripheral.getType("bottom") == "modem" then
  47. rednet.open("bottom")
  48. elseif peripheral.isPresent("front") and peripheral.getType("front") == "modem" then
  49. rednet.open("front")
  50. elseif peripheral.isPresent("back") and peripheral.getType("back") == "modem" then
  51. rednet.open("back")
  52. else
  53. print("You must place a modem on the computer before you can use E-Mail!")
  54. end
  55.  
  56. -- Screen Display --
  57. Reset()
  58.  
  59. -- Message Proccessing (Main Function) --
  60. while true do
  61. ID, thing = rednet.receive()
  62. if thing == "SendMessage" then
  63. ID, Username = rednet.receive()
  64. ID, Sender = rednet.receive()
  65. ID, MessageName = rednet.receive()
  66. ID, Message = rednet.receive()
  67. if fs.exists(uRoot .. Username .. "/" .. Username .. ".ccUser") then
  68. if MessageName then
  69. if Message then
  70. os.sleep(0.1)
  71. rednet.send(ID, "true")
  72. term.setTextColor(colors.yellow)
  73. write(Sender) term.setTextColor(colors.white) write(" Just Sent A Message To ") term.setTextColor(colors.yellow) write(Username .. "!\n") term.setTextColor(colors.white)
  74. fs.makeDir(uRoot .. Username .. "/Messages/" .. MessageName)
  75. mRoot = uRoot .. Username .. "/Messages/" .. MessageName
  76. mw = fs.open(mRoot .. "/" .. MessageName, "w")
  77. mw.write(Message)
  78. mw.close()
  79. sw = fs.open(mRoot .. "/Sender.txt", "w")
  80. sw.write(Sender)
  81. sw.close()
  82. else
  83. rednet.send(ID, "false")
  84. end
  85. else
  86. rednet.send(ID, "false")
  87. end
  88. else
  89. rednet.send(ID, "false")
  90. end
  91. elseif thing == "RetrieveMessage" then
  92. ID, Username = rednet.receive()
  93. mRoot = uRoot .. Username .. "/Messages/"
  94. List = fs.list(mRoot)
  95. i = 1
  96. Messages = { }
  97. for k, v in pairs(List) do
  98. mr = fs.open(mRoot .. v .. "/" .. v, "r")
  99. MsgContent = mr.readAll()
  100. mr.close()
  101. sr = fs.open(mRoot .. v .. "/Sender.txt", "r")
  102. Author = sr.readLine()
  103. sr.close()
  104. Messages[i] = { }
  105. Messages[i].MessageName = v
  106. Messages[i].Sender = Author
  107. Messages[i].Message = MsgContent
  108. Messages[i].RUser = Username
  109. i = i + 1
  110. end
  111. Messages[i] = { }
  112. Messages[i].Option = "Reload Inbox"
  113. i = i + 1
  114. Messages[i] = { }
  115. Messages[i].Option = "Back"
  116. Messages[i].Special = " "
  117. MessageInfo = textutils.serialize(Messages)
  118. rednet.send(ID, MessageInfo)
  119. elseif thing == "DeleteMessage" then
  120. ID, MessageName = rednet.receive()
  121. ID, Receiver = rednet.receive()
  122. fs.delete(uRoot .. Receiver .. "/Messages/" .. MessageName)
  123. elseif thing == "VerifyUser" then
  124. ID, Username = rednet.receive()
  125. ID, Password = rednet.receive()
  126. if fs.exists(uRoot .. Username .. "/" .. Username .. ".ccUser") then
  127. pr = fs.open(uRoot .. Username .. "/" .. Username .. ".ccUser", "r")
  128. CheckPassword = pr.readLine()
  129. pr.close()
  130. if CheckPassword == Password then
  131. rednet.send(ID, "true")
  132. term.setTextColor(colors.yellow)
  133. write(Username) term.setTextColor(colors.white) write(" Has Just Logged In!\n")
  134. else
  135. rednet.send(ID, "false")
  136. mRoot = uRoot .. Username .. "/Messages/"
  137. fs.makeDir(mRoot .. "Failed Login")
  138. uw = fs.open(mRoot .. "Failed Login/Sender.txt", "w")
  139. uw.writeLine("E-Mail Server")
  140. uw.close()
  141. if fs.exists(mRoot .. "Failed Login/Failed Login") then
  142. pw = fs.open(mRoot .. "Failed Login/Failed Login", "a")
  143. pw.write("NOTICE: Someone has tried to access to your account! \nTimestamp: " .. textutils.formatTime(os.time(), false) .. " -- Minecraft Time\nComputer ID: " .. ID .. "\n\n")
  144. pw.close()
  145. else
  146. pw = fs.open(mRoot .. "Failed Login/Failed Login", "w")
  147. pw.write("NOTICE: Someone has tried to access to your account! \nTimestamp: " .. textutils.formatTime(os.time(), false) .. " -- Minecraft Time\nComputer ID: " .. ID .. "\n\n")
  148. pw.close()
  149. end
  150. end
  151. else
  152. rednet.send(ID, "false")
  153. end
  154. elseif thing == "CreateUser" then
  155. ID, Username = rednet.receive()
  156. ID, Password = rednet.receive()
  157. os.sleep(0.1)
  158. if fs.exists(uRoot .. Username) or Username == "" then
  159. rednet.send(ID, "false")
  160. else
  161. rednet.send(ID, "true")
  162. fs.makeDir(uRoot .. Username)
  163. fs.makeDir(uRoot .. Username .. "/Messages")
  164. uw = fs.open(uRoot .. Username .. "/" .. Username .. ".ccUser", "w")
  165. uw.write(Password)
  166. uw.close()
  167. write("User Account ") term.setTextColor(colors.yellow) write(Username) term.setTextColor(colors.white) write(" Was ") term.setTextColor(colors.lime) write("Created!\n") term.setTextColor(colors.white)
  168. end
  169. elseif thing == "DeleteUser" then
  170. ID, Username = rednet.receive()
  171. ID, Password = rednet.receive()
  172. if fs.exists(uRoot .. Username .. "/" .. Username .. ".ccUser") then
  173. pr = fs.open(uRoot .. Username .. "/" .. Username .. ".ccUser", "r")
  174. CheckPassword = pr.readLine()
  175. pr.close()
  176. if Password == CheckPassword then
  177. rednet.send(ID, "true")
  178. fs.delete(uRoot .. Username)
  179. write("User Account ") term.setTextColor(colors.yellow) write(Username) term.setTextColor(colors.white) write(" Was ") term.setTextColor(colors.red) write("Deleted!\n") term.setTextColor(colors.white)
  180. else
  181. rednet.send(ID, "false")
  182. end
  183. else
  184. rednet.send(ID, "false")
  185. end
  186. end
  187. end
Add Comment
Please, Sign In to add comment