Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.wrap("right")
- local power = true
- local partner = "0"
- --split
- function split(pString,pPattern)
- local Table = {}
- local fpat = "(.-)"..pPattern
- local last_end = 1
- local s,e,cap = pString:find(fpat,1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Table,cap)
- end
- last_end = e+1
- s,e,cap = pString:find(fpat,last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Table,cap)
- end
- return Table
- end
- -- open modems
- function set_chan()
- rednet.open("top")
- file = fs.open("port.db","r")
- fileDataX = {}
- local line = file.readLine()
- repeat
- table.insert(fileDataX,line)
- line = file.readLine()
- until line == nil
- file.close()
- for iu=1,#fileDataX do
- dataX = fileDataX[iu]
- print("Open Port: "..dataX)
- modem.open(tonumber(dataX))
- end
- end
- --decoder
- function recive_wlan_lan()
- while power == true do
- event, id, message = os.pullEvent()
- if event == "rednet_message" then
- if tostring(id) ~= partner then
- print("sending in lan: "..message)
- data = split(message,"|")
- modem.transmit(tonumber(data[2]),tonumber(data[3]),data[4])
- end
- end
- end
- end
- --decoder
- function recive_lan_wlan()
- while power == true do
- event, modemside , sendchan , replaychan , message , dist = os.pullEvent()
- if modemside == "right" then
- if tonumber(dist) > 6 then
- senddata = os.getComputerID().."|"..sendchan.."|"..replaychan.."|"..message
- print("sending in wlan: "..senddata)
- rednet.broadcast(senddata)
- end
- end
- end
- end
- --start program
- shell.run("delete port.db")
- shell.run("pastebin get zaxKi9mC port.db")
- set_chan()
- local found = fs.exists("config.cfg")
- if found == false then
- print("start router on ID:"..os.getComputerID())
- print("enter partner ID:")
- partner_w = read()
- print("1. wlan to lan")
- print("2. lan to wlan")
- modus_w = read()
- local file = fs.open("config.cfg","w")
- file.writeLine(partner_w)
- file.writeLine(modus_w)
- file.close()
- end
- file = fs.open("config.cfg","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- partner = fileData[1]
- modus = fileData[2]
- if modus == "1" then
- print("Start wlan to lan")
- recive_wlan_lan()
- end
- if modus == "2" then
- print("Start lan to wlan")
- recive_lan_wlan()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement