Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tMails = {}
- local bGo = true
- local function split(sMail)
- local tPositions = {0,0,0,0,0}
- local tContents= {"","","",""}
- local last = 0
- local first
- for i = 1, # tPositions do --determine separator locations
- first, last = string.find(sMail,"#|#",last+1)
- tPositions[i] = last
- end -- end for
- for i = 1,((# tPositions) - 1) do --get contents
- tContents[i] = string.sub(sMail, tPositions[i]+1,tPositions[i+1]-3)
- end -- end for
- return tContents[1],tContents[2],tContents[3],tContents[4]
- end -- end split
- local function sendMail(header, dst, src, msg)
- rednet.send(tonumber(dst), "#|#"..header.."#|#"..dst.."#|#"..src.."#|#"..msg.."#|#")
- end -- end sendMail
- local function reply(dst, msg)
- src = os.getComputerID()
- header = "$REPLY"
- sendMail(header, dst, src, msg)
- end -- end reply
- print("Booting server...")
- rednet.open("top")
- while bGo do
- local id,msg,dist = rednet.receive()
- print("From: "..id.." : "..msg)
- local header,dst,src,mesg = split(msg)
- if header == "$REQUEST" then
- for i,v in ipairs(tMails) do
- if v[2] == src then
- sendMail(v[1],v[2],v[3],v[4])
- end --end if
- end -- end for
- elseif header == "$MAIL" then
- local newMail = {header,dst,src,mesg}
- table.insert(tMails,newMail)
- reply(id,"mail got")
- elseif header == "$REPLY" then
- if mesg=="mails got" then
- for i,v in ipairs(tMails) do
- if v[2] == src then
- table.remove(tMails,i)
- end -- end if
- end -- end for
- end -- end if
- end -- end if
- end -- end while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement