Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mailServerRednetID = 0
- awaitingmail = {}
- function string:split(inSplitPattern, outResults)
- if not outResults then
- outResults = {}
- end
- local theStart = 1
- local theSplitStart, theSplitEnd = string.find(self, inSplitPattern, theStart)
- while theSplitStart do
- table.insert(outResults,string.sub(self,theStart,theSplitStart - 1))
- theStart = theSplitEnd+1
- theSplitStart,theSplitEnd = string.find(self,inSplitPattern,theStart)
- end
- table.insert(outResults, string.sub(self,theStart))
- return outResults
- end
- rednet.open('bottom')
- function listen()
- while true do
- local senderid, message, protocol = rednet.receive("mailreq")
- awaitingmail.insert(0,{message.split(',')[1], string.gsub(message.split(',')[2], "[comma]", ",")})
- end
- end
- function compose()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("You have "..#awaitingmail.." new messages")
- write("Read (r) or Compose (c) >")
- answer = read()
- print('')
- if(answer == "c")then
- write('To (id): ')
- to = read();
- print('')
- write('Message: ')
- msg = read();
- if(rednet.send(mailServerRednetID, to .. "," .. string.gsub(msg,",","[comma]"), "mailreq"))then
- print("Sent")
- else
- print("Didn't send (Uh oh!)")
- end
- end
- if(answer == "r")then
- write("Number (1 - ".. #awaitingmail .."): ")
- num = tonumber(read())
- print(awaitingmail[num][1])
- print(awaitingmail[num][2])
- end
- end
- end
- parallel.waitForAll(listen, compose)
Advertisement
Add Comment
Please, Sign In to add comment