Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- local connect1=false
- local connect2=false
- local user1id
- local user2id
- function handshakes()
- local senderID, toConnect=rednet.receive("cProt")
- user1id=senderID
- user2id=tonumber(toConnect)
- rednet.send(senderID,"handshake","handshake")
- print("sent user # "..senderID.." a handshake")
- rednet.send(tonumber(toConnect),"handshake","handshake")
- print("sent user # "..toConnect.." a handshake")
- local l, userOneHandshake,u6 = rednet.receive("handshakeConfirm")
- if(userOneHandshake == "confirm") then
- connect1=true
- print("user "..l.." handshake confirmed")
- end
- local p, userTwoHandshake,u1 = rednet.receive("handshakeConfirm")
- if(userTwoHandshake=="confirm") then
- print("user "..p.." handshake confirmed")
- end
- rednet.send(82,user1id,"dbGet")
- print("requesting nickname data from database")
- local u2,nick1=rednet.receive("dbNickSend")
- print("recieved data")
- rednet.send(user2id,nick1,"nickProt")
- print("sent user: "..user2id.." default username: "..nick1)
- rednet.send(82,tostring(user2id),"dbGet")
- print("requesting nickname data from database")
- local u3, nick2=rednet.receive("dbNickSend")
- print("recieved data")
- rednet.send(user1id,nick2,"nickProt")
- print("sent user: "..user1id.." default username: "..nick2)
- connect2=true
- end
- function messageTransfer()
- local id,msg,u4=rednet.receive("messageProtocol")
- print("message recieved. relaying message")
- if id==tonumber(user1id) then
- rednet.send (user2id,msg,"MPincoming")
- print("message sent to user 2")
- elseif id==tonumber(user2id) then
- rednet.send(user1id, msg,"MPincoming")
- print("message sent to user 1")
- end
- end
- function Nicknames()
- local IDc, cmd, u5=rednet.receive("commandProtocol")
- local find, u6 =string.find(cmd,"/nick",1,true)
- local cmdlength=string.len(cmd)
- if find==1 then
- local nickname=string.sub(cmd,7)
- print("user "..IDc.." changed nickname to "..nickname)
- if IDc==user1id then
- rednet.send(user2id,nickname,"nickProt")
- else if IDc==user2id then
- rednet.send(user1id,nickname,"nickProt")
- end
- end
- end
- end
- function relayConnections()
- local senderID, toConnect=rednet.receive("cProt")
- if connect1==true and connect2==true and senderID ~=0 and toConnect~=0 then
- rednet.send(82,"fillerTextLol","GetNextServer")
- local db,nextServer=rednet.receive("NextServer")
- rednet.send(senderID,nextServer,"relay")
- rednet.send(tonumber(toConnect),nextServer,"relay")
- end
- end
- while connect1==false and connect2==false do
- handshakes()
- end
- while connect1==true and connect2==true do
- parallel.waitForAny(messageTransfer,Nicknames,relayConnections)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement