Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Config File ]]--
- IDserver = 11 --[[ The server that this computer is gona use for send messages
- IMPORTANT: 2 Computers cant use the same server! ]]--
- IDcomputer = "7" --[[ For check the ID of this computer, start the mail program
- and check it at top right of the screen. ]]--
- modem = "back" --[[ Where the modem is at?
- (front, back, top, bottom, right, left) ]]--
- --[[ End of Config ]]--
- --[[ Start of program ]]--
- generalloop = true
- while (generalloop == true) do
- sleep(0.1)
- rednet.open(modem)
- term.clear()
- term.setCursorPos(45,1)
- Start = "ID: "
- ID = os.computerID()
- End = " \n"
- Start = Start..ID
- write(Start..End)
- term.setCursorPos(1,1)
- print "Mail Menu"
- print "-------------------------"
- print "1. Send Message"
- print "2. Look for new messages"
- print "3. Disconnect"
- print "-------------------------"
- write "Please select an option: "
- input = read()
- if (input == "1") then
- SMloop = true
- while (SMloop == true) do
- term.clear()
- term.setCursorPos(1,1)
- print "Send Message"
- print "---------------"
- write "To: "
- to = read()
- write "Message: "
- message = read()
- print "---------------"
- print ""
- print "Sending Message..."
- sleep(2)
- if (to == "") or (message == "") then
- term.clear()
- term.setCursorPos(1,1)
- print "Message Failed"
- print "-----------------------------"
- print "Please fill all the fields"
- sleep(2)
- else
- SMloop = false
- term.clear()
- term.setCursorPos(1,1)
- rednet.send(IDserver, message)
- rednet.send(IDserver, to)
- rednet.send(IDserver, IDcomputer)
- server, msg = rednet.receive()
- end
- end
- if (msg == "Message Recived") then
- print "Message Sent"
- print "---------------------------------------"
- print("To: " .. to)
- print("Message: " .. message)
- print "---------------------------------------"
- print "The message has been sent to the server"
- print "As soon as the computer"
- print "that you sended refreshes"
- print "the new messages, he will recive your"
- print "email."
- print ""
- print "NOTE: If you did not enter any computer"
- print " ID, the message it will never be"
- print " recived by anyone!"
- print "---------------------------------------"
- print "(Press B for go back)"
- backloop = true
- while (backloop == true) do
- local sBack, back = os.pullEvent("key")
- if (sBack == "key") then
- if (back == 48) then
- break
- end
- end
- end
- elseif (msg == "Error") then
- term.clear()
- term.setCursorPos(1,1)
- print "Error: Message not sent"
- print "-------------------------"
- print "Something went wrong!"
- print "Please try it again."
- print "Remember to put a valid"
- print "destination!"
- print ""
- print "Ex:"
- print "To: 6"
- print "-------------------------"
- print "(Press B for go back)"
- backloop = true
- while (backloop == true) do
- local sBack, back = os.pullEvent("key")
- if (sBack == "key") then
- if (back == 48) then
- break
- end
- end
- end
- end
- elseif (input == "2") then
- term.clear()
- term.setCursorPos(1,1)
- print "Looking for new messages"
- print "-------------------------------------"
- print "Asking the server for new messages..."
- print ""
- print "This can take a while, please wait."
- from, senderMsg, distance = rednet.receive(30)
- from, sendby, distance = rednet.receive(2)
- if (senderMsg ~= nil) then
- if (sendby ~= nil) then
- rednet.send(from, "Recived")
- term.clear()
- term.setCursorPos(1,1)
- print "Message Recived"
- print "------------------------------"
- print("From: " ..sendby)
- print ""
- print("Message: " ..senderMsg)
- print "------------------------------"
- print "(Press B for go back)"
- backloop = true
- while (backloop == true) do
- local sBack, back = os.pullEvent("key")
- if (sBack == "key") then
- if (back == 48) then
- break
- end
- end
- end
- else
- term.clear()
- term.setCursorPos(1,1)
- print "No new messages recived"
- print ""
- print "(Press B for go back)"
- backloop = true
- while (backloop == true) do
- local sBack, back = os.pullEvent("key")
- if (sBack == "key") then
- if (back == 48) then
- break
- end
- end
- end
- end
- end
- elseif (input == "3") then
- generalloop = false
- term.clear()
- term.setCursorPos(1,1)
- print "Disconecting..."
- print "------------------"
- print "Disconnected!"
- print ""
- print "(Press Q for quit)"
- rednet.close(modem)
- quitloop = true
- while (quitloop == true) do
- local sQuit, quit = os.pullEvent("key")
- if (sQuit == "key") then
- if (quit == 16) then
- break
- end
- end
- end
- sleep(0.1)
- term.clear()
- term.setCursorPos(1,1)
- else
- print ""
- print "Unknown option!"
- print "Please try again."
- sleep(3)
- end
- end
- --[[ End of program ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement