Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1, 1)
- function receive()
- rednet.open("left")
- while true do
- local senderId, message = rednet.receive()
- print("Received message from ID: " .. senderId .. ", length: " .. #message)
- local cmd = message:match("%S+")
- message = message:gsub(cmd.." ", "")
- if cmd == "LOGIN" then
- local data = message:match("%S+:%S+")
- local f, t = message:find(":")
- if f ~= nil and t ~= nil then
- local username = data:sub(0, t-1)
- local password = data:sub(t+1)
- if fs.exists("users/" .. username) then
- local file = fs.open("users/"..username, "r")
- local pw = file.readLine()
- if password == pw then
- rednet.send(senderId, "RIGHT_PASSWORD")
- print("User "..username.." successfully logged in!")
- else
- rednet.send(senderId, "WRONG_PASSWORD")
- print("User "..username.." failed to log in!")
- end
- file.close()
- else
- rednet.send(senderId, "USER_NOT_EXISTS")
- print("User "..username.." doesn't exists!")
- end
- else
- rednet.send(senderId, "WRONG_FORMAT")
- print("WRONG_FORMAT")
- end
- elseif cmd == "SEND" then
- local data = message:match("%S+:%S+")
- local f, t = message:find(":")
- if f ~= nil and t ~= nil then
- local username = data:sub(0, t-1)
- local password = data:sub(t+1)
- message = message:gsub(data.." ", "")
- if fs.exists("users/" .. username) then
- local file = fs.open("users/"..username, "r")
- local pw = file.readLine()
- file.close()
- if password == pw then
- local to = message:match("%S+")
- message = message:gsub(to.." ", "")
- if fs.exists("users/" .. to) then
- local count = #fs.list("mails/" .. to)
- if not fs.exists("mails/"..to) then
- fs.makeDir("mails/"..to)
- end
- local file = fs.open("mails/" .. to .. "/" .. count+1, "w")
- file.writeLine(username)
- file.writeLine(message)
- file.close()
- rednet.send(senderId, "SUCCESSFUL_SENT")
- print("E-Mail sent from "..username.." to "..to..", length: "..#message)
- else
- rednet.send(senderId, "TARGET_NOT_EXISTS")
- end
- else
- rednet.send(senderId, "FAILED_SENT")
- end
- else
- rednet.send(senderId, "FAILED_SENT")
- end
- end
- elseif cmd == "CHECK" then
- local data = message:match("%S+:%S+")
- local f, t = message:find(":")
- if f ~= nil and t ~= nil then
- local username = data:sub(0, t-1)
- local password = data:sub(t+1)
- if fs.exists("users/" .. username) then
- local file = fs.open("users/"..username, "r")
- local pw = file.readLine()
- file.close()
- if password == pw then
- for i, file in ipairs(fs.list("mails/"..username)) do
- end
- rednet.send(senderId, "lag")
- end
- end
- end
- else
- print("Unknown command: "..cmd)
- end
- end
- end
- receive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement