Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- rednet security client
- -- Build Beta 1
- MODEM = peripheral.wrap("top")
- local decodePort = function(TAB)
- -TAKEN OUT
- end
- -- lets find the server
- local serverFound = false
- local connected = false
- local targetServ = "bankSer"
- local targetPort = nil
- local count = 8
- local status = 1
- local credentials = {cid = os.getComputerID(), name = os.getComputerLabel(), protocol = nil}
- print("Searching..")
- while not serverFound and count < 13 do -- 120 public ports
- MODEM.open(count)
- print("opened: "..count)
- if status == 1 then
- credentials.protocol = "_ping"
- MODEM.transmit(count,count,textutils.serialize(credentials))
- local T = os.startTimer(0.5)
- os.sleep(0)
- local ev = { os.pullEvent() }
- if ev[1] == "modem_message" then
- local iC = ev[3]
- local rC = ev[4]
- local str = ev[5]
- if str == "_pong" then
- status = 2
- print("PINGED!")
- end
- os.sleep(0)
- if status == 2 then
- credentials.protocol = "whoareyou?"
- MODEM.transmit(count,count,textutils.serialize(credentials))
- local T = os.startTimer(0.4)
- os.sleep(0)
- local ev = { os.pullEvent() }
- if ev[1] == "modem_message" then
- local iC = ev[3]
- local rC = ev[4]
- local str = ev[5]
- if str == targetServ then
- status = 3
- serverFound = true
- targetPort = count
- print("Found Target Server, Requesting to Connect")
- end
- end
- end
- end
- end
- credentials.protocol = nil
- count = count + 1
- os.sleep(0.4)
- end
- print("Search ended, trying to connect")
- local attempts = 0
- while serverFound and not connected and attempts < 3 do
- if status == 3 then
- credentials.protocol = "connectionRequest"
- MODEM.transmit(targetPort,targetPort,textutils.serialize(credentials))
- local T = os.startTimer(0.4)
- os.sleep(0)
- local ev = { os.pullEvent() }
- if ev[1] == "modem_message" then
- local iC = ev[3]
- local rC = ev[4]
- local pkg = textutils.unserialize(ev[5])
- targetPort = tonumber(decodePort(pkg))
- print(targetPort)
- connected = true
- end
- end
- attempts = attempts + 1
- end
- print("ENDOF program")
Advertisement
Add Comment
Please, Sign In to add comment