Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Local Variables ]]--
- -- Root Directories --
- Root = ".Network/"
- uRoot = ".Network/Users/"
- --[[ Functions ]]--
- -- Printing --
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function Reset()
- clear()
- term.setTextColor(colors.red)
- write("E-Mail Network")
- term.setTextColor(colors.yellow)
- printTR("- Server -")
- term.setTextColor(colors.white)
- printTM("[ ID: " .. os.getComputerID() .. " ]")
- w, h = term.getSize()
- print(string.rep("-", w)) write("\n")
- end
- function printTM( text )
- local w, h = term.getSize()
- term.setCursorPos((w - #text) / 2, 1)
- write(text)
- end
- function printTR( text )
- w, h = term.getSize()
- term.setCursorPos(w - #text, 1)
- write(text)
- end
- --[[ Interface ]]--
- os.pullEvent = os.pullEventRaw
- -- Check For Rednet Modem --
- if peripheral.isPresent("right") and peripheral.getType("right") == "modem" then
- rednet.open("right")
- elseif peripheral.isPresent("left") and peripheral.getType("left") == "modem" then
- rednet.open("left")
- elseif peripheral.isPresent("top") and peripheral.getType("top") == "modem" then
- rednet.open("top")
- elseif peripheral.isPresent("bottom") and peripheral.getType("bottom") == "modem" then
- rednet.open("bottom")
- elseif peripheral.isPresent("front") and peripheral.getType("front") == "modem" then
- rednet.open("front")
- elseif peripheral.isPresent("back") and peripheral.getType("back") == "modem" then
- rednet.open("back")
- else
- print("You must place a modem on the computer before you can use E-Mail!")
- end
- -- Screen Display --
- Reset()
- -- Message Proccessing (Main Function) --
- while true do
- ID, thing = rednet.receive()
- if thing == "SendMessage" then
- ID, Username = rednet.receive()
- ID, Sender = rednet.receive()
- ID, MessageName = rednet.receive()
- ID, Message = rednet.receive()
- if fs.exists(uRoot .. Username .. "/" .. Username .. ".ccUser") then
- if MessageName then
- if Message then
- os.sleep(0.1)
- rednet.send(ID, "true")
- term.setTextColor(colors.yellow)
- write(Sender) term.setTextColor(colors.white) write(" Just Sent A Message To ") term.setTextColor(colors.yellow) write(Username .. "!\n") term.setTextColor(colors.white)
- fs.makeDir(uRoot .. Username .. "/Messages/" .. MessageName)
- mRoot = uRoot .. Username .. "/Messages/" .. MessageName
- mw = fs.open(mRoot .. "/" .. MessageName, "w")
- mw.write(Message)
- mw.close()
- sw = fs.open(mRoot .. "/Sender.txt", "w")
- sw.write(Sender)
- sw.close()
- else
- rednet.send(ID, "false")
- end
- else
- rednet.send(ID, "false")
- end
- else
- rednet.send(ID, "false")
- end
- elseif thing == "RetrieveMessage" then
- ID, Username = rednet.receive()
- mRoot = uRoot .. Username .. "/Messages/"
- List = fs.list(mRoot)
- i = 1
- Messages = { }
- for k, v in pairs(List) do
- mr = fs.open(mRoot .. v .. "/" .. v, "r")
- MsgContent = mr.readAll()
- mr.close()
- sr = fs.open(mRoot .. v .. "/Sender.txt", "r")
- Author = sr.readLine()
- sr.close()
- Messages[i] = { }
- Messages[i].MessageName = v
- Messages[i].Sender = Author
- Messages[i].Message = MsgContent
- Messages[i].RUser = Username
- i = i + 1
- end
- Messages[i] = { }
- Messages[i].Option = "Reload Inbox"
- i = i + 1
- Messages[i] = { }
- Messages[i].Option = "Back"
- Messages[i].Special = " "
- MessageInfo = textutils.serialize(Messages)
- rednet.send(ID, MessageInfo)
- elseif thing == "DeleteMessage" then
- ID, MessageName = rednet.receive()
- ID, Receiver = rednet.receive()
- fs.delete(uRoot .. Receiver .. "/Messages/" .. MessageName)
- elseif thing == "VerifyUser" then
- ID, Username = rednet.receive()
- ID, Password = rednet.receive()
- if fs.exists(uRoot .. Username .. "/" .. Username .. ".ccUser") then
- pr = fs.open(uRoot .. Username .. "/" .. Username .. ".ccUser", "r")
- CheckPassword = pr.readLine()
- pr.close()
- if CheckPassword == Password then
- rednet.send(ID, "true")
- term.setTextColor(colors.yellow)
- write(Username) term.setTextColor(colors.white) write(" Has Just Logged In!\n")
- else
- rednet.send(ID, "false")
- mRoot = uRoot .. Username .. "/Messages/"
- fs.makeDir(mRoot .. "Failed Login")
- uw = fs.open(mRoot .. "Failed Login/Sender.txt", "w")
- uw.writeLine("E-Mail Server")
- uw.close()
- if fs.exists(mRoot .. "Failed Login/Failed Login") then
- pw = fs.open(mRoot .. "Failed Login/Failed Login", "a")
- pw.write("NOTICE: Someone has tried to access to your account! \nTimestamp: " .. textutils.formatTime(os.time(), false) .. " -- Minecraft Time\nComputer ID: " .. ID .. "\n\n")
- pw.close()
- else
- pw = fs.open(mRoot .. "Failed Login/Failed Login", "w")
- pw.write("NOTICE: Someone has tried to access to your account! \nTimestamp: " .. textutils.formatTime(os.time(), false) .. " -- Minecraft Time\nComputer ID: " .. ID .. "\n\n")
- pw.close()
- end
- end
- else
- rednet.send(ID, "false")
- end
- elseif thing == "CreateUser" then
- ID, Username = rednet.receive()
- ID, Password = rednet.receive()
- os.sleep(0.1)
- if fs.exists(uRoot .. Username) or Username == "" then
- rednet.send(ID, "false")
- else
- rednet.send(ID, "true")
- fs.makeDir(uRoot .. Username)
- fs.makeDir(uRoot .. Username .. "/Messages")
- uw = fs.open(uRoot .. Username .. "/" .. Username .. ".ccUser", "w")
- uw.write(Password)
- uw.close()
- 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)
- end
- elseif thing == "DeleteUser" then
- ID, Username = rednet.receive()
- ID, Password = rednet.receive()
- if fs.exists(uRoot .. Username .. "/" .. Username .. ".ccUser") then
- pr = fs.open(uRoot .. Username .. "/" .. Username .. ".ccUser", "r")
- CheckPassword = pr.readLine()
- pr.close()
- if Password == CheckPassword then
- rednet.send(ID, "true")
- fs.delete(uRoot .. Username)
- 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)
- else
- rednet.send(ID, "false")
- end
- else
- rednet.send(ID, "false")
- end
- end
- end
Add Comment
Please, Sign In to add comment