Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modemSide = "back"
- modem = peripheral.wrap(modemSide)
- modem.open(93)
- turtle = {}
- testForExist = {}
- notExists = true
- secretPass = "Ehfks87-i"
- secretPass2 = "sgxyg&%UI33%^&HS34DH-N"
- turtlePort = 512
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function makeString(l)
- if l < 1 then return nil end -- Check for l < 1
- local s = "" -- Start string
- for i = 1, l do
- s = s .. string.char(math.random(32, 126)) -- Generate random number from 32 to 126, turn it into character and add to string
- end
- return s -- Return string
- end
- function authentificationServer(port)
- authPass = false
- rndString = tostring(makeString(math.random(8,20)))
- modem.transmit(57,port,textutils.serialize({"authentification",encrypt.encrypt(rndString,secretPass)}))
- qevent, qside, qch1, qch2, qmsg = os.pullEvent("modem_message")
- qmsgTab = textutils.unserialize(qmsg)
- if encrypt.decrypt(qmsgTab[2],secretPass2) == rndString then
- authPass = true
- end
- return authPass
- end
- function authentificationClient(port)
- qevent, qside, qch1, qch2, qmsg = os.pullEvent("modem_message")
- modem.transmit(65529,port,encrypt.encrypt(encrypt.decrypt(qmsg,secretPass),secretPass2))
- end
- clear()
- while true do
- notExists = true
- event, side, ch1, ch2, msg = os.pullEvent("modem_message")
- clear()
- print("h")
- msgTab = textutils.unserialize(msg)
- if msgTab[1] == "turtle" and ch2 == 1 then
- print("1st cond")
- if authentificationServer(turtlePort) == true then
- print("h")
- for i,v in pairs(turtle) do
- print(i..v)
- testForExist = textutils.unserialize(turtle[i])
- if testForExist[1] == msgTab[2] then
- notExists = false
- end
- end
- print("i")
- if notExists == true then
- turtle[#turtle + 1] = textutils.serialize({msgTab[2],msgTab[3],msgTab[4],msgTab[5]})
- end
- end
- elseif msgTab[1] == "turtle" and ch2 == 2 then
- print("msg")
- modem.transmit(324,1,textutils.serialize(turtle))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement