Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --code by majsky
- local args = {...}
- local version = 1
- if #args ~= 1 and #args ~= 2 then
- print "Usage:\n mount <side> [server ID]"
- return
- end
- if http then
- local data = nil
- parallel.waitForAll(
- function()
- textutils.slowPrint("Contacting update server...")
- end,
- function()
- data = http.get("https://dl.dropbox.com/u/49227540/cc/wireless_peripheral_client/ver.txt")
- end
- )
- if data then
- local version = data.readLine()
- if version then
- if ver < tonumber(version) then
- print("New version on wireless peripherals found\nRun mount update to download newest version")
- end
- end
- end
- end
- if #args == 1 and http then
- if string.lower(args[1]) == "update" then
- local prog = nil
- parallel.waitForAll(
- function()
- textutils.slowPrint("Downloading update...")
- end,
- function()
- prog = http.get("https://dl.dropbox.com/u/49227540/cc/wireless_peripheral_client/prog.lua")
- end
- )
- if prog then
- prog = prog.readAll()
- local file = io.open(shell.getRunningProgram(), "w")
- file:write(prog)
- file:close()
- print "Program was sucessfully updated\nRestart the program, please"
- return
- end
- end
- end
- os.sleep(1.5)
- term.clear()
- local modem = false
- for k, v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "modem" then
- modem = true
- rednet.open(v)
- break
- end
- end
- if not modem then
- print 'Modem not found'
- return
- end
- local periType = nil
- local methods = {}
- local server = nil
- for i=1, 3 do
- if #args == 2 then
- rednet.send(tonumber(args[2], "#PERI_CLIENT"))
- else
- rednet.broadcast("#PERI_CLIENT")
- end
- local id, msg = rednet.receive(1)
- if msg == "#PERI_SERVER" then
- server = id
- for i = 1, 3 do
- id, msg = rednet.receive(1)
- if id == server then
- data = textutils.unserialize(msg)
- periType = data[1]
- methods = data[2]
- break
- end
- end
- break
- end
- end
- if not server then
- print "Peripheral server not found!"
- return
- end
- print("Connected to server "..server..", which is running "..periType)
- local oldPeri = {}
- for k, v in pairs(peripheral) do
- oldPeri[k] = v
- end
- function peripheral.isPresent(side)
- if side == args[1] then
- return true
- end
- return oldPeri.isPresent(side)
- end
- function peripheral.getType(side)
- if side == args[1] then
- return periType
- end
- return oldPeri.getType(side)
- end
- function peripheral.getMethods(side)
- if side == args[1] then
- return methods
- end
- return oldPeri.getMethods(side)
- end
- function peripheral.call(side, func, par1, par2, par3, par4, par5)
- if side == args[1] then
- local arg = {"call", func, par1, par2, par3, par4, par5}
- rednet.send(server, textutils.serialize(arg))
- for i = 1, 3 do
- local id, msg = rednet.receive(1)
- if id == server then
- local response = textutils.unserialize(msg)
- if type(response) == "table" then
- return unpack(response)
- end
- return nil
- end
- end
- print 'Connection lost!'
- return nil
- end
- return oldPeri.call(side, func, par1, par2, par3, par4, par5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement