Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- rednet security server
- -- Build Beta 1
- local serverProperties = {publicPort = 10, serverType = "bankSer"}
- local privatePorts = {}
- MODEM = peripheral.wrap("top")
- MODEM.open(serverProperties.publicPort)
- print("opened: "..serverProperties.publicPort)
- local RNGen = function()
- --TAKEN OUT
- end
- local encodePort = function(RNG)
- --TAKEN OUT
- end
- local decodePort = function(TAB)
- --TAKEN OUT
- end
- while true do
- local ev = { os.pullEvent() }
- if ev[1] == "modem_message" then
- local iC = ev[3]
- local rC = ev[4]
- local pkg = textutils.unserialize(ev[5])
- if type(pkg) == "table" then -- verify if its a table
- if pkg.cid ~= nil then -- pkg must have a cid -computer id-
- if privatePorts[pkg.cid] == nil then -- if cid isnt in memory create a slot
- privatePorts[pkg.cid] = {name = pkg.name, port = 0}
- end
- os.sleep(0)
- if pkg.protocol == "_ping" then
- MODEM.transmit(rC,serverProperties.publicPort,"_pong")
- print("pinged from "..pkg.cid)
- elseif pkg.protocol == "whoareyou?" then
- MODEM.transmit(rC,serverProperties.publicPort,serverProperties.serverType)
- print("send Server ID to "..pkg.cid)
- elseif pkg.protocol == "connectionRequest" then
- local gPort = RNGen()
- local packet = encodePort(gPort)
- privatePorts[pkg.cid].port = gPort
- MODEM.open(gPort)
- print(" opened: "..gPort)
- print(" for cid: "..pkg.cid)
- print(" encoded at: "..textutils.serialize(packet))
- MODEM.transmit(rC,serverProperties.publicPort,textutils.serialize(packet))
- elseif pkg.protocol == "connectionVerify" then
- MODEM.transmit(rC,rC,"connectionEstablished")
- else -- if pkg.protocol doesnt exist or doesnt match
- MODEM.transmit(rC,serverProperties.publicPort,"error: invalid protocol")
- print("invalid protocol")
- end
- else -- if pkg.cid is nil
- MODEM.transmit(rC,serverProperties.publicPort,"error: invalid Credentials")
- print("invalid Credentials")
- end
- else -- if pkg is a string
- MODEM.transmit(rC,serverProperties.publicPort,"error: invalid packet")
- print("invalid packet..")
- end
- os.sleep(0)
- elseif ev[1] == "key" then
- print(textutils.serialize(privatePorts))
- os.sleep(1.5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment