Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- keys = {2,120,34,87,45,89,67,16,123}
- root=262144
- channelStart = 46
- modem = peripheral.wrap("right")
- if not modem.isOpen(root) then modem.open(root) end
- for j=channelStart,channelStart+125 do modem.open(j) end
- function headerPull(str)
- local tble={}
- for i=1,#str do
- local char=string.sub(str,i,i)
- if char == "$" then return tonumber(table.concat(tble)) end
- table.insert(tble,char)
- end
- end
- function headerDel(str)
- local tble={}
- for k=1,#str do
- if string.sub(str,k,k) == "$" then loc=(k+1) break end
- end
- for i=loc,#str do
- local char=string.sub(str,i,i)
- table.insert(tble,char)
- msg=table.concat(tble)
- end
- return msg
- end
- function headerAdd(str,dest)
- local msg=tostring(dest.."$"..str)
- return msg
- end
- function keyPull(str)
- local tble={}
- for k=1,#str do
- if string.sub(str,k,k) == "_" then loc=(k+1) break end
- end
- for i=loc,#str do
- char=string.sub(str,i,i)
- table.insert(tble,char)
- end
- return tonumber(table.concat(tble))
- end
- function keyAdd(str,key)
- local msg=tostring(str.."_"..key)
- return msg
- end
- function keyDel(str)
- local tble={}
- for i=1,#str do
- local char=string.sub(str,i,i)
- if char == "_" then return table.concat(tble) end
- table.insert(tble,char)
- end
- end
- function checkKey(key)
- for i=1,#keys do
- if key == keys[i] then return true end
- end
- return false
- end
- function route(event,side,freq,rplyFreq,msg,dist)
- if not checkKey(keyPull(msg)) then return false end
- local dest = headerPull(msg)
- local key = keyPull(msg)
- local str = keyDel(headerDel(msg))
- modem.transmit(dest,freq,str)
- print("Routed message to channel: "..dest.." From channel: "..freq)
- end
- while true do
- route(os.pullEvent("modem_message")
- sleep(0.01)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement